| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- define([ 'toaster', 'services' ], function() {
- 'use strict';
- var app = angular.module('myApp', [ 'toaster', 'common.services' ]);
- app.init = function() {
- angular.bootstrap(document, [ 'myApp' ]);
- };
- app.controller('AuthCtrl', ['$scope', '$window', '$location', 'toaster', 'AuthenticationService','BaseService','SessionService',function($scope, $window, $location, toaster, AuthenticationService,BaseService,SessionService) {
- $scope.loading = false;
- $scope.user = {
- j_username : SessionService.getCookie('PDA_USERNAME'),
- j_password : "",
- remember_me : true,
- master:""
- };
- AuthenticationService.getMasters().success(function(responseText,status){//获取选择帐套
- if(responseText.masters){
- $scope.masters = responseText.masters;
- $scope.user.master = $scope.masters[0].ma_name;
- }
- });
-
- $scope.login = function(user, _url) {
- if($scope.user.j_username == '' ||$scope.user.j_password == ''){
- alert("还有必填项没有填写!");
- return ;
- }else{
- $scope.loading = true;
- AuthenticationService.login(user).success(function(responseText, status) {
- if(responseText) {
- $scope.loading = false;
- toaster.pop('error', '登录失败', responseText);
- }else if(status == 200){
- if(user.remember_me)
- SessionService.setCookie('PDA_USERNAME', user.j_username);
- else
- SessionService.removeCookie('PDA_USERNAME');
- var rootPath= BaseService.getRootPath();
- $window.location.href = rootPath+'/jsps/PDAmobile/index.html'
- }
- }).error(function(responseText) {
- $scope.loading = false;
- toaster.pop('error', '登录失败', responseText || '用户名或密码错误');
- });
- }
- };
-
- $scope.enter = function(event){
- if(event.keyCode == 13)
- document.getElementById("j_password").focus();
- }
- var decodeUrl = function(url) {
- url = unescape(url.replace(/\$2F/g, '%2F').replace(/@/g, '#'));
- if(url.indexOf('http:') == -1 && url.indexOf('https:') == -1) {
- url = AuthenticationService.root() + '/' + url;
- }
- return url;
- };
- var loginAndRedirect = function() {
- var path = $location.path();
- if(path) {
- var params = path.split('/'), _params = [];
- angular.forEach(params, function(param){
- param && _params.push(param);
- });
- if(_params.length == 4 && _params[0] == 'redirect') {
- $scope.login({
- j_username: _params[1],
- j_password: _params[2]
- }, decodeUrl(_params[3]));
- }
- }
- };
- loginAndRedirect();
- }]);
- return app;
- });
|