| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | 
							- package controllers
 
- import (
 
-     "wb/ctrl"
 
-     "github.com/astaxie/beego"
 
-     "wb/cs"
 
-     "encoding/base64"
 
-     "wb/usr"
 
-     "eps/models/userMgr"
 
-     "wb/om"
 
-     "fmt"
 
-     "wb/lg"
 
-     "wb/cc"
 
-     "wb/st"
 
-     "strings"
 
- )
 
- type MainController struct {
 
-     ctrl.BaseController
 
- }
 
- func (this *MainController) Get() {
 
-     url := "/sui/gis/main"
 
-     url64 := this.GetString("url")
 
-     url64 = strings.TrimSpace(url64)
 
-     if url64 != ""{
 
-         if bUrl, err := base64.URLEncoding.DecodeString(url64);err== nil{
 
-             newUrl := string(bUrl)
 
-             newUrl = strings.TrimSpace(newUrl)
 
-             if newUrl != ""{
 
-                 url = newUrl
 
-             }
 
-         }
 
-     }
 
-     user := this.GetSessionUser()
 
-     //fmt.Println("url:", url)
 
-     this.Data["MainUrl"] = url
 
-     this.Data["UserName"] = user.GetName()
 
-     this.TplName = "main.tpl"
 
- }
 
- type LoginController struct {
 
-     ctrl.LoginController
 
- }
 
- func (this *LoginController) Get() {
 
-     _, ok := this.GetSession(cc.SessionUser).(usr.Usr)
 
-     if this.Ctx.Input.URL() == "/" && ok {
 
-         this.Redirect("/main", 302)
 
-         return
 
-     }
 
-     lg.Info("LoginController:", this.Ctx.Input.URL())
 
-     redirectUrl := "/main"
 
-     redirectUrlB64 := this.GetString("redirect")
 
-     if redirectUrlB64 != "" {
 
-         redirectUrlDec, err := base64.URLEncoding.DecodeString(redirectUrlB64)
 
-         if err == nil {
 
-             redirectUrl = string(redirectUrlDec)
 
-         }
 
-     }
 
-     this.Data["redirectUrl"] = redirectUrl
 
-     switch this.Ctx.Input.URL() {
 
-     case "/public":
 
-         this.TplName = "login/public.html"
 
-         this.Data["username"] = "guest"
 
-     case "/demo":
 
-         this.TplName = "login/public.html"
 
-         demoUrl := beego.AppConfig.DefaultString("demoUrl", "/genset/status?sn=012345678910")
 
-         //this.Data["redirectUrl"] ="/genset/status?sn=012345678910"
 
-         this.Data["redirectUrl"] = demoUrl
 
-         this.Data["username"] = "demo"
 
-     default:
 
-         if beego.AppConfig.String("publicEnable") == "true"{
 
-             this.Data["HasPublicLogin"] = true
 
-         }
 
-         this.TplName = "login/login.html"
 
-     }
 
- }
 
- func (this *LoginController) Post(){
 
-     lg.Info("LoginController.Post")
 
-     uonename := strings.TrimSpace(this.GetString("login_username"))
 
-     uonepasd := strings.TrimSpace(this.GetString("login_password"))
 
-     if beego.AppConfig.String("demoEnable") == "true"{
 
-         if uonename == "demo"{
 
-             u := userMgr.User{"demo", "demo", "demo", "role_admin", "demo", "", "", "flag_available",""}
 
-             this.LoginAs(u)
 
-             return
 
-         }
 
-     }
 
-     if beego.AppConfig.String("publicEnable") == "true"{
 
-         if uonename == "guest"{
 
-             u := userMgr.User{"guest", "guest", "guest", "role_guest", "guest", "", "", "flag_available",""}
 
-             this.LoginAs(u)
 
-             return
 
-         }
 
-     }
 
-     loginRet := cs.JsonResult{}
 
-     if uonename == "" || uonepasd == "" {
 
-         loginRet.Result = "请输入用户名和密码!"
 
-     }
 
-     params := om.Params{
 
-         "uonename": uonename,
 
-         "uonepasd": uonepasd,
 
-     }
 
-     if c, u := userMgr.GetValidUser(params); c == st.Success {
 
-         this.LoginAs(u)
 
-     } else {
 
-         lg.SError(fmt.Sprintf("[S]User:%s login error code: %s", uonename, c))
 
-         loginRet.Result = "用户名或密码错误!"
 
-         this.Data["json"] = &loginRet
 
-         this.ServeJSON()
 
-     }
 
- }
 
 
  |