mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-05-05 12:22:35 +02:00
Add database query status (and improved response), photos, likes, comments, bans
This commit is contained in:
parent
519ae22197
commit
abbd5bc494
22 changed files with 1118 additions and 72 deletions
31
service/api/authorization/auth-anonymous.go
Normal file
31
service/api/authorization/auth-anonymous.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
// This identity provider represents non logged-in users.
|
||||
|
||||
package authorization
|
||||
|
||||
import (
|
||||
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
||||
"github.com/notherealmarco/WASAPhoto/service/database"
|
||||
)
|
||||
|
||||
type AnonymousAuth struct {
|
||||
}
|
||||
|
||||
func BuildAnonymous() *AnonymousAuth {
|
||||
return &AnonymousAuth{}
|
||||
}
|
||||
|
||||
func (u *AnonymousAuth) GetType() string {
|
||||
return "Anonymous"
|
||||
}
|
||||
|
||||
func (u *AnonymousAuth) Authorized(db database.AppDatabase) (reqcontext.AuthStatus, error) {
|
||||
return reqcontext.UNAUTHORIZED, nil
|
||||
}
|
||||
|
||||
func (u *AnonymousAuth) UserAuthorized(db database.AppDatabase, uid string) (reqcontext.AuthStatus, error) {
|
||||
return reqcontext.UNAUTHORIZED, nil
|
||||
}
|
||||
|
||||
func (u *AnonymousAuth) GetUserID() string {
|
||||
return ""
|
||||
}
|
|
@ -29,7 +29,7 @@ func BuildBearer(header string) (*BearerAuth, error) {
|
|||
return &BearerAuth{token: header[7:]}, nil
|
||||
}
|
||||
|
||||
func (b *BearerAuth) GetToken() string {
|
||||
func (b *BearerAuth) GetUserID() string {
|
||||
return b.token
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func BuildAuth(header string) (reqcontext.Authorization, error) {
|
|||
return auth, nil
|
||||
}
|
||||
|
||||
func SendAuthorizationError(f func(db database.AppDatabase, uid string) (reqcontext.AuthStatus, error), uid string, db database.AppDatabase, w http.ResponseWriter) bool {
|
||||
func SendAuthorizationError(f func(db database.AppDatabase, uid string) (reqcontext.AuthStatus, error), uid string, db database.AppDatabase, w http.ResponseWriter, notFoundStatus int) bool {
|
||||
auth, err := f(db, uid)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
@ -36,7 +36,7 @@ func SendAuthorizationError(f func(db database.AppDatabase, uid string) (reqcont
|
|||
}
|
||||
// requested user is not found -> 404 as the resource is not found
|
||||
if auth == reqcontext.USER_NOT_FOUND {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.WriteHeader(notFoundStatus)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue