mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-15 12:34:44 +00:00
Support for password resets
This commit is contained in:
36
codes/handler/verify.go
Normal file
36
codes/handler/verify.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
pb "github.com/micro/services/codes/proto"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (c *Codes) Verify(ctx context.Context, req *pb.VerifyRequest, rsp *pb.VerifyResponse) error {
|
||||
// validate the request
|
||||
if len(req.Code) == 0 {
|
||||
return ErrMissingCode
|
||||
}
|
||||
if len(req.Identity) == 0 {
|
||||
return ErrMissingIdentity
|
||||
}
|
||||
|
||||
// lookup the code
|
||||
var code Code
|
||||
if err := c.DB.Where(&Code{Code: req.Code, Identity: req.Identity}).First(&code).Error; err == gorm.ErrRecordNotFound {
|
||||
return ErrInvalidCode
|
||||
} else if err != nil {
|
||||
logger.Errorf("Error reading code from database: %v", err)
|
||||
return errors.InternalServerError("DATABASE_ERORR", "Error connecting to database")
|
||||
}
|
||||
|
||||
// check the invite hasn't expired
|
||||
if code.ExpiresAt.Before(c.Time()) {
|
||||
return ErrExpiredCode
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user