Commit 5159d87e by 王昆

gsb

parent e24903fd
var system = require("../../../system")
const CtlBase = require("../../ctl.base");
const uuidv4 = require('uuid/v4');
class UserCtl extends CtlBase {
constructor() {
super("auth", CtlBase.getServiceName(UserCtl));
this.redisClient = system.getObject("util.redisClient");
constructor() {
super("auth", CtlBase.getServiceName(UserCtl));
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);
var password = this.trim(pobj.password);
try {
var user = await this.service.findOne({"loginname": loginName});
if (!user) {
return system.getResultFail(-1, "用户不存在");
}
user = user.dataValues;
if (user.password !== super.encryptPasswd(password)) {
return system.getResultFail(-1, "密码错误");
}
return system.getResultSuccess(user, "");
} catch (error) {
console.log(error);
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 register(pobj, qobj, req) {
try {
let user = await this.service.create({
userName: this.trim(pobj.userName),
password: this.encryptPasswd(pobj.password),
mobile: this.trim(pobj.mobile),
nickName: this.trim(pobj.nickName),
sign_body: this.trim(pobj.sign_body),
isAdmin: Number(pobj.isAdmin) ? true : false,
});
return system.getResultSuccess(user);
} catch (error) {
console.log(error);
if (error.message == 'Validation error') {
return system.getResult(-1, "用户名已存在");
}
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async userList(queryobj, obj, req){
var pageInfo = obj.pageInfo || {};
var search = obj.search || {};
var apps = await this.service.userPage(pageInfo, search);
return system.getResultSuccess(apps, null);
}
async setLogin(user) {
let sid = uuidv4();
await this.redisClient.setWithEx(sid, JSON.stringify(user), 60 * 60 * 5);
return sid;
}
}
module.exports = UserCtl;
\ No newline at end of file
......@@ -9,7 +9,6 @@ class Dao {
this.model = db.models[this.modelName];
}
async preCreate(u) {
u.id = await this.redisClient.genrateId(this.modelName);
return u;
}
async create(u, t) {
......
......@@ -5,67 +5,6 @@ class UserDao extends Dao {
constructor() {
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;
\ No newline at end of file
......@@ -3,25 +3,24 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("user", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
loginname: {
type: DataTypes.STRING,
allowNull: false,
},
userName: 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,
version: true,
freezeTableName: true,
// freezeTableName: true,
// define the table's name
tableName: 'tbl_users',
tableName: 'p_user',
validate: {},
indexes: [
// Create a unique index on email
......@@ -55,4 +54,4 @@ module.exports = (db, DataTypes) => {
// }
]
});
}
}
\ No newline at end of file
......@@ -3,46 +3,17 @@ const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class UserService extends ServiceBase {
constructor() {
super("auth", ServiceBase.getDaoName(UserService));
}
constructor() {
super("auth", ServiceBase.getDaoName(UserService));
}
async login(userName, password) {
// password = this.getEncryptStr(password);
async register(user) {
let ss = await this.dao.register(user);
}
let user = await this.dao.findOne({userName: userName});
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;
\ No newline at end of file
......@@ -6,11 +6,16 @@ var settings={
db:10,
},
database:{
dbname : "stat",
user: "root",
password: "!@#Qaz741",
// dbname : "stat",
// user: "root",
// password: "!@#Qaz741",
// config: {
// host: 'rm-2ze5muw8tb37i3ig4lo.mysql.rds.aliyuncs.com',
dbname : "bpo_stat",
user: "write",
password: "write",
config: {
host: 'rm-2ze5muw8tb37i3ig4lo.mysql.rds.aliyuncs.com',
host: '192.168.18.237',
port: 3306,
// host: '43.247.184.35',
// 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