Esempio n. 1
0
func registerUser(ctx *app.Context) {
	username := ctx.RequireIndexValue(0)
	userVal, _ := newEmptyUser(ctx)
	updating := false
	if ctx.Orm().MustOne(ByUsername(username), userVal.Interface()) {
		// Updating existing user
		updating = true
	} else {
		// Creating a new one
		userVal = newUser(ctx, username)
	}
	var askPassword bool
	ctx.ParseParamValue("p", &askPassword)
	if !updating || askPassword {
		password1, err := speakeasy.Ask("Password:"******"Confirm Password:"******"passwords don't match"))
		}
		setUserValue(userVal, "Password", password.New(password1))
	}
	var admin bool
	ctx.ParseParamValue("s", &admin)
	setUserValue(userVal, "Admin", admin)

	var email string
	ctx.ParseParamValue("e", &email)
	if email != "" {
		setUserValue(userVal, "Email", email)
	}

	ctx.Orm().MustSave(userVal.Interface())
	ctx.Logger().Infof("saved user as %+v", userVal.Interface())
}