angular.module('push') .controller('LoginCtrl', function ($scope, LoginService, UtilService, UserService, homepageOfNodeService, ConfigService, $ionicHistory, $timeout, SqliteStorageService, $ionicPopup, CommonService, $state, ResourceLibraryService, ConstantService) { if ($scope.app) { $scope.setStatusBar(0); } $scope.defaultLan = UserService.defaultLan; $scope.loginLogo = 'img/push_login.png'; if ($scope.isLiyangApp) { $scope.loginLogo = 'img/liyang_login.jpg'; } $scope.user = { name: '', password: '' }; //登录 $scope.login = function () { var loginName = $scope.user.name; var loginPassWord = $scope.user.password; if (!loginName || !loginPassWord) { if ($scope.app) { UtilService.showMess('手机号与密码是必填项!'); } else { $ionicPopup.alert({ title: '提示', template: "
手机号与密码是必填项!
", buttons: [{ text: "确定" }] }); //CommonService.showMessage('手机号与密码是必填项!', $scope); } return; } $scope.showLoadingToast(); LoginService.login(loginName, loginPassWord).then(function (response) { $scope.hideLoadingToast(); console.log(response); if (response.code == ConstantService.STATUS_TYPE_21002) { //未注册 if ($scope.app) { UtilService.showMess(response.message); } else { if ($scope.defaultLan == 'Chinese') { $ionicPopup.alert({ title: '提示', template: "" + response.message + "
", buttons: [{ text: "确定" }] }); } else { $ionicPopup.alert({ title: 'notice', template: "User not registered
", buttons: [{ text: "OK" }] }); } //CommonService.showMessage(response.message, $scope); } } else if (response.code == ConstantService.STATUS_TYPE_21004) { //用户名或密码错误! if ($scope.app) { UtilService.showMess(response.message); } else { if ($scope.defaultLan == 'Chinese') { $ionicPopup.alert({ title: '提示', template: "" + response.message + "
", buttons: [{ text: "确定" }] }); } else { $ionicPopup.alert({ title: 'notice', template: "Incorrect username or password
", buttons: [{ text: "OK" }] }); } // CommonService.showMessage(response.message, $scope); } } else if (response.code == 21008) { //登录超出限制 if ($scope.app) { UtilService.showMess(response.message); } else { if ($scope.defaultLan == 'Chinese') { $ionicPopup.alert({ title: '提示', template: "" + response.message + "
", buttons: [{ text: "确定" }] }); } else { $ionicPopup.alert({ title: 'notice', template: "Incorrect username or password
", buttons: [{ text: "OK" }] }); } // CommonService.showMessage(response.message, $scope); } } else if (response.code == 3351) { if ($scope.defaultLan == 'Chinese') { $ionicPopup.alert({ title: '提示', template: '用户未注册!' }); return; } else { $ionicPopup.alert({ title: 'notice', template: 'User not registered!' }); return; } } else if (response.code == ConstantService.STATUS_TYPE_21005) { //该用户名已被禁用 if ($scope.app) { UtilService.showMess(response.message); } else { $ionicPopup.alert({ title: '提示', template: "" + response.message + "
", buttons: [{ text: "确定" }] }); //CommonService.showMessage(response.message, $scope); } } else if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) { if ($scope.app) { UtilService.showMess(ConstantService.MESSAGE_TYPE_21000); } // } else { // CommonService.showMessage(ConstantService.MESSAGE_TYPE_21000, $scope); // } ConfigService.islogin = true; //$scope.selCom.hide(); // $timeout(function () { // $state.reload(); // },30); //存储用户信息--自动登录 var tempdate = UtilService.formatDate(); sessionStorage.id = response.data.userId; sessionStorage.mobile = $scope.user.name; // sessionStorage.password= $scope.user.password; sessionStorage.updatetime = tempdate.formattime2; sessionStorage.type = 1; //保存用户信息 UserService.user = response.data; UserService.id = response.data.userid; //UserService.node = response.data.comefrom; if (UtilService.isDefined(response.data.node.nodename)) { //UserService.nodename = response.data.node.nodename; } UserService.role = response.data.userRoleList;//角色 // if($scope.app){ // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // } $scope.getUserIMInfo(); // UserService.viplevel = response.member.memberid; // ConfigService.mychannellist = response.channelList; //ConfigService.comefrom = response.data.comefrom; // $ionicHistory.clearCache(); // $scope.go("tab.activityIndex"); // $scope.go("tab.account"); // console.log($location.path().split('/').slice(1).join('.')); // $scope.go($location.path().split('/').slice(1).join('.')) /*console.log($scope.user);*/ localStorage.setItem("uid", response.data.userid); //用户手机号作为用户的唯一的表示,用作全局变量 localStorage.setItem("mobile", $scope.user.name); //存储密码用作自动登录 localStorage.setItem("password", $scope.user.password); //保存用户信息 UserService.user = response; ResourceLibraryService.postResetUserNode(localStorage.node).then(function (response) { console.log(response); }) homepageOfNodeService.getNodeAuth(UserService.node).then(function (res) { $scope.isUserManager = res.data; console.log($scope.isUserManager) }) $timeout(function () { // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) $state.reload(); }, 300); // $scope.goback(); $state.go('tab.account'); } }, function () { $scope.hideLoadingToast(); // if($scope.app){ // UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR); // }else{ // CommonService.showMessage(ConstantService.INTERFACE_MESSAGE_ERROR,$scope); // } }); }; //微信第三方登录 $scope.wechatLogin = function () { $scope.showLoadingToast(); //请求用户授权 var scope = "snsapi_userinfo", state = "_" + (+new Date()); Wechat.auth(scope, state, function (response) { if ($scope.app) { UtilService.showMess("授权成功"); } else { CommonService.showMessage("授权成功", $scope); } // console.log(response); LoginService.getAccessToken(response.code).then(function (res) { // console.log(res); // access_token: "16_pKE6r3tWT-Yq9Vjrlop7rXmVjMgXnv87W0UZammN_9yiGaDvMDj4TN5CuDMNYx4UAu7hbfiOLuCTgTFAEsSWV5_BtMJTQjjIdwTTtUk7fvY" // expires_in: 7200 // openid: "oAmnd54xuec4OsNmIBLkqKHZgQ2M" // refresh_token: "16_Fc7btUDkiqNK8KGz3FZ9Zd5CkOtaGEiQEBzmFgmrq2ECsd-pRMBIJmpB0IYSTmQ3NBFh6So7vS9wY2dzQ09joaymZ3hHJdM8RxsJRlUiJew" // scope: "snsapi_userinfo" // unionid: "olQ930mg5NDUB2ZLN9k7N2DVoZMA" wechatReqLogin(res); }, function () { $scope.hideLoadingToast(); }); }, function (error) { // console.log(error); $scope.hideLoadingToast(); }); $timeout(function () { $scope.hideLoadingToast(); }, 3000); }; // $scope.login = function () { // $scope.showLoadingToast(); // // console.log("scope.user.name = " + scope.user.name); // // console.log("scope.user.password = " + scope.user.password); // // console.log("user.loginname = " + user.loginname); // // console.log("user.password = " + user.password); // /*if($scope.user.name == null && $scope.user.password == null){ // $scope.user.name = user.loginname; // $scope.user.password = user.password; // }*/ // LoginService.login($scope.user.loginname, $scope.user.password).then(function (response) { // $scope.hideLoadingToast(); // if (response.dataType == "-2") { // //未注册 // if($scope.app){ // UtilService.showMess("未注册"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'未注册' // }) // } // } else if (response.dataType == "0") { // //用户名或密码错误! // if($scope.app){ // UtilService.showMess("手机号或密码错误"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'手机号或密码错误' // }) // } // // } else if (response.dataType == "2") { // //该用户名已被禁用 // if($scope.app){ // UtilService.showMess("用户名已被禁用"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'用户名已被禁用' // }) // } // // } else { // if($scope.app){ // //UtilService.showMess("登录成功"); // }else{ // $ionicPopup.alert({ // title:'提示', // //template:'登录成功' // }) // } // if($scope.app){ // //UtilService.showMess("登录成功"); // }else{ // //CommonService.showMessage("登录成功",$scope); // } // ConfigService.islogin = true; // //存储用户信息--自动登录 // var tempdate = UtilService.formatDate(); // var del_sql = "delete from userinfo"; // if($scope.app){ // SqliteStorageService.deleteData(del_sql); // SqliteStorageService.insertSingleData("userinfo", { // id: response.user.userId, // mobile: $scope.user.name, // password: $scope.user.password, // updatetime: tempdate.formattime2, // type: 1 // }); // }else{ // sessionStorage.id=response.user.userId; // sessionStorage.mobile=response.user.name; // sessionStorage.password=response.user.password; // sessionStorage.updatetime=response.user.formattime2; // sessionStorage.type=1; // } // // //保存用户信息 // UserService.user = response; // UserService.id = response.user.userId; // UserService.role = response.rolelist; // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // UserService.viplevel = response.member.memberid; // ConfigService.mychannellist = response.channelList; // ConfigService.comefrom = response.user.comefrom; // $ionicHistory.clearCache(); // // $scope.go("tab.activityIndex"); // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) // $state.reload(); // } // }, function () { // $scope.hideLoadingToast(); // UtilService.showMess("网络不给力,请重试"); // }); // }; $scope.showPrivacyPolicy = function () { $scope.go('privacyPolicy'); } // //微信第三方登录 // $scope.wechatLogin = function () { // $scope.showLoadingToast(); // //请求用户授权 // var scope = "snsapi_userinfo", // state = "_" + (+new Date()); // Wechat.auth(scope, state, function (response) { // if($scope.app){ // UtilService.showMess("授权成功"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'授权成功' // }) // } // // // console.log(response); // LoginService.getAccessToken(response.code).then(function (res) { // // console.log(res); // wechatReqLogin(res); // }, function () { // $scope.hideLoadingToast(); // }); // }, function (error) { // // console.log(error); // $scope.hideLoadingToast(); // }); // $timeout(function () { // $scope.hideLoadingToast(); // }, 5000); // }; //公用第三方登录返回处理 var thirdCommonLogin = function (response, type, temptoken) { var tempwechat = {}; if (type == 2) { tempwechat = angular.fromJson(response.weChat); } else { tempwechat = response.qq; } if (angular.isDefined(response.gsonInfo)) { var tempuser = angular.fromJson(response.gsonInfo); if (tempuser.dataType == "21005") { //该用户名已被禁用 if ($scope.app) { UtilService.showMess("用户名已被禁用"); } else { CommonService.showMessage("用户名已被禁用", $scope); } } else if (tempuser.dataType == "21006") { $scope.go('bindPhone', { tokeninfo: angular.toJson(temptoken), type: type }); } else { if ($scope.app) { UtilService.showMess("登录成功"); } else { CommonService.showMessage("登录成功", $scope); } //用户手机号作为用户的唯一的表示,用作全局变量 localStorage.setItem("mobile", tempuser.user.mobile); //存储密码用作自动登录 localStorage.setItem("password", tempuser.user.password); //保存用户的userid localStorage.setItem("userId", tempuser.user.userid); //保存用户信息 UserService.user = tempuser.user; UserService.id = localStorage.getItem("userId"); ConfigService.islogin = true; // 关闭登录框 //$scope.selCom.hide(); $scope.getUserInfo();//获取用户信息 $state.reload(); //存储用户信息--自动登录 /*var tempdate = UtilService.formatDate(); SqliteStorageService.deleteData("delete from userinfo"); var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : ""; var tempobj = { id: tempuser.user.userid, mobile: "", password: "", updatetime: tempdate.formattime2, access_token: tempwechat.access_token, refresh_token: refresh, openid: tempwechat.openid, type: type }; SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) { }, function (err) { });*/ ConfigService.isedit = 1; //保存用户信息 UserService.user = tempuser.user; UserService.id = tempuser.user.userid; //UserService.node = tempuser.user.comefrom; if (UtilService.isDefined(tempuser.user.node.nodename)) { //UserService.nodename = tempuser.user.node.nodename; } UserService.role = tempuser.user.userRoleList; $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // UserService.viplevel = tempuser.member.memberid; // ConfigService.mychannellist = tempuser.channelList; ConfigService.comefrom = tempuser.user.comefrom; // $scope.go("tab.activityIndex"); $timeout(function () { $state.reload(); }, 300); $scope.goback(); } } else { if (type == 2) { $scope.wechatLogin(); } else { // if($scope.app){ // UtilService.showMess("网络不给力,请重试"); // }else{ // CommonService.showMessage("网络不给力,请重试",$scope); // } } } $scope.hideLoadingToast(); }; //微信请求后台登录 var wechatReqLogin = function (res) { LoginService.wxLogin(res, "", "").then(function (response) { thirdCommonLogin(response.data, 2, res); }, function () { $scope.hideLoadingToast(); }); }; // var thirdCommonLogin = function (response, type, temptoken) { // var tempwechat = {}; // if (type == 2) { // tempwechat = angular.fromJson(response.weChat); // } else { // tempwechat = response.qq; // } // if (angular.isDefined(response.gsonInfo)) { // var tempuser = angular.fromJson(response.gsonInfo); // if (tempuser.dataType == "2") { // //该用户名已被禁用 // if($scope.app){ // UtilService.showMess("用户名已被禁用"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'用户名已被禁用' // }) // } // // } else if (tempuser.dataType == "-2") { // $scope.go('bindPhone', {tokeninfo: angular.toJson(temptoken), type: type}); // } else { // if($scope.app){ // UtilService.showMess("登录成功"); // }else{ // $ionicPopup.alert({ // title:'提示', // template:'登录成功' // }) // } // // ConfigService.islogin = true; // //存储用户信息--自动登录 // var tempdate = UtilService.formatDate(); // SqliteStorageService.deleteData("delete from userinfo"); // var refresh = angular.isDefined(tempwechat.refresh_token) ? tempwechat.refresh_token : ""; // var tempobj = { // id: tempuser.user.userId, // mobile: "", // password: "", // updatetime: tempdate.formattime2, // access_token: tempwechat.access_token, // refresh_token: refresh, // openid: tempwechat.openid, // type: type // }; // SqliteStorageService.insertSingleData("userinfo", tempobj).then(function (suc) { // }, function (err) { // }); // ConfigService.isedit = 1; // //保存用户信息 // UserService.user = tempuser; // UserService.id = tempuser.user.userId; // UserService.role = tempuser.rolelist; // $scope.getUserIMInfo();//获取用户cliendif、订阅主题信息 // UserService.viplevel = tempuser.member.memberid; // ConfigService.mychannellist = tempuser.channelList; // ConfigService.comefrom = tempuser.user.comefrom; // $ionicHistory.clearCache(); // // $scope.go("tab.activityIndex"); // // $state.go($location.path().split('/').slice(1).join('.'),{},{reload:true}) // $state.reload(); // } // } else { // if (type == 2) { // $scope.wechatLogin(); // } else { // UtilService.showMess("网络不给力,请重试"); // } // } // $scope.hideLoadingToast(); // }; // // //微信请求后台登录 // var wechatReqLogin = function (res) { // LoginService.wxLogin(res, "", "").then(function (response) { // thirdCommonLogin(response, 2, res); // }, function () { // $scope.hideLoadingToast(); // }); // }; $scope.qqLogin = function () { $scope.showLoadingToast(); var args = {}; args.client = QQSDK.ClientType.QQ;//QQSDK.ClientType.QQ,QQSDK.ClientType.TIM; QQSDK.ssoLogin(function (result) { // console.log(result); LoginService.QQLogin(result, "", "").then(function (response) { thirdCommonLogin(response, 3, result); }, function () { $scope.hideLoadingToast(); }) }, function (failReason) { UtilService.showMess("授权失败"); $scope.hideLoadingToast(); }, args); }; $scope.showPassword = function () { /*$scope.show_psd = !$scope.show_psd*/ $scope.show_psd = false; }; //关闭启动动画 $timeout(function () { if (navigator.splashscreen) { navigator.splashscreen.hide(); } }, 1000); //$scope.loginModelPublic(); // $scope.hideModel=function () { // $scope.selCom.hide(); // } });