~~~
l.Redirect(beego.URLFor("MainsController.Get"), 302)
~~~
实例:
~~~
func (l *LoginController) Post() {
name := l.GetString("username")
pwd := l.GetString("password")
w := md5.New()
io.WriteString(w, pwd) //将str写入到w中
bw := w.Sum(nil) //w.Sum(nil)将w的hash转成[]byte格式
// md5str2 := fmt.Sprintf("%x", bw) //将 bw 转成字符串
md5str := hex.EncodeToString(bw) //将 bw 转成字符串
o := orm.NewOrm()
qs := o.QueryTable(new(models.Users))
res := qs.Filter("name", name).Filter("pwd", md5str).Exist()
if res {
l.SetSession("user_name", name)
l.Redirect(beego.URLFor("MainsController.Get"), 302)
} else {
l.Redirect(beego.URLFor("LoginController.Get"), 302)
}
}
~~~