package controllers import ( "github.com/astaxie/beego" "git.kingpenguin.tk/chteufleur/datahouse.git/models/user" "git.kingpenguin.tk/chteufleur/datahouse.git/models/variables" ) type UserController struct { beego.Controller } func (c *UserController) Prepare() { sess := c.GetSession(variables.SessionName) if sess == nil { c.Redirect(variables.LoginRouteNoRegex+variables.UserRoute, 302) } else { c.Data["IsAuthentificated"] = true } c.Data["IsUser"] = true c.Data["version"] = variables.Version } func (c *UserController) Get() { loginStr := c.getUserLogin() u := user.GetUserByLogin(loginStr) c.Data["user"] = u c.TplName = "user.tpl" } func (c *UserController) Post() { pwd1 := c.Input().Get("password1") pwd2 := c.Input().Get("password2") jid := c.Input().Get("jid") loginStr := c.getUserLogin() user.ChangeJID(loginStr, jid) if pwd1 == pwd2 && pwd1 != "" { user.ChangePassword(loginStr, pwd1) } c.Redirect(variables.UserRoute, 302) } func (c *UserController) getUserLogin() string { ret := "" login := c.GetSession(variables.SessionName) switch lo := login.(type) { case string: ret = lo } return ret }