{"version":3,"names":[],"mappings":"","sources":["login/login-controller.js"],"sourcesContent":["(function() {\r\n 'use strict';\r\n\r\n /**\r\n * @ngdoc object\r\n * @name login.controller:LoginCtrl\r\n *\r\n * @description\r\n *\r\n */\r\n angular\r\n .module('login')\r\n .controller('LoginCtrl', LoginCtrl);\r\n\r\n function LoginCtrl($scope, $timeout, $location, $mdDialog, Login) {\r\n\r\n $scope.showLoginForm = true;\r\n $scope.showCodeForm = false;\r\n\r\n $scope.errorMessage = undefined;\r\n $scope.errorTitle = undefined;\r\n $scope.phoneError = false;\r\n\r\n $scope.sendCode = function() {\r\n\r\n $scope.errorMessage = undefined;\r\n $scope.errorTitle = undefined;\r\n $scope.phoneError = false;\r\n\r\n var cleanPhone = $scope.phone.replace(/\\D/g, '');\r\n if (cleanPhone.length != 10) {\r\n $scope.phoneError = true;\r\n $scope.errorTitle = undefined;\r\n $scope.errorMessage = \"מספר הטלפון לא תקין\";\r\n $mdDialog.show({\r\n templateUrl: 'login/errorMessage.html',\r\n scope: $scope,\r\n preserveScope: true\r\n });\r\n return;\r\n }\r\n\r\n showLoader();\r\n Login.createUserAndGetCode(cleanPhone).then(function(response) {\r\n hideLoader();\r\n if (response.data.success) {\r\n $scope.setItemInLocalStorage('codeSentDate', new Date());\r\n $scope.setItemInLocalStorage('phone', cleanPhone);\r\n $scope.goToCodeEnter();\r\n } else {\r\n // $scope.errorMessage = \"הודעה כבר נשלחה למספר זה, ניתן לשלוח שוב בעוד \"\r\n // $scope.errorMessage += response.data.timeRemaining;\r\n // $scope.errorMessage += \" דקות\";\r\n $scope.errorTitle = undefined;\r\n $scope.errorMessage = \"הודעה נשלחה למספר זה\";\r\n $mdDialog.show({\r\n templateUrl: 'login/errorMessage.html',\r\n scope: $scope,\r\n preserveScope: true\r\n });\r\n }\r\n })\r\n }\r\n\r\n\r\n $scope.verifyCode = function() {\r\n $scope.errorMessage = undefined;\r\n var cleanPhone = $scope.phone.replace(/\\D/g, '');\r\n Login.verifyLoginCode(cleanPhone, $scope.code).then(function(response) {\r\n if (response.data.success) {\r\n $scope.setItemInLocalStorage(\"loginToken\", response.data.token);\r\n $scope.setItemInLocalStorage('userDetails', response.data.user);\r\n $location.path(\"menu\");\r\n } else {\r\n $scope.code = \"\";\r\n $scope.errorTitle = \"סיסמא שגויה\"\r\n $scope.errorMessage = response.data.message;\r\n $mdDialog.show({\r\n templateUrl: 'login/errorMessage.html',\r\n scope: $scope,\r\n preserveScope: true\r\n });\r\n }\r\n })\r\n }\r\n\r\n $scope.goToCodeEnter = function() {\r\n $scope.showLoginForm = false;\r\n\r\n $timeout(function() {\r\n $scope.showCodeForm = true;\r\n }, 800);\r\n }\r\n\r\n $scope.backToPhoneEnter = function() {\r\n $scope.showCodeForm = false;\r\n $timeout(function() {\r\n $scope.showLoginForm = true;\r\n }, 1000);\r\n }\r\n\r\n $scope.checkIfCodeSent = function() {\r\n var codeExpirationMinutes = 60;\r\n var dateStr = $scope.getItemFromLocalStorage('codeSentDate');\r\n if (dateStr != undefined) {\r\n var date = new Date(dateStr);\r\n var now = new Date();\r\n var diffDays = Math.round((now - date) / 86400000); // days\r\n var diffHrs = Math.round(((now - date) % 86400000) / 3600000);\r\n var diffMinutes = Math.round((((now - date) % 86400000) % 3600000) / 60000);\r\n if (diffMinutes < codeExpirationMinutes && diffHrs == 0 && diffDays == 0) {\r\n $scope.phone = $scope.getItemFromLocalStorage('phone');\r\n $scope.goToCodeEnter();\r\n }\r\n }\r\n }\r\n\r\n $scope.hideDialog = function() {\r\n if ($scope.showCodeForm == false && !$scope.phoneError) {\r\n $scope.goToCodeEnter();\r\n }\r\n $mdDialog.hide();\r\n }\r\n\r\n\r\n $scope.checkIfCodeSent();\r\n }\r\n}());\r\n"],"file":"login-controller.js"}