func (c *MainController) Post() { // Check validation of user/pass //c.Ctx.WriteString("Your user name is: xxx") c.TplName = "login.tpl" uname := c.GetString("email") password := c.GetString("password") unameKey := models.FormatUserLoginKey(uname) storedPwd, err := models.DB.Get(unameKey) if err != nil { log.Println("user:"******" does not exist.") return // user does not exist, just return password and username don't match } if models.Hash(password) != storedPwd { log.Println("password is wrong") return // password is wrong, just return password and username don't match } c.Redirect("/dashboard?uname="+uname, 302) }
func (c *UserController) Post() { c.TplName = "register.tpl" uname := c.GetString("email") password := c.GetString("password") rePassword := c.GetString("re-password") if password != rePassword { return } unameKey := models.FormatUserLoginKey(uname) _, err := models.DB.Get(unameKey) if err == nil { log.Println("user: "******" exists.") return // user exists } err = models.DB.Put(unameKey, models.Hash(password)) if err != nil { log.Println("failed to put into database") return // failure } c.Redirect("/login?user_name="+uname, 302) }