123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- 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 := ServiceInstance.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 := ServiceInstance.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 := ServiceInstance.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()
- }
|