|
@@ -453,11 +453,15 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async addUsers(pid, users) {
|
|
|
+ const projectData = await this.ctx.service.project.getDataById(pid);
|
|
|
+ const maxUser = projectData.max_user;
|
|
|
const paList = await this.getAllDataByCondition({ where: { project_id: pid } });
|
|
|
const insertData = [];
|
|
|
const create_time = Date.parse(new Date()) / 1000;
|
|
|
// 判断新密码的强度
|
|
|
const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
|
|
|
+ let userTotal = paList.length;
|
|
|
+ let overMax = false;
|
|
|
for (const u of users) {
|
|
|
if (u.account === undefined || u.account === null || u.name === undefined || u.name === null ||
|
|
|
u.password === undefined || u.password === null || u.company === undefined || u.company === null ||
|
|
@@ -472,24 +476,29 @@ module.exports = app => {
|
|
|
u.company_id = companyInfo.id;
|
|
|
u.account_group = companyInfo.type;
|
|
|
if (this._.findIndex(paList, { account: u.account }) === -1 && this._.findIndex(insertData, { account: u.account }) === -1) {
|
|
|
- insertData.push({
|
|
|
- project_id: pid,
|
|
|
- account: u.account,
|
|
|
- name: u.name,
|
|
|
- password: crypto.createHmac('sha1', u.account).update(u.password)
|
|
|
- .digest().toString('base64'),
|
|
|
- account_group: u.account_group,
|
|
|
- company: u.company,
|
|
|
- company_id: companyInfo.id,
|
|
|
- role: u.role,
|
|
|
- mobile: u.mobile || '',
|
|
|
- telephone: u.telephone || '',
|
|
|
- create_time,
|
|
|
- });
|
|
|
+ if (maxUser === 0 || userTotal <= maxUser) {
|
|
|
+ insertData.push({
|
|
|
+ project_id: pid,
|
|
|
+ account: u.account,
|
|
|
+ name: u.name,
|
|
|
+ password: crypto.createHmac('sha1', u.account).update(u.password)
|
|
|
+ .digest().toString('base64'),
|
|
|
+ account_group: u.account_group,
|
|
|
+ company: u.company,
|
|
|
+ company_id: companyInfo.id,
|
|
|
+ role: u.role,
|
|
|
+ mobile: u.mobile || '',
|
|
|
+ telephone: u.telephone || '',
|
|
|
+ create_time,
|
|
|
+ });
|
|
|
+ userTotal++;
|
|
|
+ } else {
|
|
|
+ overMax = true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
if (insertData.length > 0) await this.db.insert(this.tableName, insertData);
|
|
|
- return insertData.length;
|
|
|
+ return { insertNum: insertData.length, overMax };
|
|
|
}
|
|
|
|
|
|
/**
|