@@ -34,9 +34,7 @@ func Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse,
|
||||
if user.EmailVerifiedAt <= 0 {
|
||||
return res, fmt.Errorf(`email not verified`)
|
||||
}
|
||||
// match password
|
||||
cost, err := bcrypt.Cost([]byte(user.Password))
|
||||
log.Println(cost, err)
|
||||
|
||||
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(params.Password))
|
||||
|
||||
if err != nil {
|
||||
@@ -68,6 +66,8 @@ func Login(ctx context.Context, params model.LoginInput) (*model.LoginResponse,
|
||||
LastName: &user.LastName,
|
||||
SignupMethod: user.SignupMethod,
|
||||
EmailVerifiedAt: &user.EmailVerifiedAt,
|
||||
CreatedAt: &user.CreatedAt,
|
||||
UpdatedAt: &user.UpdatedAt,
|
||||
},
|
||||
}
|
||||
|
||||
|
@@ -48,6 +48,8 @@ func Profile(ctx context.Context) (*model.User, error) {
|
||||
LastName: &user.LastName,
|
||||
SignupMethod: user.SignupMethod,
|
||||
EmailVerifiedAt: &user.EmailVerifiedAt,
|
||||
CreatedAt: &user.CreatedAt,
|
||||
UpdatedAt: &user.UpdatedAt,
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
@@ -62,7 +62,7 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.Response, err
|
||||
if err != nil {
|
||||
log.Println(`Error generating token`, err)
|
||||
}
|
||||
db.Mgr.AddVerification(db.Verification{
|
||||
db.Mgr.AddVerification(db.VerificationRequest{
|
||||
Token: token,
|
||||
Identifier: verificationType,
|
||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||
|
@@ -58,6 +58,8 @@ func Token(ctx context.Context) (*model.LoginResponse, error) {
|
||||
Image: &user.Image,
|
||||
FirstName: &user.FirstName,
|
||||
LastName: &user.LastName,
|
||||
CreatedAt: &user.CreatedAt,
|
||||
UpdatedAt: &user.UpdatedAt,
|
||||
},
|
||||
}
|
||||
return res, nil
|
||||
|
@@ -109,7 +109,7 @@ func UpdateProfile(ctx context.Context, params model.UpdateProfileInput) (*model
|
||||
if err != nil {
|
||||
log.Println(`Error generating token`, err)
|
||||
}
|
||||
db.Mgr.AddVerification(db.Verification{
|
||||
db.Mgr.AddVerification(db.VerificationRequest{
|
||||
Token: token,
|
||||
Identifier: verificationType,
|
||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||
|
@@ -34,6 +34,8 @@ func Users(ctx context.Context) ([]*model.User, error) {
|
||||
LastName: &user.LastName,
|
||||
Password: &user.Password,
|
||||
EmailVerifiedAt: &user.EmailVerifiedAt,
|
||||
CreatedAt: &user.CreatedAt,
|
||||
UpdatedAt: &user.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
|
40
server/resolvers/verificationRequests.go
Normal file
40
server/resolvers/verificationRequests.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package resolvers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/yauthdev/yauth/server/db"
|
||||
"github.com/yauthdev/yauth/server/graph/model"
|
||||
"github.com/yauthdev/yauth/server/utils"
|
||||
)
|
||||
|
||||
func VerificationRequests(ctx context.Context) ([]*model.VerificationRequest, error) {
|
||||
gc, err := utils.GinContextFromContext(ctx)
|
||||
var res []*model.VerificationRequest
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
if !utils.IsSuperAdmin(gc) {
|
||||
return res, fmt.Errorf("unauthorized")
|
||||
}
|
||||
|
||||
verificationRequests, err := db.Mgr.GetVerificationRequests()
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
for _, verificationRequest := range verificationRequests {
|
||||
res = append(res, &model.VerificationRequest{
|
||||
ID: fmt.Sprintf("%d", verificationRequest.ID),
|
||||
Email: &verificationRequest.Email,
|
||||
Token: &verificationRequest.Token,
|
||||
Expires: &verificationRequest.ExpiresAt,
|
||||
CreatedAt: &verificationRequest.CreatedAt,
|
||||
UpdatedAt: &verificationRequest.UpdatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
@@ -65,6 +65,8 @@ func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.Log
|
||||
LastName: &user.LastName,
|
||||
SignupMethod: user.SignupMethod,
|
||||
EmailVerifiedAt: &user.EmailVerifiedAt,
|
||||
CreatedAt: &user.CreatedAt,
|
||||
UpdatedAt: &user.UpdatedAt,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user