func (c *LoginController) Post() { account := c.Input().Get("account") password := c.Input().Get("password") autologin := c.Input().Get("autologin") == "on" //数据库比较 pass, err := models.VerifyUser(common.MakeMD5(account), common.MakeMD5(password)) if err != nil { c.Redirect("/login", 301) beego.Error(err) return } if pass { beego.Error("login successful!") maxage := 0 if autologin { maxage = 1<<31 - 1 } c.Ctx.SetCookie("account", common.MakeMD5(account), maxage, "/") c.Ctx.SetCookie("password", common.MakeMD5(password), maxage, "/") c.SetSession("account", common.MakeMD5(account)) // c.SetSession("password", password) } else { c.Redirect("/login", 301) beego.Error("login failed!") return } c.Redirect("/", 301) return }
func AddUser(user StoneUser) error { ORM := orm.NewOrm() user.Account = common.MakeMD5(user.Telphone) user.Password = common.MakeMD5(user.Password) _, err := ORM.Insert(&user) if err != nil { return err } return nil }
func UpdateUserPassword(telphone, email, new_password string) (bool, error) { ORM := orm.NewOrm() user := new(StoneUser) err := ORM.Raw("SELECT * from stone_user where telphone=? and email=?", telphone, email).QueryRow(user) if err != nil { return false, err } user.Password = common.MakeMD5(new_password) _, err = ORM.Update(user) if err != nil { return false, err } return true, err }