Commit 5159d87e by 王昆

gsb

parent e24903fd
var system = require("../../../system") var system = require("../../../system")
const CtlBase = require("../../ctl.base"); const CtlBase = require("../../ctl.base");
const uuidv4 = require('uuid/v4');
class UserCtl extends CtlBase { class UserCtl extends CtlBase {
constructor() { constructor() {
super("auth", CtlBase.getServiceName(UserCtl)); super("auth", CtlBase.getServiceName(UserCtl));
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
}
async login(pobj, qobj, req) {
let loginName = this.trim(pobj.loginName);
let password = this.trim(pobj.password);
try {
let user = await this.service.findOne({"userName": loginName});
if (!user) {
return system.getResultFail(-1, "用户不存在");
}
if (user.password !== this.encryptPasswd(password)) {
return system.getResultFail(-1, "用户名或密码错误");
}
let sid = await this.setLogin(user);
return system.getResultSuccess(sid);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
} }
}
async login(pobj, qobj, req) {
var loginName = this.trim(pobj.loginname); async register(pobj, qobj, req) {
var password = this.trim(pobj.password); try {
try { let user = await this.service.create({
var user = await this.service.findOne({"loginname": loginName}); userName: this.trim(pobj.userName),
if (!user) { password: this.encryptPasswd(pobj.password),
return system.getResultFail(-1, "用户不存在"); mobile: this.trim(pobj.mobile),
} nickName: this.trim(pobj.nickName),
user = user.dataValues; sign_body: this.trim(pobj.sign_body),
if (user.password !== super.encryptPasswd(password)) { isAdmin: Number(pobj.isAdmin) ? true : false,
return system.getResultFail(-1, "密码错误"); });
}
return system.getResultSuccess(user, ""); return system.getResultSuccess(user);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return system.getResultFail(500, "接口异常:" + error.message); if (error.message == 'Validation error') {
} return system.getResult(-1, "用户名已存在");
} }
return system.getResultFail(500, "接口异常:" + error.message);
async register(pobj, qobj, req) {
if (!pobj.loginname) {
return system.getResultFail(-1, "用户为空");
}
if (!pobj.password) {
return system.getResultFail(-1, "密码为空");
}
var user = await this.service.findOne({
loginname: pobj.loginname
});
if (user) {
return system.getResultFail(-1, "用户已存在, 请修改并重试");
}
let inse = {
loginname: pobj.loginname,
password: super.encryptPasswd(pobj.password)
};
var u = await this.service.register(inse);
return system.getResultSuccess(u, "注册成功");
} }
}
async userList(queryobj, obj, req){ async setLogin(user) {
var pageInfo = obj.pageInfo || {}; let sid = uuidv4();
var search = obj.search || {}; await this.redisClient.setWithEx(sid, JSON.stringify(user), 60 * 60 * 5);
var apps = await this.service.userPage(pageInfo, search); return sid;
return system.getResultSuccess(apps, null); }
}
} }
module.exports = UserCtl; module.exports = UserCtl;
\ No newline at end of file
...@@ -9,7 +9,6 @@ class Dao { ...@@ -9,7 +9,6 @@ class Dao {
this.model = db.models[this.modelName]; this.model = db.models[this.modelName];
} }
async preCreate(u) { async preCreate(u) {
u.id = await this.redisClient.genrateId(this.modelName);
return u; return u;
} }
async create(u, t) { async create(u, t) {
......
...@@ -5,67 +5,6 @@ class UserDao extends Dao { ...@@ -5,67 +5,6 @@ class UserDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(UserDao)); super(Dao.getModelName(UserDao));
} }
async register(user) {
console.log(user)
var sql = "SELECT id FROM tbl_users WHERE loginname LIKE :loginname ";
var list = await this.customQuery(sql, {loginname: "%" + user.loginname + "%"});
console.log(list)
}
async getAuths(userid) {
var self = this;
return this.model.findOne({
where: {id: userid},
include: [{model: self.db.models.account, attributes: ["id", "isSuper", "referrerOnlyCode"]},
{
model: self.db.models.role, as: "Roles", attributes: ["id", "code"], include: [
{model: self.db.models.product, as: "Products", attributes: ["id", "code"]}
]
},
],
});
}
extraModelFilter() {
//return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return {
"key": "include",
"value": [{model: this.db.models.app,}, {
model: this.db.models.role,
as: "Roles",
attributes: ["id", "name"]
}]
};
}
extraWhere(obj, w, qc, linkAttrs) {
if (obj.codepath && obj.codepath != "") {
// if(obj.codepath.indexOf("userarch")>0){//说明是应用管理员的查询
// console.log(obj);
// w["app_id"]=obj.appid;
// }
}
if (linkAttrs.length > 0) {
var search = obj.search;
var lnkKey = linkAttrs[0];
var strq = "$" + lnkKey.replace("~", ".") + "$";
w[strq] = {[this.db.Op.like]: "%" + search[lnkKey] + "%"};
}
return w;
}
//修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId, company_only_code, result) {
var customerObj = {companyOnlyCode: company_only_code};
var putSqlWhere = {where: {id: userId}};
this.updateByWhere(customerObj, putSqlWhere);
return result;
}
} }
module.exports = UserDao; module.exports = UserDao;
\ No newline at end of file
...@@ -3,25 +3,24 @@ const settings = require("../../../../config/settings"); ...@@ -3,25 +3,24 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("user", { return db.define("user", {
id: { userName: DataTypes.STRING,
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
loginname: {
type: DataTypes.STRING,
allowNull: false,
},
password: DataTypes.STRING, password: DataTypes.STRING,
status : DataTypes.INTEGER, mobile: DataTypes.INTEGER,
nickName: DataTypes.INTEGER,
mobile: DataTypes.INTEGER,
mobile: DataTypes.INTEGER,
isAdmin: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
}, { }, {
paranoid: true,//假的删除 paranoid: true, //假的删除
underscored: true, underscored: true,
version: true, version: true,
freezeTableName: true, freezeTableName: true,
// freezeTableName: true, // freezeTableName: true,
// define the table's name // define the table's name
tableName: 'tbl_users', tableName: 'p_user',
validate: {}, validate: {},
indexes: [ indexes: [
// Create a unique index on email // Create a unique index on email
...@@ -55,4 +54,4 @@ module.exports = (db, DataTypes) => { ...@@ -55,4 +54,4 @@ module.exports = (db, DataTypes) => {
// } // }
] ]
}); });
} }
\ No newline at end of file
...@@ -3,46 +3,17 @@ const ServiceBase = require("../../sve.base"); ...@@ -3,46 +3,17 @@ const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
class UserService extends ServiceBase { class UserService extends ServiceBase {
constructor() { constructor() {
super("auth", ServiceBase.getDaoName(UserService)); super("auth", ServiceBase.getDaoName(UserService));
} }
async login(userName, password) {
// password = this.getEncryptStr(password);
async register(user) { let user = await this.dao.findOne({userName: userName});
let ss = await this.dao.register(user);
}
async userPage(pageInfo, search) {
var currentPage = Number(pageInfo.pageNo || 1);
var pageSize = Number(pageInfo.pageSize || 10);
var where = {};
if (search.nickName) {
where.nickName = {
[this.db.Op.like]: "%" + search.nickName + "%"
};
}
if (search.userName) {
where.userName = search.userName;
}
if (search.mobile) {
where.mobile = search.mobile;
}
if(search.isBack) {
where.utype = Number(search.isBack) - 1;
}
var orderby = [
["id", 'desc']
];
return await this.getPageList(currentPage, pageSize, where, orderby);
}
}
} }
module.exports = UserService; module.exports = UserService;
\ No newline at end of file
...@@ -6,11 +6,16 @@ var settings={ ...@@ -6,11 +6,16 @@ var settings={
db:10, db:10,
}, },
database:{ database:{
dbname : "stat", // dbname : "stat",
user: "root", // user: "root",
password: "!@#Qaz741", // password: "!@#Qaz741",
// config: {
// host: 'rm-2ze5muw8tb37i3ig4lo.mysql.rds.aliyuncs.com',
dbname : "bpo_stat",
user: "write",
password: "write",
config: { config: {
host: 'rm-2ze5muw8tb37i3ig4lo.mysql.rds.aliyuncs.com', host: '192.168.18.237',
port: 3306, port: 3306,
// host: '43.247.184.35', // host: '43.247.184.35',
// port: 8899,s // port: 8899,s
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment