//'use strict';
var app = angular.module('myloginApp', ['ngRoute','ngResource','loginControllers','LoginServices']);
app.config(['$routeProvider','$httpProvider',function ($routeProvider,$httpProvider) {
$routeProvider
.when('/', {
title: '登录',
templateUrl: 'login.html',
controller:'loginCtrl'
}).otherwise({
});
//跨域
/*$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common['Content-Type']= 'application/json';
$httpProvider.defaults.headers.common['app-key']='fb98ab9159f51fd0'; //(key)
$httpProvider.defaults.headers.common['Authorization']='12345678'; //(key)*/
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common['Content-Type']= 'application/json';
$httpProvider.defaults.headers.common['app-key']='fb98ab9159f51fd0'; //(key)
$httpProvider.defaults.headers.common['Authorization']='12345678'; //(key)
}]);
var loginControllers = angular.module('loginControllers',[]);
/*定义 Controller: loginCtrl (登录)*/
loginControllers.controller('loginCtrl', ['$scope','$window','loginService',function ($scope,$window,loginService) {
$scope.objLoginInfo={};
$scope.errorInfo='';
$scope.gotologin = function(objLoginInfo) {
// 得到Key及iv
var strMD5Passwd = CryptoJS.MD5(objLoginInfo.password).toString();
var strRandomIV = randomKey(16);
var strData = URL.getHost();
//var strData = '192.168.192.223';
var key = CryptoJS.enc.Utf8.parse(strMD5Passwd);
var iv = CryptoJS.enc.Utf8.parse(strRandomIV);
var strAesEncrypted = CryptoJS.AES.encrypt(strData, key,
{ iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding});
var strUserName = objLoginInfo.username;
var strUserNameLength = ZeroPadding.left(strUserName.length, 3);
var strDataPacket = strRandomIV + strUserNameLength + strAesEncrypted + strUserName;
//var url = '120.26.83.34';
//var url = '192.168.192.223';
var url = strData;
strDataPacket = url + "/" + Base64.encode(strDataPacket);
//strDataPacket = '192.168.1.210/'+objLoginInfo.username+','+objLoginInfo.password;
loginService.getToken(strDataPacket, function (response, status, headers, config) {
//缓存用户信息
var a=listToObject(response.user,'rows').rows;
var user=a[0];
sessionStorage.setItem('strUser',JSON.stringify(user));
//角色
var b=listToObject(response.role,'rows').rows;
var role=b[0];
sessionStorage.setItem('strRole',JSON.stringify(role));
cookieOperate.setCookie('ckdToken', headers('Authorization'));
cookieOperate.setCookie('userName', objLoginInfo.username);
if(role.index_page){
window.location.href='index.html#'+role.index_page;
}else{
window.location.href='index.html';
}
/*if (role.rid==1) {
window.location.href='index.html';
}else if (role.rid==2) {
window.location.href='index.html#/doctorFirst';
}else if (role.rid==3) {
window.location.href='index.html#/nursefirst';
}else{
window.location.href='index.html#/nutritionistFirst';
}*/
sessionStorage.setItem("strUserName",objLoginInfo.username);
//JSON.parse();
//window.location.href='index.html';
///zbdy-webapp_20150519/zbdy-webapp/app/login.html
},function(data){
alert('用户名密码错误,登录失败');
});
}
}])
var app = angular.module('myloginApp', ['ngRoute','ngResource','loginControllers','LoginServices']);
app.config(['$routeProvider','$httpProvider',function ($routeProvider,$httpProvider) {
$routeProvider
.when('/', {
title: '登录',
templateUrl: 'login.html',
controller:'loginCtrl'
}).otherwise({
});
//跨域
/*$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common['Content-Type']= 'application/json';
$httpProvider.defaults.headers.common['app-key']='fb98ab9159f51fd0'; //(key)
$httpProvider.defaults.headers.common['Authorization']='12345678'; //(key)*/
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common['Content-Type']= 'application/json';
$httpProvider.defaults.headers.common['app-key']='fb98ab9159f51fd0'; //(key)
$httpProvider.defaults.headers.common['Authorization']='12345678'; //(key)
}]);
var loginControllers = angular.module('loginControllers',[]);
/*定义 Controller: loginCtrl (登录)*/
loginControllers.controller('loginCtrl', ['$scope','$window','loginService',function ($scope,$window,loginService) {
$scope.objLoginInfo={};
$scope.errorInfo='';
$scope.gotologin = function(objLoginInfo) {
// 得到Key及iv
var strMD5Passwd = CryptoJS.MD5(objLoginInfo.password).toString();
var strRandomIV = randomKey(16);
var strData = URL.getHost();
//var strData = '192.168.192.223';
var key = CryptoJS.enc.Utf8.parse(strMD5Passwd);
var iv = CryptoJS.enc.Utf8.parse(strRandomIV);
var strAesEncrypted = CryptoJS.AES.encrypt(strData, key,
{ iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding});
var strUserName = objLoginInfo.username;
var strUserNameLength = ZeroPadding.left(strUserName.length, 3);
var strDataPacket = strRandomIV + strUserNameLength + strAesEncrypted + strUserName;
//var url = '120.26.83.34';
//var url = '192.168.192.223';
var url = strData;
strDataPacket = url + "/" + Base64.encode(strDataPacket);
//strDataPacket = '192.168.1.210/'+objLoginInfo.username+','+objLoginInfo.password;
loginService.getToken(strDataPacket, function (response, status, headers, config) {
//缓存用户信息
var a=listToObject(response.user,'rows').rows;
var user=a[0];
sessionStorage.setItem('strUser',JSON.stringify(user));
//角色
var b=listToObject(response.role,'rows').rows;
var role=b[0];
sessionStorage.setItem('strRole',JSON.stringify(role));
cookieOperate.setCookie('ckdToken', headers('Authorization'));
cookieOperate.setCookie('userName', objLoginInfo.username);
if(role.index_page){
window.location.href='index.html#'+role.index_page;
}else{
window.location.href='index.html';
}
/*if (role.rid==1) {
window.location.href='index.html';
}else if (role.rid==2) {
window.location.href='index.html#/doctorFirst';
}else if (role.rid==3) {
window.location.href='index.html#/nursefirst';
}else{
window.location.href='index.html#/nutritionistFirst';
}*/
sessionStorage.setItem("strUserName",objLoginInfo.username);
//JSON.parse();
//window.location.href='index.html';
///zbdy-webapp_20150519/zbdy-webapp/app/login.html
},function(data){
alert('用户名密码错误,登录失败');
});
}
}])