add FindUserByEmai
This commit is contained in:
parent
4d632ed042
commit
445cacc540
10
action.go
10
action.go
|
@ -24,6 +24,16 @@ func (s Service) FindUser(userID string) (model.User, error) {
|
|||
return user.FindUser(userID)
|
||||
}
|
||||
|
||||
// FindUserByEmail ...
|
||||
func (s Service) FindUserByEmail(email string) (model.User, error) {
|
||||
return user.FindUserByEmail(email)
|
||||
}
|
||||
|
||||
// GetHashedPassword ...
|
||||
func (s Service) GetHashedPassword(userID string) (string, error) {
|
||||
return user.GetHashedPassword(userID)
|
||||
}
|
||||
|
||||
// UpdateUser ...
|
||||
func (s Service) UpdateUser(userID string, payload model.UserUpdateOptions) error {
|
||||
return user.UpdateByUserID(userID, payload)
|
||||
|
|
|
@ -98,6 +98,49 @@ func FindUser(userID string) (r model.User, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// FindUserByEmail ...
|
||||
func FindUserByEmail(email string) (r model.User, err error) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
// Find user exists or not
|
||||
if email == "" {
|
||||
err = errors.New("invalid email data")
|
||||
return
|
||||
}
|
||||
user, _ := findOneByCondition(ctx, bson.M{"email": email})
|
||||
if user.ID.IsZero() {
|
||||
err = errors.New("user not found")
|
||||
return
|
||||
}
|
||||
|
||||
r = getResponse(ctx, user)
|
||||
return
|
||||
}
|
||||
|
||||
// GetHashedPassword ...
|
||||
func GetHashedPassword(userID string) (result string, err error) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
// Find user exists or not
|
||||
id, isValid := mongodb.NewIDFromString(userID)
|
||||
if !isValid {
|
||||
err = errors.New("invalid email data")
|
||||
return
|
||||
}
|
||||
user, _ := findByID(ctx, id)
|
||||
if user.ID.IsZero() {
|
||||
err = errors.New("user not found")
|
||||
return
|
||||
}
|
||||
|
||||
result = user.HashedPassword
|
||||
return
|
||||
}
|
||||
|
||||
// All ...
|
||||
func All(queryParams model.UserAllQuery) (r model.UserAll) {
|
||||
var (
|
||||
|
|
Loading…
Reference in New Issue