UNPKG

unserver-unify

Version:

422 lines (417 loc) 15.6 kB
'use strict'; angular.module('bamboo').controller('LoginPageCtrl', function($scope, $rootScope, $state, $timeout, deviceDetector, $translate, loginService, ApiService, CommonService, AppConfig, $uibModal, $filter, Lightbox, $window, pwdService, $localStorage, toastrHelper, siteConfigSvs) { $scope.agreeFlag = true; var _self = this; this.imageUrlPrefix = ApiService.SHOST + "/public/" + ApiService.RES + "/school/" + loginService.school._id + "/"; // console.log('-- login controller --'); _self.showMobileSid = false; //init the var to show/hide sidebar for mobile view //$scope.showMobileLogo = true; //console.info($rootScope.showMobileLogo); //toastrHelper.showToastrSuccess("Information",10000); var headerConfig = siteConfigSvs.getConfig().HeaderConfig || {}; var loginfooter = siteConfigSvs.getConfig().LoginFooter || {}; this.footerConfig = siteConfigSvs.getConfig().footerConfig || {}; _self.HIDE_APPLICATIONS = headerConfig.HIDE_APPLICATIONS; _self.COM_RIGHT = loginfooter.companyRights || "Bamboosys System Technology 2017"; // console.log(_self.HIDE_APPLICATIONS); // console.log(_self.COM_RIGHT); _self.toggleSideBar = function() { _self.showMobileSid = !_self.showMobileSid; } $scope.doTheBack = function() { window.history.back(); }; this.appUrl = ApiService.APPURL; this.loginService = loginService; this.searchCompany = function(q) { $state.go('index.searchcompany', { key: q }); } if ($state.current.name.indexOf('index.mobile.login') == 0 && loginService.subDomain == 'caregiverasia') { console.log('Care Giver Asia Login '); var URL = '//api.sgedushare.com/ui/57da553bfc58753752883bad/oauth/caregiveasia'; $window.location.href = URL; return; } this.googleLoginURL=ApiService.getFullUrl('/oauth/google/'+loginService.school.key); this.linkedInLoginURL = ApiService.getFullUrl('/oauth/linkedin/'+loginService.school.key); // this.linkedInGSXLoginURL = ApiService.getFullUrl('/oauth/linkedingsx'); this.facebookLoginURL=ApiService.getFullUrl('/oauth/facebook/'+loginService.school.key); this.twitterLoginURL=ApiService.getFullUrl('/oauth/twitter/'+ loginService.school.key); this.caregiveLoginURL = ApiService.getFullUrl('/oauth/caregiveasia'); this.wsfedUrl = ApiService.getFullUrl('/oauth/wsfed'); this.registeUrl = "index.setting.signup"; this.CURR_YEAR = new Date().getFullYear(); var resetPwdOpts = { size: "md-lg vertical-align-center", animation: true, backdrop: 'static', component: 'resetPwdComponent', keyboard: false, resolve: { reason: function() { return _self.changePwdReason; } } } // $uibModal.open(resetPwdOpts); this.requestTempPassword = function() { console.log(_self.tempIC); console.log(_self.birthday); var info = { ic: _self.tempIC, birth: _self.birthday, ownername: loginService.school.name, }; ApiService.post('/request_pass', info).then(function(result) { //console.log(result); if (result.data.success) { CommonService.showNoBlockInfo(result.data.info); } else { CommonService.showError(result.data.error || result.data.info); } }); } function initRegisteUrl() { if (!$rootScope.currentSchool) { console.log("return 2"); return; } if ($rootScope.currentSchool.translationStyle == 'poiz') { _self.registeUrl = "index.setting.presignupshop"; } else if ($rootScope.currentSchool.translationStyle == 'gsx') { _self.registeUrl = "index.setting.presignupschool"; } else if ($rootScope.currentSchool.homepage == 'stec') { _self.registeUrl = "index.setting.signup"; } else if ($rootScope.currentSchool.jobFlag) { _self.registeUrl = "index.setting.presignup"; } else { _self.registeUrl = "index.setting.signup"; } console.info(_self.registeUrl); console.info($rootScope.currentSchool.translationStyle); } initRegisteUrl(); $scope.login = { domain: loginService.subDomain, userType: 'student' }; this.unreadmsgs = 0; if (loginService.user) { if (loginService.user.parentFlag) { console.log('--- parent Login --'); $window.location.href = ApiService.PARENTURL + "/mystudy/activitySummary"; } var info = { action: 'getmyunreadmsgcounter', } ApiService.post('/user', info).then(function(result) { // console.log(result); if (result.data.success && result.data.data) { _self.unreadmsgs = result.data.data.messages; _self.tasks = result.data.data.tasks; } }) } console.log(loginService.school); if (loginService.school) { // console.log(this.imageUrlPrefix); // console.log(loginService.school); $scope.customStyle = { "background-color": loginService.school.footercolor }; if (loginService.school.themecolors) { $scope.coursebtmStyle = { "background-color": loginService.school.themecolors.coursewidgetbtmcolor }; $scope.colorStyle = loginService.school.themecolors.theme3headercolor; } if (ApiService.DID && ApiService.department.icon) { this.department = ApiService.department; this.logoUrl = this.imageUrlPrefix + ApiService.department.icon; } else if (loginService.school.icon) { this.logoUrl = this.imageUrlPrefix + loginService.school.icon; // console.log(this.logoUrl); } else { this.logoUrl = "//s3-ap-southeast-1.amazonaws.com/edushare/public/resg/school/54321ef40f6006a95112893f/Logo.png"; } this.companyName = loginService.school.name; if ($rootScope.currentLanguage == "Chinese") { this.companyDescription = loginService.school.descriptionCN || loginService.school.description; } else { this.companyDescription = loginService.school.description || loginService.school.descriptionCN; } this.descriptionCN = loginService.school.descriptionCN; $scope.school = loginService.school; if (loginService.school.links) { var links = []; angular.forEach(loginService.school.links, function(link) { if (link.enable) { links.push(link) } }) $scope.links = links; } // console.log($scope.school); // console.debug("schoole info:", loginService.school); } else { this.logoUrl = 'assets/images/bamboo_logo.png'; this.companyName = 'Bamboosys System Technology'; this.companyDescription = ''; } //console.log(_self.logoUrl); if (deviceDetector.isMobile() && !deviceDetector.isTablet()) { $timeout(function() { //if(loginService.user){ $rootScope.showMobileLogo = true // }else{ // $rootScope.showMobileLogo = false // }; }, 100); console.info($state.current.name); if ($state.current.name.indexOf("index.home") < 0) { console.info("---!!!----"); $timeout(function() { $rootScope.showMobileLogo = false; }, 100); } $scope.$on('$destroy', function() { $rootScope.showMobileLogo = false; }); } $scope.selectForum = function() { $state.go('index.forums'); }; $scope.needLoginButton = function() { return ApiService.getSchoolInfo(loginService.subDomain).then(function(school) { _self.school = school; $rootScope.currentSchool = school; $rootScope.initLang(); loginService.school = school; }, function(err) { console.log(" School Service Retry counter : " + $rootScope.apiRetry); if (!$rootScope.apiRetry) { $rootScope.apiRetry = 1; $state.go('index.home'); } else if ($rootScope.apiRetry < 4) { $rootScope.apiRetry++; $state.go('index.home'); } else { $state.go('errstate'); } }); }; $rootScope.showCourseLoginDialog = this.showCourseLoginDialog = function() { if (loginService.user) { CommonService.showInfo($filter('trans')({ eng: 'If you want to start this course, Please enroll first!', chn: '如果需要开始课程学习,请首先报名!' })); } else { _self.openLoginDialog(); } } this.openLoginDialog = $scope.openLoginDialog = function() { if (loginService.subDomain == "caregiverasia") { var URL = '//api.sgedushare.com/ui/57da553bfc58753752883bad/oauth/caregiveasia'; $window.location.href = URL; return; } var options = { templateUrl: 'app/login/login.dlg.html', controller: 'LoginDlgCtrl', controllerAs: 'ctrl', size: "md-lg vertical-align-center", backdrop: 'static' } if (loginService.school.loginTheme) { switch (loginService.school.loginTheme) { case 't1': options.templateUrl = "app/login/login.dlg1.html"; break; case 't2': options.templateUrl = "app/login/login.dlg2.html"; break; } } $uibModal.open(options).result.then(function(login) { console.log(login); if (!login) {} else if (login.forgotPassword) { $state.go('index.request-reset-pwd'); } else if (login.showagreement) { $timeout(function() { $state.go('index.agreement'); }, 500) } else if (login.enviroment) { $timeout(function() { $state.go('index.enviroment'); }, 500) } else { $scope.login = login; $scope.loginMe(); } }); }; $scope.loginSubmit = function() { $scope.submitted = true; //$scope.shaking = true; if ($scope.form.$invalid) { $scope.shaking = true; $timeout(function() { $scope.shaking = false; }, 500); return; } $scope.loginMe(); } $scope.clearErrorMsg = function() { $scope.LOGINERROR = false; $rootScope.MOBILE_LOGIN_ERROR = undefined; } $scope.loginMe = function() { // setup promise, and 'working' flag // console.log(loginService) $scope.login.domain = loginService.subDomain; $scope.login.ownername = loginService.school.name; $scope.login.url = ApiService.HOST + "#/active_account"; loginService.login($scope.login).then(function(user) { console.info(user); console.log(loginService.school.welcomedoc); if (!user) { $scope.LOGINERROR = true; //CommonService.showError($translate.instant(AppConfig.LOGINERROR)); } else { var now = new Date(); var expireDate = new Date(loginService.school.expire); var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds var diffDays = Math.round(Math.abs((expireDate.getTime() - now.getTime()) / (oneDay))); if (diffDays <= 14 && user.role == "admin") CommonService.showNoBlockErr('Your account will expire after ' + diffDays + ' days !'); // console.log(user); //$rootScope.userType = $scope.login.userType; $localStorage.USER_TYPE = $scope.login.userType; console.log($localStorage.USER_TYPE); console.info($state.current.name); console.info(loginService.school.defaultPageAfterLogin); console.info(user); /* if ($state.current.name == 'index.reset-pwd') { $state.go('index.home'); } */ if (deviceDetector.isMobile() && !deviceDetector.isTablet()) { $state.go('index.home', {}, { reload: true }); } else if ($state.current.name == '403' || $state.current.name == 'index.reset-pwd') { $state.go('index.home'); } else if (loginService.school.defaultPageAfterLogin) { console.log(loginService.school.defaultPageAfterLogin); switch (loginService.school.defaultPageAfterLogin) { case 'myspace': $state.go('index.myspace.activitySummary'); break; case 'myexam': $state.go('index.myspace.exams'); break; case 'mycourse': $state.go('index.myspace.mycourses'); break; case 'home': $state.go('index.home'); break; default: $state.reload(); break; } } else { $state.reload(); } //------------------------high proprity------------------------------------------ if (user && ( user.loginCounter < 2 || !user.loginCounter)) { _self.changePwdReason = $translate.instant('ChangePwdReason1'); $uibModal.open(resetPwdOpts); $localStorage.FORCE_RESET_PWD = true; $localStorage.FORCE_RESET_PWD_REASON = _self.changePwdReason; } else if (user && user.passNeedToUpdate) { _self.changePwdReason = $translate.instant('ChangePwdReason2'); $uibModal.open(resetPwdOpts); $localStorage.FORCE_RESET_PWD = true; $localStorage.FORCE_RESET_PWD_REASON = _self.changePwdReason; //console.info(pwdService.FORCE_RESET_PWD); } } }, function(reason) { console.log(reason); // if (reason.data.errorcode && reason.data.errorcode == 1001) { // CommonService.showError($filter('trans')({ // eng: 'The account is not actived, please check email ' + reason.data.email, // chn: '账户还未激活,请检查邮箱 ' + reason.data.email // })); // } // CommonService.showError(reason); // console.log(reason); CommonService.showError(reason.data.error); }); }; this.logoutMe = $scope.logoutMe = function() { console.log("logoutMe"); loginService.logout(); }; $scope.requestPasswordReset = function(email) { var info = { email: email, url: ApiService.HOST + "#/reset-pwd", ownername: loginService.school.name, }; ApiService.post('/search_pass', info).then(function(result) { //console.log(result); if (result.data.success) { CommonService.showNoBlockInfo(result.data.info); } else { CommonService.showError(result.data.error || result.data.info); } }); }; this.showbarcode = function() { Lightbox.openModal([{ url: "assets/images/qrcode.jpeg", }], 0); } $rootScope.shareSiteInfos = { info: { site: window.location.protocol + "//" + window.location.host, title: $rootScope.currentSchool ? $rootScope.infotoshare || $rootScope.currentSchool.description : '' }, socials: [{ name: "facebook", title: "Facebook" }, { name: "twitter", title: "Twitter" }, { name: "google_plusone_share", title: "Google+", icon: "google-plus" }, { name: "sinaweibo", title: "Sina Weibo", icon: "weibo" }, { name: "email", title: "Email", icon: "envelope" }, { name: "addthis", title: "Addthis", icon: "plus", addThis: true }] }; if ($state.current.name.indexOf('index.sglogin') == 0 && loginService.user) { $state.go('index.home'); console.log("return 1"); return; } }); function selectForum() { $state.go('index.newses'); }