//RegisterUser registers a user and returns a SessionToken
RegisterUser registers a user and returns a SessionToken
// RegisterUser registers a user and returns a SessionToken
func (ac *AuthController) RegisterUser(attempt NewUserAttempt) (string, error) {
	_, err := mail.ParseAddress(attempt.Email)
	if err != nil {
		return "", errors.New(swizzle.EmailInvalid)
	}
	if len(attempt.Password) < 8 {
		return "", errors.New(swizzle.PasswordTooShort)
	}
	if ac.IsEmailAlreadyInUse(util.Base64EncodeString(attempt.Email)) {
		return "", errors.New(swizzle.EmailExists)
	}
	var user User
	user.UUID, _ = uuid.New()
	base64EncodedName := util.Base64EncodeString(attempt.Name)
	base64EncodedEmail := util.Base64EncodeString(attempt.Email)
	base64EncodedPassword := util.Base64EncodeString(attempt.Password)
	user.Name = base64EncodedName
	user.Email = base64EncodedEmail
	user.PasswordHash, _ = hashPassword(base64EncodedPassword)
	user.EmailConfirmed = false
	user.SuperAdmin = false
	user.CreatedAt = time.Now().Format(time.RFC3339)
	user.UpdatedAt = time.Now().Format(time.RFC3339)
	err = ac.PutNewUserIntoDB(&user)
	if err != nil {
		return "", err
	}
	 TODO: Session Token
	return "", nil
}
func ( ac * AuthController ) RegisterUser ( attempt NewUserAttempt ) ( string , error ) { _ , err := mail . ParseAddress ( attempt . Email ) if err != nil { return " " , errors . New ( swizzle . EmailInvalid ) } if len ( attempt . Password ) < 8 { return " " , errors . New ( swizzle . PasswordTooShort ) } if ac . IsEmailAlreadyInUse ( util . Base64EncodeString ( attempt . Email ) ) { return " " , errors . New ( swizzle . EmailExists ) } var user User user . UUID , _ = uuid . New ( ) base64EncodedName := util . Base64EncodeString ( attempt . Name ) base64EncodedEmail := util . Base64EncodeString ( attempt . Email ) base64EncodedPassword := util . Base64EncodeString ( attempt . Password ) user . Name = base64EncodedName user . Email = base64EncodedEmail user . PasswordHash , _ = hashPassword ( base64EncodedPassword ) user . EmailConfirmed = false user . SuperAdmin = false user . CreatedAt = time . Now ( ) . Format ( time . RFC3339 ) user . UpdatedAt = time . Now ( ) . Format ( time . RFC3339 ) err = ac . PutNewUserIntoDB ( & user ) if err != nil { return " " , err } return " " , nil }
RegisterUser registers a user and returns a SessionToken
RegisterUser registers a user and returns a SessionToken
// Check that email is an actual email // Check that password is at least 8 characters long // Check that the email is not already registered // Create the User // Send Confirmation email? // // TODO: Session Token