Commit 937a2439 by 王昆

gsb

parent 2566a7fc
...@@ -104,9 +104,9 @@ class CtlBase { ...@@ -104,9 +104,9 @@ class CtlBase {
var d = new Date(time); var d = new Date(time);
return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate(); return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
} }
async doexec(methodname, pobj, query, req) { async doexec(methodname, pobj, query, req, res) {
try { try {
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req, res);
return rtn; return rtn;
} catch (e) { } catch (e) {
console.log(e.stack); console.log(e.stack);
......
...@@ -46,50 +46,24 @@ class UserCtl extends CtlBase { ...@@ -46,50 +46,24 @@ class UserCtl extends CtlBase {
if (vrs.status !== 0) { if (vrs.status !== 0) {
// return vrs; // return vrs;
} }
// 查用户 // 查用户
var loginrs = await this.platformUtils.login(loginName, password); var loginrs = await this.platformUtils.login(loginName, password);
if(loginrs.status !== 0) { if(loginrs.status !== 0) {
return loginrs; return loginrs;
} }
var puser = loginrs.Data; var user = await this.service.authByCode(loginrs.data.opencode);
req.session.user = user;
return system.getResultSuccess(puser); return system.getResultSuccess(user);
// this.service.getUserByUserNamePwd({
// userName: loginName,
// password: password,
// app_id: settings.app_id
// });
// var adminUser = await this.service.findOne({
// ucname: loginName
// });
// // var adminUser = await this.service.findById(1);
// if (!adminUser) {
// return system.getResult(null, "用户名或密码错误");
// }
// var passwdMD5 = md5(password);
// if (passwdMD5 != adminUser.passwd) {
// return system.getResult(null, "用户名或密码错误");
// }
// adminUser.lastLoginTime = new Date();
// await adminUser.save();
// var xggadminsid = uuidv4();
// xggadminsid = "3cb49932-fa02-44f0-90db-9f06fe02e5c7";
// await this.redisClient.setWithEx(xggadminsid, JSON.stringify(adminUser), 60 * 60 * 2);
// // 处理登录逻辑
// var result = {
// xggadminsid: xggadminsid,
// }
// return system.getResultSuccess(result);
} catch (error) { } catch (error) {
return system.getResultFail(500, "接口异常:" + error.message); return system.getResultFail(500, "接口异常:" + error.message);
} }
} }
async setLogin(req, res, user) {
var xggadminsid = uuidv4();
await this.redisClient.setWithEx(xggadminsid + "_admin_user", JSON.stringify(user), 60 * 60 * 2);
return xggadminsid;
}
async forgetPassword(qobj, pobj, req, res) { async forgetPassword(qobj, pobj, req, res) {
var mobile = this.trim(pobj.mobile); var mobile = this.trim(pobj.mobile);
...@@ -279,27 +253,9 @@ class UserCtl extends CtlBase { ...@@ -279,27 +253,9 @@ class UserCtl extends CtlBase {
async checkLogin(gobj, qobj, req) { async checkLogin(gobj, qobj, req) {
//当前如果缓存中存在user,还是要检查当前user所在的域名,如果不和来访一致,则退出重新登录 //当前如果缓存中存在user,还是要检查当前user所在的域名,如果不和来访一致,则退出重新登录
if (req.session.user) { if (req.session.user) {
var x = null; return system.getResultSuccess(req.session.user);
if (req.session.user.Roles) {
x = req.session.user.Roles.map(r => {
return r.code
});
}
var tmp = {
id: req.session.user.id,
userName: req.session.user.userName,
nickName: req.session.user.nickName,
mobile: req.session.user.mobile,
isAdmin: req.session.user.isAdmin,
created_at: req.session.user.created_at,
email: req.session.user.email,
headUrl: req.session.user.headUrl,
roles: x ? x.join(",") : ""
}
return system.getResult(tmp, "用户登录", req);
} else { } else {
req.session.user = null; req.session.user = null;
//req.session.destroy();
return system.getResult(null, "用户未登录", req); return system.getResult(null, "用户未登录", req);
} }
} }
......
...@@ -3,7 +3,6 @@ var settings = require("../../../../config/settings"); ...@@ -3,7 +3,6 @@ var settings = require("../../../../config/settings");
const CtlBase = require("../../ctlms.base"); const CtlBase = require("../../ctlms.base");
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
var moment = require("moment"); var moment = require("moment");
var svgCaptcha = require('svg-captcha');
class CaptchaCtl extends CtlBase { class CaptchaCtl extends CtlBase {
constructor() { constructor() {
......
...@@ -4,18 +4,37 @@ const settings = require("../../../../config/settings") ...@@ -4,18 +4,37 @@ 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));
this.platformUtils = system.getObject("util.businessManager.opPlatformUtils");
} }
async saveUser(user) {
var u = await this.dao.findOne({
ucid: user.ucid,
}) || {};
u.ucid = user.ucid;
u.ucname = user.ucname;
u.passwd = user.passwd;
u.lastLoginTime = user.lastLoginTime;
if(u.id) {
u = await this.dao.create(ucid);
} else {
await u.save();
}
return u;
}
async authByCode(opencode) { async authByCode(opencode) {
var existedUser = null; var existedUser = null;
var rawUser = null; var rawUser = null;
var openuser = await this.apiCallWithAk(settings.paasUrl() + "api/auth/accessAuth/authByCode", { opencode: opencode }); var openuser = await this.apiCallWithAk(settings.paasUrl() + "api/auth/accessAuth/authByCode", { opencode: opencode });
if (openuser) { if (openuser) {
//先查看自己系统中是否已经存在当前用户 //先查看自己系统中是否已经存在当前用户
existedUser = await this.dao.model.findOne({ where: { ucname: openuser.userName, ucid: openuser.id }, raw: true }); existedUser = await this.dao.model.findOne({ where: { ucname: openuser.userName, ucid: openuser.account_id }, raw: true });
if (!existedUser) { if (!existedUser) {
existedUser = await this.register(openuser); existedUser = await this.register(openuser);
} }
rawUser = existedUser.get({ raw: true }); rawUser = existedUser;
rawUser.Roles = openuser.Roles; rawUser.Roles = openuser.Roles;
} }
return rawUser; return rawUser;
...@@ -25,8 +44,8 @@ class UserService extends ServiceBase { ...@@ -25,8 +44,8 @@ class UserService extends ServiceBase {
} }
async register(openuser) { async register(openuser) {
var param = { var param = {
ucname: openuser.userName, ucid: openuser.id, ucname: openuser.userName, ucid: openuser.account_id,
last_login_time: new Date() lastLoginTime: new Date()
} }
var cruser = await this.dao.create(param); var cruser = await this.dao.create(param);
return cruser; return cruser;
......
...@@ -173,8 +173,8 @@ class System { ...@@ -173,8 +173,8 @@ class System {
// var domain = "http://127.0.0.1"; // var domain = "http://127.0.0.1";
return { return {
// 公共服务 // 公共服务
// common: domain + ":3102" + path, common: domain + ":3102" + path,
common: "http://127.0.0.1:3102" + path, // common: "http://127.0.0.1:3102" + path,
// 商户服务 // 商户服务
merchant: domain + ":3101" + path, merchant: domain + ":3101" + path,
...@@ -185,8 +185,8 @@ class System { ...@@ -185,8 +185,8 @@ class System {
// order: "http://127.0.0.1:3103" + path, // order: "http://127.0.0.1:3103" + path,
// 发票服务 // 发票服务
// invoice: domain + ":3105" + path, invoice: domain + ":3105" + path,
invoice: "http://127.0.0.1:3105" + path, // invoice: "http://127.0.0.1:3105" + path,
} }
} else { } else {
var odomain = "http://123.57.217.203" var odomain = "http://123.57.217.203"
......
...@@ -67,7 +67,9 @@ class OpPlatformUtils { ...@@ -67,7 +67,9 @@ class OpPlatformUtils {
if (!reqApiAccessKey || !reqApiAccessKey.accessKey) { if (!reqApiAccessKey || !reqApiAccessKey.accessKey) {
return system.getResult(null, "获取请求token失败"); return system.getResult(null, "获取请求token失败");
} }
var param = { mobile: mobile } var param = {
mobile: mobile
}
//按照访问token //按照访问token
var restResult = await this.restClient.execPostWithAK( var restResult = await this.restClient.execPostWithAK(
param, param,
...@@ -144,6 +146,19 @@ class OpPlatformUtils { ...@@ -144,6 +146,19 @@ class OpPlatformUtils {
} }
return system.getResultSuccess(restResult.data); return system.getResultSuccess(restResult.data);
} }
/**
* 登录并获取登录用户信息
* @param {*} userName
* @param {*} password
*/
async loginInfo(userName, password) {
var loginrs = await this.login(userName, password);
if (loginrs.status !== 0) {
return loginrs;
}
return await this.authByCode(loginrs.data.opencode)
}
} }
module.exports = OpPlatformUtils; module.exports = OpPlatformUtils;
\ No newline at end of file
var url = require("url"); var url = require("url");
var system = require("../../base/system"); var system = require("../../base/system");
var settings = require("../settings");
var userSve = system.getObject("service.auth.userSve"); var userSve = system.getObject("service.auth.userSve");
module.exports = function (app) { module.exports = function (app) {
app.get("/auth", async function (req, res) { app.get("/auth", async function (req, res) {
if (!req.query.opencode) { var opencode = req.query.opencode || "";
if (!opencode) {
return system.getResult(null, "opencode参数不能为空"); return system.getResult(null, "opencode参数不能为空");
} }
return await userSve.authByCode(opencode); var user = await userSve.authByCode(opencode);
req.session.user = user;
console.log(req.session.id);
res.redirect(settings.indexPage());
}); });
app.get('/api/:gname/:qname/:method', function (req, res) { app.get('/api/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"]; var classPath = req.params["qname"];
......
...@@ -7,8 +7,9 @@ const redisClient = system.getObject("util.redisClient"); ...@@ -7,8 +7,9 @@ const redisClient = system.getObject("util.redisClient");
module.exports = function (app) { module.exports = function (app) {
app.all("/web/*", async function (req, res, next) { app.all("/web/*", async function (req, res, next) {
var xggadminsid = req.headers["xggadminsid"] || ""; // var xggadminsid = req.headers["xggadminsid"] || "";
var jsonUser = await redisClient.get(xggadminsid); // var jsonUser = await redisClient.get(xggadminsid);
var jsonUser = req.session.user;
if (req.url.indexOf("auth/userCtl/login") > 0 || if (req.url.indexOf("auth/userCtl/login") > 0 ||
req.url.indexOf("auth/userCtl/smsCode") > 0 || req.url.indexOf("auth/userCtl/smsCode") > 0 ||
...@@ -17,7 +18,7 @@ module.exports = function (app) { ...@@ -17,7 +18,7 @@ module.exports = function (app) {
req.url.indexOf("getRsConfig") > 0) { req.url.indexOf("getRsConfig") > 0) {
if (jsonUser) { if (jsonUser) {
req.loginUser = JSON.parse(jsonUser); req.loginUser = jsonUser;
} else { } else {
req.loginUser = null; req.loginUser = null;
} }
...@@ -27,10 +28,9 @@ module.exports = function (app) { ...@@ -27,10 +28,9 @@ module.exports = function (app) {
if (!jsonUser) { if (!jsonUser) {
res.end(JSON.stringify({ status: -99, msg: "no login" })); res.end(JSON.stringify({ status: -99, msg: "no login" }));
return; return;
} else {
redisClient.setWithEx(xggadminsid, jsonUser, 60 * 60 * 3);
} }
req.loginUser = JSON.parse(jsonUser); req.session.user = jsonUser;
req.loginUser = jsonUser;
next(); next();
}); });
......
...@@ -35,7 +35,7 @@ var settings = { ...@@ -35,7 +35,7 @@ var settings = {
}, },
paasUrl: function () { paasUrl: function () {
if (this.env == "dev") { if (this.env == "dev") {
return "http://open.gongsibao.com/"; return "http://192.168.18.125:4001/";
} else { } else {
return "http://open.gongsibao.com/"; return "http://open.gongsibao.com/";
} }
...@@ -48,6 +48,14 @@ var settings = { ...@@ -48,6 +48,14 @@ var settings = {
return 1; return 1;
}, },
}, },
indexPage: function() {
if(this.env == "dev") {
// return "http://localhost:8080";
return "https://xggadmin.gongsibao.com";
} else {
return "https://xggadmin.gongsibao.com";
}
},
homePage: function () { homePage: function () {
if (this.env == "dev") { if (this.env == "dev") {
var localsettings = require("./localsettings"); var localsettings = require("./localsettings");
......
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