Ejemplo n.º 1
0
func InsertUser() {
	admin := User{
		Name:     "admin",
		Email:    "*****@*****.**",
		Password: helpers.EncryptPassword("admin", nil),
		IRole:    Role{Id: ROLE_ADMIN},
		Status:   ACTIVE,
	}

	Engine.Insert(&admin)

	user := User{
		Name:     "hello",
		Email:    "*****@*****.**",
		Password: helpers.EncryptPassword("111111", nil),
		IRole:    Role{Id: ROLE_AUTHENTICATED},
		Status:   ACTIVE,
	}

	Engine.Insert(&user)
}
Ejemplo n.º 2
0
// Post
func (this *RegisterController) Register() {
	var (
		user  models.User
		form  models.RegisterForm
		valid validation.Validation
		err   error
	)

	if err = this.ParseForm(&form); err != nil {
		fmt.Println(err)
	} else {
		if ok, e := valid.Valid(form); ok && e == nil {
			user.Name = form.UserName
			user.Email = form.Email
			user.Password = helpers.EncryptPassword(form.Password, nil)
			user.Status = models.ACTIVE
			user.IRole = models.Role{Id: models.ROLE_AUTHENTICATED}
			user.CreateTime = time.Now()

			if _, err = models.Engine.Insert(&user); err == nil {
				this.FlashNotice(user.Name + " registered successfully. Please login now!")
				this.SaveFlash()
				this.Redirect("/login", 302)
				return
			}
		} else {
			for _, e := range valid.Errors {
				this.FlashError(e.Key + " : " + e.Message)
			}
		}
	}

	this.SaveFlash()
	this.Data["Form"] = form
	this.Data["Title"] = "Register"
	this.TplNames = "auth/register.html"
}