123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- package controllers
- import (
- "ColdVerify_server/conf"
- "ColdVerify_server/lib"
- "ColdVerify_server/models/Account"
- "ColdVerify_server/models/System"
- beego "github.com/beego/beego/v2/server/web"
- "math"
- )
- type UserController struct {
- beego.Controller
- }
- // 获取-
- func (c *UserController) Get() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- Id, err := c.GetInt("Id")
- if err != nil {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- r, is := Account.Read_User_ById(Id)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r}
- c.ServeJSON()
- return
- }
- // 列表 -
- func (c *UserController) List() {
- // 验证登录 User_is, User_r
- _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- var r_jsons lib.R_JSONS
- page, _ := c.GetInt("page")
- if page < 1 {
- page = 1
- }
- page_z, _ := c.GetInt("page_z")
- if page_z < 1 {
- page_z = conf.Page_size
- }
- T_name := c.GetString("T_name")
- var cnt int64
- List, cnt := Account.Read_User_List(T_name, page, page_z)
- page_size := math.Ceil(float64(cnt) / float64(page_z))
- r_jsons.List = List
- r_jsons.Page = page
- r_jsons.Page_size = int(page_size)
- r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
- r_jsons.Num = int(cnt)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
- c.ServeJSON()
- return
- }
- // 添加-
- func (c *UserController) Add() {
- // 验证登录 User_is, User_r
- user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- //T_power, _ := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_passstr := c.GetString("T_passstr")
- var_ := Account.User{
- //T_power: T_power,
- T_name: T_name,
- T_pass: T_pass,
- T_passstr: T_passstr,
- T_Show: 1,
- T_State: 1,
- }
- if _, is := Account.Read_UserByT_name(T_name); is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称重复!"}
- c.ServeJSON()
- return
- }
- Id, is := Account.Add_User(var_)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid, "用户管理", "添加", var_)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *UserController) Up() {
- // 验证登录 User_is, User_r
- user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- //T_power, T_power_err := c.GetInt("T_power")
- T_name := c.GetString("T_name")
- T_pass := c.GetString("T_pass")
- T_passstr := c.GetString("T_passstr")
- T_Show, T_Show_err := c.GetInt("T_Show")
- T_uuid := c.GetString("T_uuid")
- r, is := Account.Read_User(T_uuid)
- if !is {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- if _, is := Account.Read_UserByT_name(T_name); is && r.T_name != T_name {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称重复!"}
- c.ServeJSON()
- return
- }
- // .......
- //if T_power_err == nil {
- // r.T_power = T_power
- //}
- if len(T_name) > 0 {
- r.T_name = T_name
- }
- if len(T_pass) > 0 {
- r.T_pass = T_pass
- }
- if len(T_passstr) > 0 {
- r.T_passstr = T_passstr
- }
- if T_Show_err == nil {
- r.T_Show = T_Show
- }
- // .......
- if !Account.Update_User(r, "T_name", "T_pass", "T_passstr", "T_Show") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid, "用户管理", "修改", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- // 删除-
- func (c *UserController) Del() {
- // 验证登录 User_is, User_r
- user_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_uuid := c.GetString("T_uuid")
- if r, is := Account.Read_User(T_uuid); is {
- if !Account.Delete_User_(r) {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid, "用户管理", "删除", r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
- c.ServeJSON()
- return
- }
- // 修改-
- func (c *UserController) UpPassword() {
- // 验证登录 User_is, User_r
- user_r, User_is := Account.Verification(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
- if !User_is {
- c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
- c.ServeJSON()
- return
- }
- T_oldpass := c.GetString("T_oldpass")
- T_pass := c.GetString("T_pass")
- T_passstr := c.GetString("T_passstr")
- if T_oldpass != user_r.T_pass {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "旧密码错误!"}
- c.ServeJSON()
- return
- }
- if len(T_pass) > 0 {
- user_r.T_pass = T_pass
- }
- if len(T_passstr) > 0 {
- user_r.T_passstr = T_passstr
- }
- // .......
- if !Account.Update_User(user_r, "T_pass", "T_passstr") {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
- c.ServeJSON()
- return
- }
- System.Add_UserLogs_T(user_r.T_uuid, "用户管理", "修改密码", user_r)
- c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
- c.ServeJSON()
- return
- }
|