(function (angular, Controllers, app) { Controllers = Controllers || {}; Controllers.Login = Controllers.Login || {}; angular.extend(Controllers.Login, { Default: function ($scope, $http, noty, $location) { let host = $location.host(); $scope.url = host.split('.'); $scope.login = { type: 'login' }; $scope.submit = function () { $scope.login.email; $http.post("/rest/email.json", {email: $scope.login.email}).then(function () { noty.showSuccess("Wysłano link do zmiany hasła na podany adress E-mail"); $scope.email = ""; }, function (response) { if (response.status === 404) { noty.showError("Podany adres E-mail nie istnieje w bazie!"); } }); }; }, NewPassword: function ($scope, $http, noty, $location, $timeout) { $scope.submit = function () { if ($scope.sec_new_password !== $scope.new_password) { noty.showError("Hasła różnią się!"); return; } if (angular.isUndefined($scope.sec_new_password) && angular.isUndefined($scope.new_password)) { noty.showError("Pola są wymagane!"); return; } $scope.password = []; $http.post("/rest/password.json", $scope.password = { new_password: $scope.new_password, second_password: $scope.sec_new_password } ).then(function () { noty.showSuccess("Hasło zostało zmienione"); $scope.password = []; $timeout(function () { $location.path('/logowanie/'); location.reload(); }, 2000); }, function () { noty.showError("Sprawdź czy pola są wypełnione"); }); }; } }); app.controller('Controllers.Login.Default', Controllers.Login.Default); app.controller('Controllers.Login.NewPassword', Controllers.Login.NewPassword); })(angular, Controllers, app);