|
@@ -70,25 +70,33 @@ module.exports = app => {
|
|
|
this.ctx.validate(rule, data);
|
|
|
|
|
|
let accountData = {};
|
|
|
- let projectId = 0;
|
|
|
+ let projectInfo = {};
|
|
|
+ let projectList = [];
|
|
|
if (loginType === 2) {
|
|
|
// 查找项目数据
|
|
|
const projectData = await this.ctx.service.project.getProjectByCode(data.project.toString());
|
|
|
if (projectData === null) {
|
|
|
throw '不存在项目数据';
|
|
|
}
|
|
|
- projectId = projectData.id;
|
|
|
+ projectInfo = {
|
|
|
+ id: projectData.id,
|
|
|
+ name: projectData.name,
|
|
|
+ userAccount: projectData.user_account,
|
|
|
+ };
|
|
|
|
|
|
// 查找对应数据
|
|
|
accountData = await this.db.get(this.tableName, {
|
|
|
account: data.account,
|
|
|
project_id: projectData.id,
|
|
|
+ enable: 1,
|
|
|
});
|
|
|
|
|
|
if (accountData === null) {
|
|
|
throw '不存在对应用户数据';
|
|
|
}
|
|
|
|
|
|
+ projectList = await this.getProjectInfoByAccount(data.account);
|
|
|
+
|
|
|
// 判断密码
|
|
|
if (accountData.is_admin === 1) {
|
|
|
// 管理员则用sso通道判断
|
|
@@ -128,8 +136,9 @@ module.exports = app => {
|
|
|
loginTime: currentTime,
|
|
|
sessionToken,
|
|
|
loginType,
|
|
|
- projectId,
|
|
|
};
|
|
|
+ this.ctx.session.sessionProject = projectInfo;
|
|
|
+ this.ctx.session.sessionProjectList = projectList;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
@@ -138,6 +147,62 @@ module.exports = app => {
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据项目id获取用户列表
|
|
|
+ *
|
|
|
+ * @param {Number} projectId - 项目id
|
|
|
+ * @return {Array} - 返回用户数据
|
|
|
+ */
|
|
|
+ async getAccountByProjectId(projectId) {
|
|
|
+ const condition = {
|
|
|
+ columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'telephone', 'enable'],
|
|
|
+ where: { project_id: projectId, is_admin: 0 },
|
|
|
+ };
|
|
|
+ const accountList = await this.getAllDataByCondition(condition);
|
|
|
+
|
|
|
+ return accountList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 停用/启用
|
|
|
+ *
|
|
|
+ * @param {Number} accountId - 账号id
|
|
|
+ * @return {Boolean} - 返回操作结果
|
|
|
+ */
|
|
|
+ async enableAccount(accountId) {
|
|
|
+ let result = false;
|
|
|
+ const accountData = await this.getDataByCondition({ id: accountId });
|
|
|
+ if (accountData === null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ const changeStatus = accountData.enable === 1 ? 0 : 1;
|
|
|
+ result = await this.update({ enable: changeStatus }, { id: accountId });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据账号id查找对应的项目数据
|
|
|
+ *
|
|
|
+ * @param {Number} account - 账号
|
|
|
+ * @return {Array} - 返回数据
|
|
|
+ */
|
|
|
+ async getProjectInfoByAccount(account) {
|
|
|
+ let column = ['p.name', 'p.id'];
|
|
|
+ column = column.join(',');
|
|
|
+ const sql = 'SELECT ' + column + ' FROM ' +
|
|
|
+ '?? AS pa ' +
|
|
|
+ 'LEFT JOIN ?? AS p ' +
|
|
|
+ 'ON pa.`project_id` = p.`id` ' +
|
|
|
+ 'WHERE pa.`account` = ? ' +
|
|
|
+ 'GROUP BY pa.`project_id`;';
|
|
|
+ const sqlParam = [this.tableName, this.ctx.service.project.tableName, account];
|
|
|
+ const projectInfo = await this.db.query(sql, sqlParam);
|
|
|
+
|
|
|
+ return projectInfo;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ProjectAccount;
|