Exemple #1
0
func (s *UserService) CreateUser(user *model.User) (*model.User, error) {
	dbuser, err := userdao.GetUser("username", user.Username)
	if err != nil {
		// DONE: 如何使用error才不会导致调用栈的丢失?
		panic(exception.NewCoreError(err, ""))
	}
	if dbuser != nil {
		return nil, exception.NewCoreError(nil, "User already exists for name: %s", user.Username)
	}
	return userdao.CreateUser(user)
}
Exemple #2
0
func (p *AccountRegister) OnSuccessFromRegisterForm() *exit.Exit {
	fmt.Printf("-------------- register form success -----------------\n")
	fmt.Println("Username ", p.User)

	// TODO: validate user.

	if user, err := userdao.CreateUser(p.User); err != nil {
		panic(err)
	} else {
		p.User = user
	}

	// TODO: log create action.

	return exit.Redirect("/")
}