Пример #1
0
func (c *RegisterController) Post() {

	var account models.Account
	err := parseAccount(&c.Controller, &account)
	if err != nil {
		//c.Ctx.ResponseWriter.WriteHeader(400)
		c.Data["Operation"] = "Register"
		c.Data["Reason"] = "Input Someting Invalid"
		c.TplNames = "common_failed.tpl"
		return
	}

	err = models.CreateNewAccount(&account)
	if err != nil {
		//c.Ctx.ResponseWriter.WriteHeader(400)
		c.Data["Operation"] = "Register"
		existAccount, _ := models.QueryAccountByEmail(account.EMail)
		if existAccount != nil {
			c.Data["Reason"] = "Your Email is Used by Others"
		} else {
			c.Data["Reason"] = "Something Error, Try Later"
		}
		c.TplNames = "common_failed.tpl"

		return
	}

	c.Ctx.ResponseWriter.Write([]byte("Success"))
}
Пример #2
0
func (c *LoginController) Post() {
	sess, _ := globalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
	defer sess.SessionRelease(c.Ctx.ResponseWriter)

	email := c.GetString("email")
	passwd := c.GetString("password")

	account, err := models.QueryAccountByEmail(email)
	if err != nil || account == nil || account.Password != passwd {
		c.Data["Timeout"] = "2"
		c.Data["URL"] = "/static/page/login_failed.html"
	} else {
		c.Data["Timeout"] = "2"
		c.Data["URL"] = "/login_success"
		sess.Set("user-id", account.Id)
		sess.Set("user-email", account.EMail)
		sess.Set("user-name", account.DisplayName)
	}
	c.TplNames = "login_redirect.tpl"
}