Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议增加管理员新增用户的功能,谢谢 #409

Closed
ghost opened this issue Jun 26, 2018 · 38 comments
Closed

建议增加管理员新增用户的功能,谢谢 #409

ghost opened this issue Jun 26, 2018 · 38 comments

Comments

@ghost
Copy link

ghost commented Jun 26, 2018

目前的系统是缺少增加管理员新增用户的功能的,这块还是有比较多需求的。

@gaoxiaomumu
Copy link
Member

你的意思是说增加多个管理员的功能吗?

@git510961914
Copy link

他的意思是,登录管理员账号来添加新的用户

@gaoxiaomumu
Copy link
Member

这个不是有吗?成员管理那边可以添加用户的

@git510961914
Copy link

没有啊,用户管理下面只有一个删除操作

@gaoxiaomumu
Copy link
Member

只要用户注册过都会出现在用户管理中,其实主要的用户添加操作是在分组管理和项目管理中。用户管理这里没有必要有添加操作的

@ghost
Copy link
Author

ghost commented Jul 5, 2018

我的意思是关闭对外注册,由管理员自行添加用户。

@LichFaker
Copy link

关闭注册的情况下, 现在有可以通过管理员添加用户的功能了?

@jasonjoo2010
Copy link

这个我觉得得分开说,关闭注册,且没有其它登录方式(如ldap)的情况下,后台可以考虑提供创建用户这个功能,否则用户管理会乱,大家觉得呢

当然也可提供一个独立开关,但配置越多学习成本越高

@WangShuXian6
Copy link

像gitlab那样,可以在系统管理员的控制面板中关闭注册功能,同时可以在系统管理员控制面板中添加用户代替注册功能。

@yangbajing
Copy link

?这个功能为啥不提供了?不是每个公司都会有LDAP服务的。

@woodytang
Copy link

有些 组内成员很懒的,,最好让管理员统一建立账号,发放

@reducm
Copy link

reducm commented Aug 15, 2019

+1 一进来吃一惊,不知道怎么增加用户

@zhanghw0917
Copy link

臣附议

@wilderchen
Copy link

+1

@blackkeai
Copy link

还没找到新增用户的地方,docker 启动起来注册功能是关的。

@lifw555
Copy link

lifw555 commented Jun 4, 2020

+1

2 similar comments
@BlackCodes
Copy link

+1

@LucaLq
Copy link

LucaLq commented Nov 11, 2020

+1

@cambridgejames
Copy link

臣附议

@JaneYork
Copy link

JaneYork commented Feb 6, 2021

2021年了,臣附议,力求加一个管理员新增用户功能。
很奇怪,这个功能为什么迟迟没有?是什么样的业务场景导致这个非必须呢?
我怎么感觉这个必须呢?

  • 内网管理,方便管理员管理用户,包括人员职位等
  • 外网,可以防止无关人员恶意注册
  • 针对小企业、个人,一般没有LDAP,而管理权限这块非常必要

@xwh1108
Copy link

xwh1108 commented Feb 23, 2021

2021年了,臣附议,力求加一个管理员新增用户功能。

@yxAnswer
Copy link

上面这个添加用户是从哪里打开的呢? 需要升版本还是需要配置

@NICK-DUAN
Copy link

+1

@LayHuts
Copy link

LayHuts commented May 19, 2021

为什么我1.9.2米有添加用户的权限

@yxAnswer
Copy link

请问哪个版本有您说的这个添加用户入口?@#409 (comment)

@siwuai
Copy link

siwuai commented Jul 19, 2021

可以修改下源码,新增个添加用户的接口
server/controllers/user.js

  /**
   * 新增用户
   * @interface /user/add
   * @method POST
   * @category user
   * @foldnumber 10
   * @param {String} email email名称,不能为空
   * @param  {String} password 密码,不能为空
   * @param {String} [username] 用户名
   * @returns {Object}
   * @example ./api/user/add.json
   */
   async add(ctx) {
    if (this.getRole() !== 'admin') {
      return (ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.'));
    }
    let userInst = yapi.getInst(userModel);
    let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码

    params = yapi.commons.handleParams(params, {
      username: 'string',
      password: 'string',
      email: 'string'
    });

    if (!params.email) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'));
    }

    if (!params.password) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
    }

    let checkRepeat = await userInst.checkRepeat(params.email); //然后检查是否已经存在该用户

    if (checkRepeat > 0) {
      return (ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'));
    }

    let passsalt = yapi.commons.randStr();
    let data = {
      username: params.username,
      password: yapi.commons.generatePassword(params.password, passsalt), //加密
      email: params.email,
      passsalt: passsalt,
      role: 'member',
      add_time: yapi.commons.time(),
      up_time: yapi.commons.time(),
      type: 'site'
    };

    if (!data.username) {
      data.username = data.email.substr(0, data.email.indexOf('@'));
    }

    try {
      let user = await userInst.save(data);
      // this.setLoginCookie(user._id, user.passsalt);
      await this.handlePrivateGroup(user._id, user.username, user.email);
      ctx.body = yapi.commons.resReturn({
        uid: user._id,
        email: user.email,
        username: user.username,
        add_time: user.add_time,
        up_time: user.up_time,
        role: 'member',
        type: user.type,
        study: false
      });
      yapi.commons.sendMail({
        to: user.email,
        contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi可视化接口平台,您的账号 ${
          params.email
        } 已经注册成功</p>`
      });
    } catch (e) {
      ctx.body = yapi.commons.resReturn(null, 401, e.message);
    }
  }

server/router.js 新增个路由

    {
      action: 'add',
      path: 'add',
      method: 'post'
    },

然后就可以通过接口调用来新增用户了,注意添加下登录cookie就行
POST http://localhost:3000/api/user/add
{
"email":"zhangsan@github.com",
"password":"123456"
}

@ivancxj
Copy link

ivancxj commented Jul 27, 2021

求加一个管理员新增用户功能

@ivancxj
Copy link

ivancxj commented Jul 27, 2021

能说明下 不支持管理员新增用户功能的原因是啥

@gozeon
Copy link

gozeon commented Oct 25, 2021

可以修改下源码,新增个添加用户的接口 server/controllers/user.js

  /**
   * 新增用户
   * @interface /user/add
   * @method POST
   * @category user
   * @foldnumber 10
   * @param {String} email email名称,不能为空
   * @param  {String} password 密码,不能为空
   * @param {String} [username] 用户名
   * @returns {Object}
   * @example ./api/user/add.json
   */
   async add(ctx) {
    if (this.getRole() !== 'admin') {
      return (ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.'));
    }
    let userInst = yapi.getInst(userModel);
    let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码

    params = yapi.commons.handleParams(params, {
      username: 'string',
      password: 'string',
      email: 'string'
    });

    if (!params.email) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'));
    }

    if (!params.password) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
    }

    let checkRepeat = await userInst.checkRepeat(params.email); //然后检查是否已经存在该用户

    if (checkRepeat > 0) {
      return (ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'));
    }

    let passsalt = yapi.commons.randStr();
    let data = {
      username: params.username,
      password: yapi.commons.generatePassword(params.password, passsalt), //加密
      email: params.email,
      passsalt: passsalt,
      role: 'member',
      add_time: yapi.commons.time(),
      up_time: yapi.commons.time(),
      type: 'site'
    };

    if (!data.username) {
      data.username = data.email.substr(0, data.email.indexOf('@'));
    }

    try {
      let user = await userInst.save(data);
      // this.setLoginCookie(user._id, user.passsalt);
      await this.handlePrivateGroup(user._id, user.username, user.email);
      ctx.body = yapi.commons.resReturn({
        uid: user._id,
        email: user.email,
        username: user.username,
        add_time: user.add_time,
        up_time: user.up_time,
        role: 'member',
        type: user.type,
        study: false
      });
      yapi.commons.sendMail({
        to: user.email,
        contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi可视化接口平台,您的账号 ${
          params.email
        } 已经注册成功</p>`
      });
    } catch (e) {
      ctx.body = yapi.commons.resReturn(null, 401, e.message);
    }
  }

server/router.js 新增个路由

    {
      action: 'add',
      path: 'add',
      method: 'post'
    },

然后就可以通过接口调用来新增用户了,注意添加下登录cookie就行 POST http://localhost:3000/api/user/add { "email":"zhangsan@github.com", "password":"123456" }

浏览器控制台脚本

fetch("/api/user/add", {
  "headers": {
    "accept": "application/json, text/plain, */*",
    "content-type": "application/json;charset=UTF-8"
  },
  "referrerPolicy": "strict-origin-when-cross-origin",
  "body": "{"email":"xxx@xx.com.cn","password":"ymfe.org"}",
  "method": "POST",
  "mode": "cors",
  "credentials": "include"
}).then(res => res.json())
.then( res=> console.log(res));

@binwan-dev
Copy link

作者难道还停留再90年代?用户管理居然没有用户添加,反人类的设计啊

@zcjwsrf
Copy link

zcjwsrf commented Apr 27, 2022

附议+1

@ikeloo
Copy link

ikeloo commented Mar 19, 2023

可能我暴力了一点,直接钻到数据库里面找的user的那个collection,添加了几条数据,好像也可以用。

比如这样:db.getCollection("user").insert({"_id": 12,"study": true,"type": "site","username": "zhangsan","email": "zhangsan@xxxx.com","password": "060404e0e00795f3069d1fb97bd0b5125fd4005f","passsalt": "2yf3b0622uv","role": "member","add_time": 1679204824,"up_time": 1679205377,"__v": 0});

密码和密码盐可以先找自己的管理员的复制过来用一下,进去再改改。

@eaglepie
Copy link

可以修改下源码,新增个添加用户的接口 server/controllers/user.js

  /**
   * 新增用户
   * @interface /user/add
   * @method POST
   * @category user
   * @foldnumber 10
   * @param {String} email email名称,不能为空
   * @param  {String} password 密码,不能为空
   * @param {String} [username] 用户名
   * @returns {Object}
   * @example ./api/user/add.json
   */
   async add(ctx) {
    if (this.getRole() !== 'admin') {
      return (ctx.body = yapi.commons.resReturn(null, 402, 'Without permission.'));
    }
    let userInst = yapi.getInst(userModel);
    let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码

    params = yapi.commons.handleParams(params, {
      username: 'string',
      password: 'string',
      email: 'string'
    });

    if (!params.email) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'));
    }

    if (!params.password) {
      return (ctx.body = yapi.commons.resReturn(null, 400, '密码不能为空'));
    }

    let checkRepeat = await userInst.checkRepeat(params.email); //然后检查是否已经存在该用户

    if (checkRepeat > 0) {
      return (ctx.body = yapi.commons.resReturn(null, 401, '该email已经注册'));
    }

    let passsalt = yapi.commons.randStr();
    let data = {
      username: params.username,
      password: yapi.commons.generatePassword(params.password, passsalt), //加密
      email: params.email,
      passsalt: passsalt,
      role: 'member',
      add_time: yapi.commons.time(),
      up_time: yapi.commons.time(),
      type: 'site'
    };

    if (!data.username) {
      data.username = data.email.substr(0, data.email.indexOf('@'));
    }

    try {
      let user = await userInst.save(data);
      // this.setLoginCookie(user._id, user.passsalt);
      await this.handlePrivateGroup(user._id, user.username, user.email);
      ctx.body = yapi.commons.resReturn({
        uid: user._id,
        email: user.email,
        username: user.username,
        add_time: user.add_time,
        up_time: user.up_time,
        role: 'member',
        type: user.type,
        study: false
      });
      yapi.commons.sendMail({
        to: user.email,
        contents: `<h3>亲爱的用户:</h3><p>您好,感谢使用YApi可视化接口平台,您的账号 ${
          params.email
        } 已经注册成功</p>`
      });
    } catch (e) {
      ctx.body = yapi.commons.resReturn(null, 401, e.message);
    }
  }

server/router.js 新增个路由

    {
      action: 'add',
      path: 'add',
      method: 'post'
    },

然后就可以通过接口调用来新增用户了,注意添加下登录cookie就行 POST http://localhost:3000/api/user/add { "email":"zhangsan@github.com", "password":"123456" }

添加了后,返回的结果是这样的:
{
"errcode": 40011,
"errmsg": "服务器出错...",
"data": null
}

@eaglepie
Copy link

可能我暴力了一点,直接钻到数据库里面找的user的那个collection,添加了几条数据,好像也可以用。

比如这样:db.getCollection("user").insert({"_id": 12,"study": true,"type": "site","username": "zhangsan","email": "zhangsan@xxxx.com","password": "060404e0e00795f3069d1fb97bd0b5125fd4005f","passsalt": "2yf3b0622uv","role": "member","add_time": 1679204824,"up_time": 1679205377,"__v": 0});

密码和密码盐可以先找自己的管理员的复制过来用一下,进去再改改。

还可以更暴力的,直接用Navicat Premium连接yapi数据库,直接打开user表复制一条记录修改就是了。

@MrYu1019
Copy link

真的很不懂作者,这2023年了,用户管理创建用户这个功能还没有实现?太反人类了

@admins-system
Copy link

真的很不懂作者,这2023年了,用户管理创建用户这个功能还没有实现?太反人类了

如果我没看错的话这是一个开源项目

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests