package controllers import ( "ColdP_server/controllers/lib" "ColdP_server/models/Account" "fmt" beego "github.com/beego/beego/v2/server/web" "net/http" "strings" "time" ) type AdminController struct { beego.Controller } func (c *AdminController) Login() { c.TplName = "login.html" } func (c *AdminController) Login_verification() { Admin_user := c.GetString("bzd_username") Admin_pass := c.GetString("bzd_password") companyId := c.GetString("company_id") println("Login_verification", Admin_user, Admin_pass) err, admin_r := Account.Read_AdminLogin_verification(Admin_user, Admin_pass) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "账号密码错误!"} c.ServeJSON() return } if admin_r.T_pids == "*" { User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId) c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60) c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey} c.ServeJSON() return } //如果自定义了公司ID,则标识是管理员,判断是否pids是否存在要操作的pid,并且要求登录用户的PID一定为0 if companyId != "" && admin_r.T_pid == 0 { pids := strings.Split(admin_r.T_pids, "|") for _, v := range pids { newV := strings.Replace(v, "P", "", -1) if newV == companyId { User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, companyId) c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60) c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey} c.ServeJSON() return } } //不存在该公司的Pid c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有操作该公司的权限!"} c.ServeJSON() return } else { User_tokey := Account.Add_Tokey_Set(admin_r.T_uuid, fmt.Sprintf("%d", admin_r.T_pid)) c.Ctx.SetCookie("User_tokey", User_tokey, time.Second*60*60) c.Data["json"] = lib.JSONS{Code: 200, Msg: "OK!", Data: User_tokey} c.ServeJSON() return } } func (c *AdminController) Info() { // 验证登录 b_, user_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !b_ { c.Data["json"] = lib.JSONS{Code: 202, Msg: "no"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok", Data: Account.AdminToAdmin_R(user_r)} c.ServeJSON() return } func (c *AdminController) Index() { // 验证登录 b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !b_ { c.Ctx.Redirect(302, "Login") return } // 基本信息 c.Data["Admin_name"] = admin_r.T_name c.Data["Admin_root"] = admin_r.Id c.TplName = "index.html" } func (c *AdminController) Home() { b_, admin_r := lib.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !b_ { fmt.Println("当前未登录,请先登录!") c.Ctx.Redirect(http.StatusFound, "Login") } c.Data["T_name"] = admin_r.T_name c.TplName = "home.html" }