mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add get followers
This commit is contained in:
parent
b89296c249
commit
e8047c77a0
10 changed files with 162 additions and 17 deletions
|
@ -33,17 +33,32 @@ func (b *BearerAuth) GetToken() string {
|
|||
return b.token
|
||||
}
|
||||
|
||||
func (b *BearerAuth) Authorized(db database.AppDatabase) (bool, error) {
|
||||
func (b *BearerAuth) Authorized(db database.AppDatabase) (reqcontext.AuthStatus, error) {
|
||||
// this is the way we manage authorization, the bearer token is the user id
|
||||
state, err := db.UserExists(b.token)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
return reqcontext.UNAUTHORIZED, err
|
||||
}
|
||||
return state, nil
|
||||
|
||||
if state {
|
||||
return reqcontext.AUTHORIZED, nil
|
||||
}
|
||||
return reqcontext.UNAUTHORIZED, nil
|
||||
}
|
||||
|
||||
func (b *BearerAuth) UserAuthorized(db database.AppDatabase, uid string) (reqcontext.AuthStatus, error) {
|
||||
|
||||
// If uid is not a valid user, return USER_NOT_FOUND
|
||||
user_exists, err := db.UserExists(uid)
|
||||
|
||||
if err != nil {
|
||||
return reqcontext.UNAUTHORIZED, err
|
||||
}
|
||||
if !user_exists {
|
||||
return reqcontext.USER_NOT_FOUND, nil
|
||||
}
|
||||
|
||||
if b.token == uid {
|
||||
auth, err := b.Authorized(db)
|
||||
|
||||
|
@ -51,11 +66,7 @@ func (b *BearerAuth) UserAuthorized(db database.AppDatabase, uid string) (reqcon
|
|||
return -1, err
|
||||
}
|
||||
|
||||
if auth {
|
||||
return reqcontext.AUTHORIZED, nil
|
||||
} else {
|
||||
return reqcontext.UNAUTHORIZED, nil
|
||||
}
|
||||
return auth, nil
|
||||
}
|
||||
return reqcontext.FORBIDDEN, nil
|
||||
}
|
||||
|
|
|
@ -34,5 +34,10 @@ func SendAuthorizationError(f func(db database.AppDatabase, uid string) (reqcont
|
|||
w.WriteHeader(http.StatusForbidden)
|
||||
return false
|
||||
}
|
||||
// requested user is not found -> 404 as the resource is not found
|
||||
if auth == reqcontext.USER_NOT_FOUND {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue