Exemplo n.º 1
0
func (dao *UserDAO) Create(user *m.User) (string, error) {

	user.CreatedAt = time.Now()
	user.UpdatedAt = time.Now()

	result, err := r.Table("users").Insert(user).RunWrite(dao.Session)
	if err != nil {
		log.Println(err)
	}

	user.ID = result.GeneratedKeys[0]
	return user.ID, nil
}
Exemplo n.º 2
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
}