Basic Auth Context

This commit is contained in:
2021-02-02 22:55:35 -05:00
parent 7e6454c593
commit c39fe6ec24
13 changed files with 828 additions and 202 deletions

View File

@@ -0,0 +1,12 @@
package model
import (
"net/http"
)
type AuthContext struct {
AccessToken string
RefreshToken string
AuthResponse *http.ResponseWriter
AuthRequest *http.Request
}

36
graph/model/models_db.go Normal file
View File

@@ -0,0 +1,36 @@
package model
import (
"gorm.io/gorm"
"github.com/google/uuid"
)
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
u.ID = &newID
return
}
func (a *Album) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
a.ID = &newID
return
}
func (m *MediaItem) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
m.ID = &newID
return
}
func (t *Tag) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
t.ID = &newID
return
}
func (d *Device) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
d.ID = &newID
return
}

View File

@@ -32,6 +32,11 @@ type AlbumResponse struct {
PageInfo *PageInfo `json:"pageInfo" `
}
type AuthResponse struct {
Result AuthResult `json:"Result" `
Error *string `json:"Error" `
}
type AuthTypeFilter struct {
EqualTo *AuthType `json:"equalTo" `
NotEqualTo *AuthType `json:"notEqualTo" `
@@ -261,6 +266,47 @@ type UserResponse struct {
PageInfo *PageInfo `json:"pageInfo" `
}
type AuthResult string
const (
AuthResultSuccess AuthResult = "Success"
AuthResultFailure AuthResult = "Failure"
)
var AllAuthResult = []AuthResult{
AuthResultSuccess,
AuthResultFailure,
}
func (e AuthResult) IsValid() bool {
switch e {
case AuthResultSuccess, AuthResultFailure:
return true
}
return false
}
func (e AuthResult) String() string {
return string(e)
}
func (e *AuthResult) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = AuthResult(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid AuthResult", str)
}
return nil
}
func (e AuthResult) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}
type AuthType string
const (