func (this *SsoController) User() { sig := this.Ctx.Input.Param(":sig") if sig == "" { this.NotFound("sig is blank") return } sessionObj := uic.ReadSessionBySig(sig) if sessionObj == nil { this.NotFound("no such sig") return } if int64(sessionObj.Expired) < time.Now().Unix() { uic.RemoveSessionByUid(sessionObj.Uid) this.SessionExpired() return } u := uic.ReadUserById(sessionObj.Uid) if u == nil { this.NotFound("no such user") return } this.Data["json"] = map[string]interface{}{ "user": u, } this.ServeJson() }
func (this *SsoController) Logout() { sig := this.Ctx.Input.Param(":sig") if sig == "" { this.ServeErrJson("sig is blank") return } sessionObj := uic.ReadSessionBySig(sig) if sessionObj != nil { uic.RemoveSessionByUid(sessionObj.Uid) } this.ServeOKJson() }
func (this *BaseController) SessionCheck() (session *uic.Session, err error) { name := this.GetString("cName", this.Ctx.GetCookie("name")) sig := this.GetString("cSig", this.Ctx.GetCookie("sig")) if sig == "" || name == "" { err = errors.New("name or sig is empty, please check again") return } session = uic.ReadSessionBySig(sig) if session.Uid != uic.SelectUserIdByName(name) { err = errors.New("can not find this kind of session") return } return }
func (this *DashBoardController) EndpRegxquryForOps() { this.Data["Shortcut"] = g.Config().Shortcut sig := this.Ctx.GetCookie("sig") session := uic.ReadSessionBySig(sig) var username *uic.User if sig == "" || session.Uid <= 0 { this.Data["SessionFlag"] = true this.Data["ErrorMsg"] = "Session is not vaild" } else { this.Data["SessionFlag"] = false username = uic.SelectUserById(session.Uid) if username.Name != "root" { this.Data["SessionFlag"] = true this.Data["ErrorMsg"] = "You don't have permission to access this page" } } queryStr := this.GetString("queryStr", "") this.Data["QueryCondstion"] = queryStr if queryStr == "" || this.Data["SessionFlag"] == true { this.Data["Init"] = true } else { enp, _ := dashboard.QueryEndpintByNameRegxForOps(queryStr) if len(enp) > 0 { var ips []string this.Data["Endopints"] = enp this.Data["Len"] = len(enp) for _, en := range enp { if en.Ip != "" { ips = append(ips, en.Ip) } } this.Data["IP"] = strings.Join(ips, ",") } else { this.Data["Endopints"] = []string{} this.Data["Len"] = 0 this.Data["IP"] = "" } } this.TplName = "dashboard/endpoints.html" }
import ( "github.com/Cepave/fe/model/uic" "github.com/astaxie/beego/context" "strconv" "time" ) var FilterLoginUser = func(ctx *context.Context) { cookieSig := ctx.GetCookie("sig") if cookieSig == "" { ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String()) return } sessionObj := uic.ReadSessionBySig(cookieSig) if sessionObj == nil || int64(sessionObj.Expired) < time.Now().Unix() { ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String()) return } u := uic.ReadUserById(sessionObj.Uid) if u == nil { ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String()) return } ctx.Input.SetData("CurrentUser", u) } var FilterTargetUser = func(ctx *context.Context) {