|
|
var request = require('request');
|
|
|
var _ = require('lodash');
|
|
|
var fs = require('fs');
|
|
|
var Geetest = require('gt3-sdk');
|
|
|
|
|
|
var Iaccount = global.Register.system;
|
|
|
var pcGeetest = new Geetest({
|
|
|
geetest_id: '4bf7f911856073c1347247667790e7c4',
|
|
|
geetest_key: '8d41283971d071216f1cef3d190d6b44'
|
|
|
});
|
|
|
|
|
|
var Utils = {
|
|
|
createrMenus: function (data) {
|
...
|
...
|
@@ -76,30 +81,73 @@ module.exports = { |
|
|
var userInfo = {},result = { code: 400, message: "登录失败" },isSuccess=false;
|
|
|
var user = req.body.user||req.query.user;
|
|
|
var password = req.body.password||req.query.password;
|
|
|
var captcha = req.body.captcha || req.query.captcha;
|
|
|
var verifyCode = captcha.split(',');
|
|
|
var errcallback = function (err) {
|
|
|
return callback(null, result);
|
|
|
}
|
|
|
common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
|
|
|
var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
|
|
|
userInfo = { auth: userData, uid: userData.pid, name: userData.truename, role: userData.roleName, right: {},shopList:[],brands:[]};
|
|
|
if(userData.data_authority&&userData.data_authority.brand&&userData.data_authority.brand.list){
|
|
|
userInfo.brands=userData.data_authority.brand.is_all?"0":Object.keys(userData.data_authority.brand.list);
|
|
|
}
|
|
|
allRes.data.forEach(function (data) {
|
|
|
if (data.platform_id == Iaccount.WEBSITE) {
|
|
|
userInfo.right[data.path] = true;
|
|
|
}
|
|
|
|
|
|
if (!captcha) {
|
|
|
return callback(null, {
|
|
|
message: '图形验证失败',
|
|
|
code: 405
|
|
|
});
|
|
|
common.getResourceByPid(userData.pid, userData.role_id).done(function (getRRes) {
|
|
|
userInfo.menu = Utils.createrMenus(getRRes.data);
|
|
|
req.session.user = userInfo;
|
|
|
if (cookie && cookie.length > 0) {
|
|
|
req.session.gray = cookie[0];
|
|
|
result = { code: 200, message: "登录成功" ,data:req.session.user};
|
|
|
}
|
|
|
return callback(null, result);
|
|
|
},errcallback);
|
|
|
}, errcallback);
|
|
|
}
|
|
|
|
|
|
pcGeetest.validate(req.session.fallback, {
|
|
|
geetest_challenge: verifyCode[0],
|
|
|
geetest_validate: verifyCode[1],
|
|
|
geetest_seccode: verifyCode[2]
|
|
|
}, function(err, success) {
|
|
|
if (err) {
|
|
|
return callback(null, {
|
|
|
message: '网络失败',
|
|
|
code: 405
|
|
|
});
|
|
|
} else if (!success) {
|
|
|
return callback(null, {
|
|
|
message: '图形验证失败',
|
|
|
code: 405
|
|
|
});
|
|
|
} else {
|
|
|
common.Ilogin(user, password).allRight().sessionAsync(user, password).done(function (IloginRes,allRes,sesRes) {
|
|
|
var userData = IloginRes.data, cookie = sesRes.caseless.dict["set-cookie"];
|
|
|
userInfo = { auth: userData, uid: userData.pid, name: userData.truename, role: userData.roleName, right: {},shopList:[],brands:[]};
|
|
|
if(userData.data_authority&&userData.data_authority.brand&&userData.data_authority.brand.list){
|
|
|
userInfo.brands=userData.data_authority.brand.is_all?"0":Object.keys(userData.data_authority.brand.list);
|
|
|
}
|
|
|
allRes.data.forEach(function (data) {
|
|
|
if (data.platform_id == Iaccount.WEBSITE) {
|
|
|
userInfo.right[data.path] = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
common.getResourceByPid(userData.pid, userData.role_id).done(function (getRRes) {
|
|
|
userInfo.menu = Utils.createrMenus(getRRes.data);
|
|
|
req.session.user = userInfo;
|
|
|
if (cookie && cookie.length > 0) {
|
|
|
req.session.gray = cookie[0];
|
|
|
result = { code: 200, message: "登录成功" ,data:req.session.user};
|
|
|
}
|
|
|
return callback(null, result);
|
|
|
},errcallback);
|
|
|
}, errcallback);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
geeCaptcha: function(req, callback, common) {
|
|
|
return pcGeetest.register({
|
|
|
client_type: 'web'
|
|
|
}, function(err, data) {
|
|
|
if (err) {
|
|
|
return callback(null, {
|
|
|
code: 500,
|
|
|
message: "极验证注册失败"
|
|
|
});
|
|
|
}
|
|
|
|
|
|
callback(null, data);
|
|
|
});
|
|
|
},
|
|
|
isUsedMenuAuth:{
|
|
|
title:'检查有没有权限',
|
...
|
...
|
|