package ldap import ( "errors" "nginx-ui/server/base" "nginx-ui/server/models" ) type UserController struct { base.Controller } func (c *UserController) Login() { req := LDAPLoginReq{} if c.ReadBody(&req) == false { return } user, err := ServerIns.Login(&req) if err != nil { c.ErrorJson(err) return } user.Password = "" c.SetSession("user", *user) c.PostJson(models.SuccessResp(user)) } // SyncUsers 同步用户信息 // post /ldap/user/sync func (c *UserController) SyncUsers() { current := c.RequiredUser() if current == nil { return } req := LDAPUserSyncReq{} if !c.ReadBody(&req) { return } count, err := UserIns.SyncUsers(current, &req) if err != nil { c.ErrorJson(err) return } resp := make(map[string]interface{}) resp["count"] = count c.SetData(resp).Json() } // UpdateUserPassword 更新用户密码 // post /ldap/user/modifyPassword func (c *UserController) UpdateUserPassword() { } // SaveUser 新增或者修改用户 func (c *UserController) SaveUser() { current := c.RequiredUser() if current == nil { return } user := models.LdapUser{} if !c.ReadBody(&user) { return } if user.ServerKey == "" { server, err := ServerIns.GetServer() if err != nil { c.ErrorJson(errors.New("请先激活LDAP服务")) return } user.ServerKey = server.Key } resp, err := UserIns.Add(&user) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() } // GetUsers 获取全部用户 // get /ldap/users func (c *UserController) GetUsers() { current := c.RequiredUser() if current == nil { return } req := UserListReq{} if !c.ReadBody(&req) { return } resp, err := ServerIns.GetUsers(current, &req) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() } func (c *UserController) GetDetail() { current := c.RequiredUser() if current == nil { return } id, err := c.GetIntQuery("id") if err != nil { c.ErrorJson(err) return } resp, err := UserIns.GetDetail(id) if err != nil { c.ErrorJson(err) return } c.SetData(resp).Json() }