fork download
  1. (function (angular) {
  2. 'use strict';
  3. angular.module('authApp', ['ngRoute'])
  4.  
  5. .controller('MainController', function ($scope, $http) {
  6.  
  7. $scope.param = function (obj) {
  8. var parts = [];
  9. for (var key in obj) {
  10. if (obj.hasOwnProperty(key)) {
  11. parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
  12. }
  13. }
  14. return parts.join('&');
  15. };
  16. })
  17. .controller('authController', function ($scope, $http, $q) {
  18.  
  19. $scope.form = {
  20. email : '',
  21. password: '',
  22. spinner: '',
  23. sendAuthForm: function(form){
  24.  
  25. var self = this;
  26. self.spinner = true;
  27. if (self.email != '' && self.password != ''){
  28. self.checkValidAuth(form);
  29.  
  30. }else{
  31. Materialize.toast('Заполните все поля!', 4000);
  32. self.spinner = false;
  33. }
  34. },
  35. checkAuthUser: function(email, password){
  36. //Делаем запрос на сервер для проверки валидности пары email, password
  37. var deferred = $q.defer();
  38. $http({
  39. method: 'post',
  40. data: $scope.param({
  41. email : email,
  42. password : password
  43. }),
  44. headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  45. url: '/index.php?route=checkout/login/checkFastAuth'
  46. }).
  47. success(function (response, status, headers, config) {
  48. deferred.resolve(response, status, headers, config);
  49. }).
  50. error(function (response, status, headers, config) {
  51. deferred.reject(response, status, headers, config);
  52. });
  53. return deferred.promise;
  54. },
  55. checkValidAuth: function(form){
  56.  
  57. var self = this;
  58.  
  59. var myPromise = self.checkAuthUser(self.email, self.password);
  60.  
  61. myPromise.then(function(resolve){
  62.  
  63. if (resolve.ans){
  64. location.reload();
  65. //или переход ко второму шагу
  66. }else{
  67.  
  68. if (resolve.email === '1'){
  69. //email есть
  70. Materialize.toast('Неверная пара email/пароль!', 4000);
  71. self.spinner = false;
  72. }else{
  73. //email нет
  74. Materialize.toast('Данного email не существует!', 4000);
  75. self.spinner = false;
  76. }
  77. }
  78. }, function(reject){
  79. Materialize.toast('Произошла ошибка, обовите страницу!', 4000);
  80. });
  81. }
  82. };
  83.  
  84. })
Runtime error #stdin #stdout #stderr 0.38s 323136KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: "prog.js", line 84: missing } after function body
js:         })
js: .........^
js: "prog.js", line 1: Compilation produced 1 syntax errors.