Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. function onLogin(e, args) {
  2. DebugMode && console.info('[INFO]', 'Login requested on ' + new Date());
  3.  
  4. var cred;
  5. var data;
  6.  
  7. try {
  8. cred = args.credentials;
  9. data = data_login;
  10. } catch (ex) {
  11. log('warn', 'Cannot get credentials to access.');
  12. _toastr.warning(ex.message, ' ', 'Contate o suporte e informe a mensagem exibida.');
  13. $state.go('login');
  14. }
  15.  
  16. // Sanitize login credentials.
  17. cred.username = $sanitize(cred.username);
  18. cred.password = $sanitize(cred.password);
  19.  
  20. data.username = cred.username;
  21. data.password = cred.password;
  22.  
  23. LoginService.doLogin(cred/*data*/).then(
  24. /* Success */
  25. function (result) {
  26. scope.errorLogin = false;
  27. rootScope.hideMenu = false;
  28. rootScope.loading = false;
  29. rootScope.$emit('operatorIsLogged', null);
  30. rootScope.$broadcast('operatorIsLogged', null);
  31. rootScope.$broadcast('getOperatorLogged', null);
  32. rootScope.module_permissions = PermissionsService.check_modules_permissions();
  33. _toastr.success(t("Login efetuado com sucesso!"), 'Login');
  34. dao.getList("instance", null).then(function (res) {
  35. rootScope.instances = res.data.data;
  36. _storage.session.set('instances', rootScope.instances);
  37. }, function (err) {
  38. _toastr.error("Não foi possível recuperar a lista de Instâncias, saindo do sistema.", "Solicitando o Logout!");
  39. rootScope.instances = null;
  40. rootScope.$emit('doLogout');
  41. });
  42. $state.go('master.modules');//$state.go('stcpcfg');
  43. /* $rootScope.current_module = JSON.parse(StorageService.session.get("current_module")); */
  44. }, /* Error */
  45. function (reason) {
  46. scope.errorLogin = true;
  47. rootScope.hideMenu = true;
  48. rootScope.loading = false;
  49. }
  50. );
  51. }
  52.  
  53. it('testing if the onLogin function', function(){
  54. var data, cred;
  55. data = {
  56. username: {
  57. cred: {
  58. username: 'username'
  59. }
  60. },
  61. password: {
  62. cred: {
  63. password: '****'
  64. }
  65. }
  66.  
  67. };
  68.  
  69. srv.onLogin();
  70. rootScope.$emit('doLogin', srv.onLogin);
  71.  
  72. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement