mobileoa-common-modules
Version:
移动办公平台前端公共功能模块
110 lines (92 loc) • 3.3 kB
JavaScript
'use strict';
var angular = require('angular');
require('../modules');
require('../services/GestureScreenContext');
require('../../login/services/LoginService');
require('../services/GestureScreenPasswordService');
require('../services/GesturePasswordService');
require('../../login/LoginModal');
var module = angular.module('gesturepassword.controller');
module.controller('validateGestureScreenController', function(
GestureScreenContext, $scope, LinkerService,LoginService, GestureScreenPasswordService, $state, $toast,
$ionicPopup, GesturePasswordService, Timer, $rootScope, LoginModal) {
var height = window.screen.height,
width = window.screen.width,
gesturepassword = null;
$scope.count = 5;
$scope.isStateNo = false;
var screenContext = new GestureScreenContext(width, height, function(passwords) {
var validate = passwords.join('') === gesturepassword;
if (validate) {
GesturePasswordService.doComplete();
} else if (!validate && passwords.length > 0) {
$scope.$evalAsync(function() {
$scope.isStateNo = true;
});
$scope.count--;
if ($scope.count <= 0) {
$scope.count++;
$ionicPopup.confirm({
title: '提示',
content: '您已经连续5次输错手势,手势解锁已关闭,请重新登录。',
okText: '确定',
cancelType: 'button-cancel-display'
}).then(function(res) {
if (res) {
LinkerService.getCurrentUser().then(function(user) {
GestureScreenPasswordService.setPassword(user.userId, '');
LoginService.logout().then(function() {
$state.go('login');
});
});
}
});
}
}
return validate;
});
function getLoginUser() {
$scope.userId = LinkerService.currentUserId;
}
function getGesturePassword() {
var user = LinkerService.currentUser;
gesturepassword = GestureScreenPasswordService.getPassword(user.userId);
}
$scope.forgetPassword = function() {
var user = LinkerService.currentUser;
if (user) {
GestureScreenPasswordService.setPassword(user.userId, '');
LoginService.logout();
}
$state.go('login');
};
$scope.otherLogin = function() {
return LoginService.logout().then(function() {
return LoginModal.show();
});
};
getLoginUser();
getGesturePassword();
var layout = screenContext.layout;
$scope.topcontentStartY = layout.top.content.startY;
$scope.bottomContentStartY = layout.bottom.content.startY - 15;
$scope.screenContext = screenContext;
$scope.delayLoadGesturePassword = false;
Timer.delay(function() {
$scope.delayLoadGesturePassword = true;
}, 200);
var timerId;
$scope.$on('gesture.touchend', function() {
timerId = Timer.delay(function() {
$scope.isStateNo = false;
$scope.screenContext.startMove(0,0);
}, 1500);
});
$scope.$on('gesture.touchstart', function() {
$scope.isStateNo = false;
Timer.clear(timerId);
});
$scope.$on('$destroy', function() {
Timer.clear(timerId);
});
});