Esempio n. 1
0
File: users.go Progetto: coddo/gost
// CreateAppUser creates a new ApplicationUser with the given data, generates an activation token
// and sends an email containing a link used for activating the account
func CreateAppUser(emailAddress, password string, accountType int, activationServiceLink string) (*identity.ApplicationUser, error) {
	var token, err = util.GenerateUUID()
	if err != nil {
		return nil, err
	}

	passwordHash, err := util.HashString(password)
	if err != nil {
		return nil, err
	}

	var user = &identity.ApplicationUser{
		ID:                             bson.NewObjectId(),
		Email:                          emailAddress,
		Password:                       passwordHash,
		AccountType:                    accountType,
		ActivateAccountToken:           token,
		ActivateAccountTokenExpireDate: util.NextDateFromNow(accountActivationTokenExpireTime),
	}

	err = identity.CreateUser(user)
	if err != nil {
		return nil, err
	}

	go sendAccountActivationEmail(emailAddress, activationServiceLink, token)

	return user, nil
}
Esempio n. 2
0
File: users.go Progetto: coddo/gost
// ResetPassword resets the password of an application user
func ResetPassword(token, password string) error {
	var user, err = identity.GetUserByResetPasswordToken(token)
	if err != nil {
		return err
	}

	if util.IsDateExpiredFromNow(user.ResetPasswordTokenExpireDate) {
		return ErrResetPasswordTokenExpired
	}

	passwordHash, err := util.HashString(password)
	if err != nil {
		return err
	}

	user.Password = passwordHash

	return identity.UpdateUser(user)
}