예제 #1
0
파일: user.go 프로젝트: RoyDong/notes
func (c *User) Signup() {
	form := new(model.UserForm)
	if c.Request.Method == "POST" {
		form.LoadData(c.Request)
		if form.Valid() {
			m := model.UserModel
			if m.Exists(form.Email) {
				form.Message = "Email exists"
				goto RENDER
			}

			user := new(model.User)
			user.Name = form.Name
			user.Email = form.Email
			user.SetPasswd(form.Passwd)
			if m.Save(user) {
				c.Request.Session.Set("user", user, true)
				c.Redirect("/admin/setting", 302)
			}

			form.Message = "server error, could not save data"
		}
	}

RENDER:
	c.Render("admin/user/signup", form)
}
예제 #2
0
파일: user.go 프로젝트: RoyDong/notes
func (c *User) Signin() {
	form := new(model.UserForm)
	if c.Request.Method == "POST" {
		form.LoadData(c.Request)
		if form.Valid() {
			m := model.UserModel
			if user := m.FindByEmail(form.Email); user != nil &&
				user.CheckPasswd(form.Passwd) {
				c.Request.Session.Set("user", user, true)
				c.Redirect("/admin/setting", 302)
			}

			form.Message = "email or password error"
		}
	}

	c.Render("admin/user/signin", form)
}