Create function
(params interface{}, accountID primitive.ObjectID)
| 61 | |
| 62 | // Create function |
| 63 | func (userService *UserService) Create(params interface{}, accountID primitive.ObjectID) (createdUser *models.User, err error) { |
| 64 | user := &models.User{} |
| 65 | err = mapstructure.Decode(params, &user) |
| 66 | |
| 67 | // check if email unique |
| 68 | existentUser := &models.User{} |
| 69 | err = userService.getCollection().First(bson.M{"email": user.Email}, existentUser) |
| 70 | if existentUser.ID != primitive.NilObjectID { |
| 71 | return existentUser, errors.New("email is invalid or already taken") |
| 72 | } |
| 73 | // if user.Password != "" { |
| 74 | // hash, _ := hashPassword(user.Password) |
| 75 | // user.Password = hash |
| 76 | // } else { |
| 77 | // defer emailService.SendForgotPasswordEmail(bson.M{"email": user.Email}) |
| 78 | // } |
| 79 | |
| 80 | defer emailService.SendActiveEmail(bson.M{"email": user.Email}) |
| 81 | ssoUUID, _ := uuid.NewRandom() |
| 82 | user.Sso = ssoUUID.String() |
| 83 | user.AccountID = accountID |
| 84 | user.Active = true |
| 85 | user.Teams = []models.TeamInner{} |
| 86 | err = userService.getCollection().Create(user) |
| 87 | return user, err |
| 88 | } |
| 89 | |
| 90 | // UpdatePassword function |
| 91 | func (userService *UserService) UpdatePassword(id interface{}, password string) (updatedUser *models.User, err error) { |
no test coverage detected