Example #1
0
func (this *UserController) Signup() {
	uid := this.GetSession("Uid")
	if uid != nil {
		this.Redirect("/", 302)
	}

	if this.Ctx.Input.Param("0") != "submit" {
		this.Redirect("/user/login", 302)
	}

	user := models.User{
		Username: this.GetString("username"),
		Password: this.GetString("passkey"),
		Name:     this.GetString("name"),
		College:  this.GetString("college"),
		Email:    this.GetString("email"),
	}
	// All the fields verified, as well checked if username and email are unique
	err := user.SignupVerify()
	if err != nil {
		flash := beego.NewFlash()
		flash.Error(err.Error())
		flash.Store(&this.Controller)
	}
	uid, done := user.Create()

	if done {
		this.SetSession("Uid", this.GetString("username"))
		this.SetSession("id", uid)
		this.Redirect("/", 302)
	}
	this.Redirect("/user/login", 302)
}