Exemplo n.º 1
0
// Register performs some validation checks before creating a User record
// in the datastore.
func (auth *AuthService) Register(user *models.User) *models.User {
	// Check if a user exists with the same name, email address
	existingUser, err := auth.UserDAO.GetByName(user.Name)
	if existingUser != nil {
		return nil
	}

	// Although user.PasswordHash is set, it has not been has not been hashed yet
	// so let's take care of that before creating the record.
	hash, err := auth.HashPassword(user.PasswordHash)
	if err != nil {
		return nil
	}

	user.PasswordHash = hash

	_, err = auth.UserDAO.Create(user)
	if err != nil {
		return nil
	}

	return user
}