feat:allow signup without verification (#39)
* fix: add disable basic auth check in resolvers * feat: allow signup without email verification Resolves #32
This commit is contained in:
parent
0a2efe048b
commit
a0171ad500
|
@ -43,18 +43,18 @@ type DirectiveRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComplexityRoot struct {
|
type ComplexityRoot struct {
|
||||||
Error struct {
|
AuthResponse struct {
|
||||||
Message func(childComplexity int) int
|
|
||||||
Reason func(childComplexity int) int
|
|
||||||
}
|
|
||||||
|
|
||||||
LoginResponse struct {
|
|
||||||
AccessToken func(childComplexity int) int
|
AccessToken func(childComplexity int) int
|
||||||
AccessTokenExpiresAt func(childComplexity int) int
|
AccessTokenExpiresAt func(childComplexity int) int
|
||||||
Message func(childComplexity int) int
|
Message func(childComplexity int) int
|
||||||
User func(childComplexity int) int
|
User func(childComplexity int) int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Error struct {
|
||||||
|
Message func(childComplexity int) int
|
||||||
|
Reason func(childComplexity int) int
|
||||||
|
}
|
||||||
|
|
||||||
Meta struct {
|
Meta struct {
|
||||||
IsBasicAuthenticationEnabled func(childComplexity int) int
|
IsBasicAuthenticationEnabled func(childComplexity int) int
|
||||||
IsEmailVerificationEnabled func(childComplexity int) int
|
IsEmailVerificationEnabled func(childComplexity int) int
|
||||||
|
@ -112,11 +112,11 @@ type ComplexityRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MutationResolver interface {
|
type MutationResolver interface {
|
||||||
Signup(ctx context.Context, params model.SignUpInput) (*model.Response, error)
|
Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse, error)
|
||||||
Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse, error)
|
Login(ctx context.Context, params model.LoginInput) (*model.AuthResponse, error)
|
||||||
Logout(ctx context.Context) (*model.Response, error)
|
Logout(ctx context.Context) (*model.Response, error)
|
||||||
UpdateProfile(ctx context.Context, params model.UpdateProfileInput) (*model.Response, error)
|
UpdateProfile(ctx context.Context, params model.UpdateProfileInput) (*model.Response, error)
|
||||||
VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.LoginResponse, error)
|
VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.AuthResponse, error)
|
||||||
ResendVerifyEmail(ctx context.Context, params model.ResendVerifyEmailInput) (*model.Response, error)
|
ResendVerifyEmail(ctx context.Context, params model.ResendVerifyEmailInput) (*model.Response, error)
|
||||||
ForgotPassword(ctx context.Context, params model.ForgotPasswordInput) (*model.Response, error)
|
ForgotPassword(ctx context.Context, params model.ForgotPasswordInput) (*model.Response, error)
|
||||||
ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error)
|
ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error)
|
||||||
|
@ -124,7 +124,7 @@ type MutationResolver interface {
|
||||||
type QueryResolver interface {
|
type QueryResolver interface {
|
||||||
Meta(ctx context.Context) (*model.Meta, error)
|
Meta(ctx context.Context) (*model.Meta, error)
|
||||||
Users(ctx context.Context) ([]*model.User, error)
|
Users(ctx context.Context) ([]*model.User, error)
|
||||||
Token(ctx context.Context) (*model.LoginResponse, error)
|
Token(ctx context.Context) (*model.AuthResponse, error)
|
||||||
Profile(ctx context.Context) (*model.User, error)
|
Profile(ctx context.Context) (*model.User, error)
|
||||||
VerificationRequests(ctx context.Context) ([]*model.VerificationRequest, error)
|
VerificationRequests(ctx context.Context) ([]*model.VerificationRequest, error)
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,34 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
_ = ec
|
_ = ec
|
||||||
switch typeName + "." + field {
|
switch typeName + "." + field {
|
||||||
|
|
||||||
|
case "AuthResponse.accessToken":
|
||||||
|
if e.complexity.AuthResponse.AccessToken == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.AuthResponse.AccessToken(childComplexity), true
|
||||||
|
|
||||||
|
case "AuthResponse.accessTokenExpiresAt":
|
||||||
|
if e.complexity.AuthResponse.AccessTokenExpiresAt == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.AuthResponse.AccessTokenExpiresAt(childComplexity), true
|
||||||
|
|
||||||
|
case "AuthResponse.message":
|
||||||
|
if e.complexity.AuthResponse.Message == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.AuthResponse.Message(childComplexity), true
|
||||||
|
|
||||||
|
case "AuthResponse.user":
|
||||||
|
if e.complexity.AuthResponse.User == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.AuthResponse.User(childComplexity), true
|
||||||
|
|
||||||
case "Error.message":
|
case "Error.message":
|
||||||
if e.complexity.Error.Message == nil {
|
if e.complexity.Error.Message == nil {
|
||||||
break
|
break
|
||||||
|
@ -158,34 +186,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
|
|
||||||
return e.complexity.Error.Reason(childComplexity), true
|
return e.complexity.Error.Reason(childComplexity), true
|
||||||
|
|
||||||
case "LoginResponse.accessToken":
|
|
||||||
if e.complexity.LoginResponse.AccessToken == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.LoginResponse.AccessToken(childComplexity), true
|
|
||||||
|
|
||||||
case "LoginResponse.accessTokenExpiresAt":
|
|
||||||
if e.complexity.LoginResponse.AccessTokenExpiresAt == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.LoginResponse.AccessTokenExpiresAt(childComplexity), true
|
|
||||||
|
|
||||||
case "LoginResponse.message":
|
|
||||||
if e.complexity.LoginResponse.Message == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.LoginResponse.Message(childComplexity), true
|
|
||||||
|
|
||||||
case "LoginResponse.user":
|
|
||||||
if e.complexity.LoginResponse.User == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.LoginResponse.User(childComplexity), true
|
|
||||||
|
|
||||||
case "Meta.isBasicAuthenticationEnabled":
|
case "Meta.isBasicAuthenticationEnabled":
|
||||||
if e.complexity.Meta.IsBasicAuthenticationEnabled == nil {
|
if e.complexity.Meta.IsBasicAuthenticationEnabled == nil {
|
||||||
break
|
break
|
||||||
|
@ -586,7 +586,7 @@ type Error {
|
||||||
reason: String!
|
reason: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse {
|
type AuthResponse {
|
||||||
message: String!
|
message: String!
|
||||||
accessToken: String
|
accessToken: String
|
||||||
accessTokenExpiresAt: Int64
|
accessTokenExpiresAt: Int64
|
||||||
|
@ -640,11 +640,11 @@ input ResetPassowrdInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
signup(params: SignUpInput!): Response!
|
signup(params: SignUpInput!): AuthResponse!
|
||||||
login(params: LoginInput!): LoginResponse!
|
login(params: LoginInput!): AuthResponse!
|
||||||
logout: Response!
|
logout: Response!
|
||||||
updateProfile(params: UpdateProfileInput!): Response!
|
updateProfile(params: UpdateProfileInput!): Response!
|
||||||
verifyEmail(params: VerifyEmailInput!): LoginResponse!
|
verifyEmail(params: VerifyEmailInput!): AuthResponse!
|
||||||
resendVerifyEmail(params: ResendVerifyEmailInput!): Response!
|
resendVerifyEmail(params: ResendVerifyEmailInput!): Response!
|
||||||
forgotPassword(params: ForgotPasswordInput!): Response!
|
forgotPassword(params: ForgotPasswordInput!): Response!
|
||||||
resetPassword(params: ResetPassowrdInput!): Response!
|
resetPassword(params: ResetPassowrdInput!): Response!
|
||||||
|
@ -653,7 +653,7 @@ type Mutation {
|
||||||
type Query {
|
type Query {
|
||||||
meta: Meta!
|
meta: Meta!
|
||||||
users: [User!]!
|
users: [User!]!
|
||||||
token: LoginResponse
|
token: AuthResponse
|
||||||
profile: User!
|
profile: User!
|
||||||
verificationRequests: [VerificationRequest!]!
|
verificationRequests: [VerificationRequest!]!
|
||||||
}
|
}
|
||||||
|
@ -823,6 +823,137 @@ func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArg
|
||||||
|
|
||||||
// region **************************** field.gotpl *****************************
|
// region **************************** field.gotpl *****************************
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse_message(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: "AuthResponse",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.Message, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
if !graphql.HasFieldError(ctx, fc) {
|
||||||
|
ec.Errorf(ctx, "must not be null")
|
||||||
|
}
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(string)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse_accessToken(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: "AuthResponse",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.AccessToken, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(*string)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse_accessTokenExpiresAt(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: "AuthResponse",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.AccessTokenExpiresAt, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(*int64)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalOInt642ᚖint64(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse_user(ctx context.Context, field graphql.CollectedField, obj *model.AuthResponse) (ret graphql.Marshaler) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
fc := &graphql.FieldContext{
|
||||||
|
Object: "AuthResponse",
|
||||||
|
Field: field,
|
||||||
|
Args: nil,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.User, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(*model.User)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalOUser2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Error_message(ctx context.Context, field graphql.CollectedField, obj *model.Error) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Error_message(ctx context.Context, field graphql.CollectedField, obj *model.Error) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -893,137 +1024,6 @@ func (ec *executionContext) _Error_reason(ctx context.Context, field graphql.Col
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _LoginResponse_message(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "LoginResponse",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.Message, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _LoginResponse_accessToken(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "LoginResponse",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.AccessToken, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _LoginResponse_accessTokenExpiresAt(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "LoginResponse",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.AccessTokenExpiresAt, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*int64)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalOInt642ᚖint64(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _LoginResponse_user(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "LoginResponse",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.User, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*model.User)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalOUser2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐUser(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _Meta_version(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Meta_version(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -1306,9 +1306,9 @@ func (ec *executionContext) _Mutation_signup(ctx context.Context, field graphql.
|
||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(*model.Response)
|
res := resTmp.(*model.AuthResponse)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐResponse(ctx, field.Selections, res)
|
return ec.marshalNAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
|
@ -1348,9 +1348,9 @@ func (ec *executionContext) _Mutation_login(ctx context.Context, field graphql.C
|
||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(*model.LoginResponse)
|
res := resTmp.(*model.AuthResponse)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNLoginResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res)
|
return ec.marshalNAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Mutation_logout(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Mutation_logout(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
|
@ -1467,9 +1467,9 @@ func (ec *executionContext) _Mutation_verifyEmail(ctx context.Context, field gra
|
||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(*model.LoginResponse)
|
res := resTmp.(*model.AuthResponse)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNLoginResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res)
|
return ec.marshalNAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Mutation_resendVerifyEmail(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Mutation_resendVerifyEmail(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
|
@ -1695,9 +1695,9 @@ func (ec *executionContext) _Query_token(ctx context.Context, field graphql.Coll
|
||||||
if resTmp == nil {
|
if resTmp == nil {
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(*model.LoginResponse)
|
res := resTmp.(*model.AuthResponse)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalOLoginResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res)
|
return ec.marshalOAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Query_profile(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Query_profile(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
|
@ -3747,6 +3747,39 @@ func (ec *executionContext) unmarshalInputVerifyEmailInput(ctx context.Context,
|
||||||
|
|
||||||
// region **************************** object.gotpl ****************************
|
// region **************************** object.gotpl ****************************
|
||||||
|
|
||||||
|
var authResponseImplementors = []string{"AuthResponse"}
|
||||||
|
|
||||||
|
func (ec *executionContext) _AuthResponse(ctx context.Context, sel ast.SelectionSet, obj *model.AuthResponse) graphql.Marshaler {
|
||||||
|
fields := graphql.CollectFields(ec.OperationContext, sel, authResponseImplementors)
|
||||||
|
|
||||||
|
out := graphql.NewFieldSet(fields)
|
||||||
|
var invalids uint32
|
||||||
|
for i, field := range fields {
|
||||||
|
switch field.Name {
|
||||||
|
case "__typename":
|
||||||
|
out.Values[i] = graphql.MarshalString("AuthResponse")
|
||||||
|
case "message":
|
||||||
|
out.Values[i] = ec._AuthResponse_message(ctx, field, obj)
|
||||||
|
if out.Values[i] == graphql.Null {
|
||||||
|
invalids++
|
||||||
|
}
|
||||||
|
case "accessToken":
|
||||||
|
out.Values[i] = ec._AuthResponse_accessToken(ctx, field, obj)
|
||||||
|
case "accessTokenExpiresAt":
|
||||||
|
out.Values[i] = ec._AuthResponse_accessTokenExpiresAt(ctx, field, obj)
|
||||||
|
case "user":
|
||||||
|
out.Values[i] = ec._AuthResponse_user(ctx, field, obj)
|
||||||
|
default:
|
||||||
|
panic("unknown field " + strconv.Quote(field.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.Dispatch()
|
||||||
|
if invalids > 0 {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
var errorImplementors = []string{"Error"}
|
var errorImplementors = []string{"Error"}
|
||||||
|
|
||||||
func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, obj *model.Error) graphql.Marshaler {
|
func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, obj *model.Error) graphql.Marshaler {
|
||||||
|
@ -3779,39 +3812,6 @@ func (ec *executionContext) _Error(ctx context.Context, sel ast.SelectionSet, ob
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
var loginResponseImplementors = []string{"LoginResponse"}
|
|
||||||
|
|
||||||
func (ec *executionContext) _LoginResponse(ctx context.Context, sel ast.SelectionSet, obj *model.LoginResponse) graphql.Marshaler {
|
|
||||||
fields := graphql.CollectFields(ec.OperationContext, sel, loginResponseImplementors)
|
|
||||||
|
|
||||||
out := graphql.NewFieldSet(fields)
|
|
||||||
var invalids uint32
|
|
||||||
for i, field := range fields {
|
|
||||||
switch field.Name {
|
|
||||||
case "__typename":
|
|
||||||
out.Values[i] = graphql.MarshalString("LoginResponse")
|
|
||||||
case "message":
|
|
||||||
out.Values[i] = ec._LoginResponse_message(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
invalids++
|
|
||||||
}
|
|
||||||
case "accessToken":
|
|
||||||
out.Values[i] = ec._LoginResponse_accessToken(ctx, field, obj)
|
|
||||||
case "accessTokenExpiresAt":
|
|
||||||
out.Values[i] = ec._LoginResponse_accessTokenExpiresAt(ctx, field, obj)
|
|
||||||
case "user":
|
|
||||||
out.Values[i] = ec._LoginResponse_user(ctx, field, obj)
|
|
||||||
default:
|
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.Dispatch()
|
|
||||||
if invalids > 0 {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
var metaImplementors = []string{"Meta"}
|
var metaImplementors = []string{"Meta"}
|
||||||
|
|
||||||
func (ec *executionContext) _Meta(ctx context.Context, sel ast.SelectionSet, obj *model.Meta) graphql.Marshaler {
|
func (ec *executionContext) _Meta(ctx context.Context, sel ast.SelectionSet, obj *model.Meta) graphql.Marshaler {
|
||||||
|
@ -4392,6 +4392,20 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o
|
||||||
|
|
||||||
// region ***************************** type.gotpl *****************************
|
// region ***************************** type.gotpl *****************************
|
||||||
|
|
||||||
|
func (ec *executionContext) marshalNAuthResponse2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx context.Context, sel ast.SelectionSet, v model.AuthResponse) graphql.Marshaler {
|
||||||
|
return ec._AuthResponse(ctx, sel, &v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) marshalNAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx context.Context, sel ast.SelectionSet, v *model.AuthResponse) graphql.Marshaler {
|
||||||
|
if v == nil {
|
||||||
|
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||||
|
ec.Errorf(ctx, "must not be null")
|
||||||
|
}
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
return ec._AuthResponse(ctx, sel, v)
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) {
|
func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) {
|
||||||
res, err := graphql.UnmarshalBoolean(v)
|
res, err := graphql.UnmarshalBoolean(v)
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
@ -4432,20 +4446,6 @@ func (ec *executionContext) unmarshalNLoginInput2githubᚗcomᚋauthorizerdevᚋ
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalNLoginResponse2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v model.LoginResponse) graphql.Marshaler {
|
|
||||||
return ec._LoginResponse(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNLoginResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v *model.LoginResponse) graphql.Marshaler {
|
|
||||||
if v == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return ec._LoginResponse(ctx, sel, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNMeta2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐMeta(ctx context.Context, sel ast.SelectionSet, v model.Meta) graphql.Marshaler {
|
func (ec *executionContext) marshalNMeta2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐMeta(ctx context.Context, sel ast.SelectionSet, v model.Meta) graphql.Marshaler {
|
||||||
return ec._Meta(ctx, sel, &v)
|
return ec._Meta(ctx, sel, &v)
|
||||||
}
|
}
|
||||||
|
@ -4841,6 +4841,13 @@ func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel a
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) marshalOAuthResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐAuthResponse(ctx context.Context, sel ast.SelectionSet, v *model.AuthResponse) graphql.Marshaler {
|
||||||
|
if v == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
return ec._AuthResponse(ctx, sel, v)
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) {
|
func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) {
|
||||||
res, err := graphql.UnmarshalBoolean(v)
|
res, err := graphql.UnmarshalBoolean(v)
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
@ -4880,13 +4887,6 @@ func (ec *executionContext) marshalOInt642ᚖint64(ctx context.Context, sel ast.
|
||||||
return graphql.MarshalInt64(*v)
|
return graphql.MarshalInt64(*v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalOLoginResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v *model.LoginResponse) graphql.Marshaler {
|
|
||||||
if v == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
return ec._LoginResponse(ctx, sel, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) {
|
func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) {
|
||||||
res, err := graphql.UnmarshalString(v)
|
res, err := graphql.UnmarshalString(v)
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
type AuthResponse struct {
|
||||||
|
Message string `json:"message"`
|
||||||
|
AccessToken *string `json:"accessToken"`
|
||||||
|
AccessTokenExpiresAt *int64 `json:"accessTokenExpiresAt"`
|
||||||
|
User *User `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
|
@ -16,13 +23,6 @@ type LoginInput struct {
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse struct {
|
|
||||||
Message string `json:"message"`
|
|
||||||
AccessToken *string `json:"accessToken"`
|
|
||||||
AccessTokenExpiresAt *int64 `json:"accessTokenExpiresAt"`
|
|
||||||
User *User `json:"user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
IsGoogleLoginEnabled bool `json:"isGoogleLoginEnabled"`
|
IsGoogleLoginEnabled bool `json:"isGoogleLoginEnabled"`
|
||||||
|
|
|
@ -40,7 +40,7 @@ type Error {
|
||||||
reason: String!
|
reason: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse {
|
type AuthResponse {
|
||||||
message: String!
|
message: String!
|
||||||
accessToken: String
|
accessToken: String
|
||||||
accessTokenExpiresAt: Int64
|
accessTokenExpiresAt: Int64
|
||||||
|
@ -94,11 +94,11 @@ input ResetPassowrdInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mutation {
|
type Mutation {
|
||||||
signup(params: SignUpInput!): Response!
|
signup(params: SignUpInput!): AuthResponse!
|
||||||
login(params: LoginInput!): LoginResponse!
|
login(params: LoginInput!): AuthResponse!
|
||||||
logout: Response!
|
logout: Response!
|
||||||
updateProfile(params: UpdateProfileInput!): Response!
|
updateProfile(params: UpdateProfileInput!): Response!
|
||||||
verifyEmail(params: VerifyEmailInput!): LoginResponse!
|
verifyEmail(params: VerifyEmailInput!): AuthResponse!
|
||||||
resendVerifyEmail(params: ResendVerifyEmailInput!): Response!
|
resendVerifyEmail(params: ResendVerifyEmailInput!): Response!
|
||||||
forgotPassword(params: ForgotPasswordInput!): Response!
|
forgotPassword(params: ForgotPasswordInput!): Response!
|
||||||
resetPassword(params: ResetPassowrdInput!): Response!
|
resetPassword(params: ResetPassowrdInput!): Response!
|
||||||
|
@ -107,7 +107,7 @@ type Mutation {
|
||||||
type Query {
|
type Query {
|
||||||
meta: Meta!
|
meta: Meta!
|
||||||
users: [User!]!
|
users: [User!]!
|
||||||
token: LoginResponse
|
token: AuthResponse
|
||||||
profile: User!
|
profile: User!
|
||||||
verificationRequests: [VerificationRequest!]!
|
verificationRequests: [VerificationRequest!]!
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ import (
|
||||||
"github.com/authorizerdev/authorizer/server/resolvers"
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *mutationResolver) Signup(ctx context.Context, params model.SignUpInput) (*model.Response, error) {
|
func (r *mutationResolver) Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse, error) {
|
||||||
return resolvers.Signup(ctx, params)
|
return resolvers.Signup(ctx, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mutationResolver) Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse, error) {
|
func (r *mutationResolver) Login(ctx context.Context, params model.LoginInput) (*model.AuthResponse, error) {
|
||||||
return resolvers.Login(ctx, params)
|
return resolvers.Login(ctx, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ func (r *mutationResolver) UpdateProfile(ctx context.Context, params model.Updat
|
||||||
return resolvers.UpdateProfile(ctx, params)
|
return resolvers.UpdateProfile(ctx, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mutationResolver) VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.LoginResponse, error) {
|
func (r *mutationResolver) VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.AuthResponse, error) {
|
||||||
return resolvers.VerifyEmail(ctx, params)
|
return resolvers.VerifyEmail(ctx, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func (r *queryResolver) Users(ctx context.Context) ([]*model.User, error) {
|
||||||
return resolvers.Users(ctx)
|
return resolvers.Users(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *queryResolver) Token(ctx context.Context) (*model.LoginResponse, error) {
|
func (r *queryResolver) Token(ctx context.Context) (*model.AuthResponse, error) {
|
||||||
return resolvers.Token(ctx)
|
return resolvers.Token(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -15,6 +16,10 @@ import (
|
||||||
|
|
||||||
func ForgotPassword(ctx context.Context, params model.ForgotPasswordInput) (*model.Response, error) {
|
func ForgotPassword(ctx context.Context, params model.ForgotPasswordInput) (*model.Response, error) {
|
||||||
var res *model.Response
|
var res *model.Response
|
||||||
|
if constants.DISABLE_BASIC_AUTHENTICATION == "true" {
|
||||||
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
|
}
|
||||||
|
|
||||||
params.Email = strings.ToLower(params.Email)
|
params.Email = strings.ToLower(params.Email)
|
||||||
|
|
||||||
if !utils.IsValidEmail(params.Email) {
|
if !utils.IsValidEmail(params.Email) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
@ -14,13 +15,17 @@ import (
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse, error) {
|
func Login(ctx context.Context, params model.LoginInput) (*model.AuthResponse, error) {
|
||||||
gc, err := utils.GinContextFromContext(ctx)
|
gc, err := utils.GinContextFromContext(ctx)
|
||||||
var res *model.LoginResponse
|
var res *model.AuthResponse
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if constants.DISABLE_BASIC_AUTHENTICATION == "true" {
|
||||||
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
|
}
|
||||||
|
|
||||||
params.Email = strings.ToLower(params.Email)
|
params.Email = strings.ToLower(params.Email)
|
||||||
user, err := db.Mgr.GetUserByEmail(params.Email)
|
user, err := db.Mgr.GetUserByEmail(params.Email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,7 +59,7 @@ func Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse,
|
||||||
|
|
||||||
session.SetToken(userIdStr, refreshToken)
|
session.SetToken(userIdStr, refreshToken)
|
||||||
|
|
||||||
res = &model.LoginResponse{
|
res = &model.AuthResponse{
|
||||||
Message: `Logged in successfully`,
|
Message: `Logged in successfully`,
|
||||||
AccessToken: &accessToken,
|
AccessToken: &accessToken,
|
||||||
AccessTokenExpiresAt: &expiresAt,
|
AccessTokenExpiresAt: &expiresAt,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
|
@ -11,6 +12,9 @@ import (
|
||||||
|
|
||||||
func ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error) {
|
func ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error) {
|
||||||
var res *model.Response
|
var res *model.Response
|
||||||
|
if constants.DISABLE_BASIC_AUTHENTICATION == "true" {
|
||||||
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
|
}
|
||||||
|
|
||||||
if params.Password != params.ConfirmPassword {
|
if params.Password != params.ConfirmPassword {
|
||||||
return res, fmt.Errorf(`passwords don't match`)
|
return res, fmt.Errorf(`passwords don't match`)
|
||||||
|
|
|
@ -7,14 +7,24 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
"github.com/authorizerdev/authorizer/server/session"
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Signup(ctx context.Context, params model.SignUpInput) (*model.Response, error) {
|
func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse, error) {
|
||||||
var res *model.Response
|
gc, err := utils.GinContextFromContext(ctx)
|
||||||
|
var res *model.AuthResponse
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if constants.DISABLE_BASIC_AUTHENTICATION == "true" {
|
||||||
|
return res, fmt.Errorf(`basic authentication is disabled for this instance`)
|
||||||
|
}
|
||||||
if params.ConfirmPassword != params.Password {
|
if params.ConfirmPassword != params.Password {
|
||||||
return res, fmt.Errorf(`passowrd and confirm password does not match`)
|
return res, fmt.Errorf(`passowrd and confirm password does not match`)
|
||||||
}
|
}
|
||||||
|
@ -51,31 +61,70 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.Response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
user.SignupMethod = enum.BasicAuth.String()
|
user.SignupMethod = enum.BasicAuth.String()
|
||||||
|
if constants.DISABLE_EMAIL_VERICATION == "true" {
|
||||||
|
user.EmailVerifiedAt = time.Now().Unix()
|
||||||
|
}
|
||||||
_, err = db.Mgr.SaveUser(user)
|
_, err = db.Mgr.SaveUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
userIdStr := fmt.Sprintf("%d", user.ID)
|
||||||
// insert verification request
|
userToReturn := &model.User{
|
||||||
verificationType := enum.BasicAuthSignup.String()
|
ID: userIdStr,
|
||||||
token, err := utils.CreateVerificationToken(params.Email, verificationType)
|
Email: user.Email,
|
||||||
if err != nil {
|
Image: &user.Image,
|
||||||
log.Println(`Error generating token`, err)
|
FirstName: &user.FirstName,
|
||||||
|
LastName: &user.LastName,
|
||||||
|
SignupMethod: user.SignupMethod,
|
||||||
|
EmailVerifiedAt: &user.EmailVerifiedAt,
|
||||||
|
CreatedAt: &user.CreatedAt,
|
||||||
|
UpdatedAt: &user.UpdatedAt,
|
||||||
}
|
}
|
||||||
db.Mgr.AddVerification(db.VerificationRequest{
|
|
||||||
Token: token,
|
|
||||||
Identifier: verificationType,
|
|
||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
|
||||||
Email: params.Email,
|
|
||||||
})
|
|
||||||
|
|
||||||
// exec it as go routin so that we can reduce the api latency
|
if constants.DISABLE_EMAIL_VERICATION != "true" {
|
||||||
go func() {
|
// insert verification request
|
||||||
utils.SendVerificationMail(params.Email, token)
|
verificationType := enum.BasicAuthSignup.String()
|
||||||
}()
|
token, err := utils.CreateVerificationToken(params.Email, verificationType)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(`Error generating token`, err)
|
||||||
|
}
|
||||||
|
db.Mgr.AddVerification(db.VerificationRequest{
|
||||||
|
Token: token,
|
||||||
|
Identifier: verificationType,
|
||||||
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
|
Email: params.Email,
|
||||||
|
})
|
||||||
|
|
||||||
res = &model.Response{
|
// exec it as go routin so that we can reduce the api latency
|
||||||
Message: `Verification email has been sent. Please check your inbox`,
|
go func() {
|
||||||
|
utils.SendVerificationMail(params.Email, token)
|
||||||
|
}()
|
||||||
|
|
||||||
|
res = &model.AuthResponse{
|
||||||
|
Message: `Verification email has been sent. Please check your inbox`,
|
||||||
|
User: userToReturn,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
refreshToken, _, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||||
|
ID: userIdStr,
|
||||||
|
Email: user.Email,
|
||||||
|
}, enum.RefreshToken)
|
||||||
|
|
||||||
|
accessToken, expiresAt, _ := utils.CreateAuthToken(utils.UserAuthInfo{
|
||||||
|
ID: userIdStr,
|
||||||
|
Email: user.Email,
|
||||||
|
}, enum.AccessToken)
|
||||||
|
|
||||||
|
session.SetToken(userIdStr, refreshToken)
|
||||||
|
res = &model.AuthResponse{
|
||||||
|
Message: `Signed up successfully.`,
|
||||||
|
AccessToken: &accessToken,
|
||||||
|
AccessTokenExpiresAt: &expiresAt,
|
||||||
|
User: userToReturn,
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.SetCookie(gc, accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
|
@ -13,10 +13,10 @@ import (
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Token(ctx context.Context) (*model.LoginResponse, error) {
|
func Token(ctx context.Context) (*model.AuthResponse, error) {
|
||||||
metaInfo := utils.GetMetaInfo()
|
metaInfo := utils.GetMetaInfo()
|
||||||
log.Println("=> meta", metaInfo)
|
log.Println("=> meta", metaInfo)
|
||||||
var res *model.LoginResponse
|
var res *model.AuthResponse
|
||||||
|
|
||||||
gc, err := utils.GinContextFromContext(ctx)
|
gc, err := utils.GinContextFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,7 +55,7 @@ func Token(ctx context.Context) (*model.LoginResponse, error) {
|
||||||
}, enum.AccessToken)
|
}, enum.AccessToken)
|
||||||
}
|
}
|
||||||
utils.SetCookie(gc, token)
|
utils.SetCookie(gc, token)
|
||||||
res = &model.LoginResponse{
|
res = &model.AuthResponse{
|
||||||
Message: `Token verified`,
|
Message: `Token verified`,
|
||||||
AccessToken: &token,
|
AccessToken: &token,
|
||||||
AccessTokenExpiresAt: &expiresAt,
|
AccessTokenExpiresAt: &expiresAt,
|
||||||
|
|
|
@ -12,9 +12,9 @@ import (
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.LoginResponse, error) {
|
func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.AuthResponse, error) {
|
||||||
gc, err := utils.GinContextFromContext(ctx)
|
gc, err := utils.GinContextFromContext(ctx)
|
||||||
var res *model.LoginResponse
|
var res *model.AuthResponse
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.Log
|
||||||
|
|
||||||
session.SetToken(userIdStr, refreshToken)
|
session.SetToken(userIdStr, refreshToken)
|
||||||
|
|
||||||
res = &model.LoginResponse{
|
res = &model.AuthResponse{
|
||||||
Message: `Email verified successfully.`,
|
Message: `Email verified successfully.`,
|
||||||
AccessToken: &accessToken,
|
AccessToken: &accessToken,
|
||||||
AccessTokenExpiresAt: &expiresAt,
|
AccessTokenExpiresAt: &expiresAt,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user