(function () { 'use strict'; var controllerId = 'signin'; angular.module('app').controller(controllerId, ['common', 'config', '$modal', '$sce', '$location', 'datacontext', 'validation', 'branding', 'fullScreenLoaderContext', signin]); function signin(common, config, $modal, $sce, $location, datacontext, validation, branding, fsl) { var vm = this; activate(); function activate($scope) { var getLogFn = common.logger.getLogFn; var log = getLogFn(controllerId); var logSuccess = getLogFn(controllerId, "success"); var logError = getLogFn(controllerId, "error"); vm.branding = branding; vm.isSignInError = false; vm.myuseraction = $sce.trustAsResourceUrl(config.realm + 'Token'); vm.applicationId = config.applicationId; vm.loginUrl = $sce.trustAsResourceUrl(config.realm + 'Account/Login'); vm.redirectUrl = config.sysUrl; vm.notAuthorised = config.notAuthorised; vm.username = ""; vm.password = ""; vm.signinFailed = false; vm.usernameDoesNotExist = false; vm.state = ""; vm.forgetPasswordMessage = ""; vm.newPasswordModel = { applicationId: config.applicationId, email: "" }; vm.brandorganisationId = ""; vm.validation = validation.userValidationConfig(); vm.isForgottenPasswordCollapsed = true; vm.registerUrl = config.registerUrl; vm.individualRegisterUrl = config.individualRegisterUrl; vm.individual = $location.search().individual; NProgress.done(); if ($location.$$path === "/signin/failed") { fsl.hide(); vm.isSignInError = true; } vm.isUserLockedOut = config.isLockedOut; vm.generateRegistrationOptions = function () { getRegistrationOptions(vm); }; function getRegistrationOptions(vm) { vm.modelinstance = $modal.open({ templateUrl: 'app/signin/options.html', size: 'sm', backdrop: 'static', controller: optionsController, resolve: { registerUrl: function () { return vm.registerUrl; }, individualRegisterUrl: function () { return vm.individualRegisterUrl; } } }); } var optionsController = function (registerUrl, individualRegisterUrl, $modalInstance) { vm.registerUrl = registerUrl; vm.individualRegisterUrl = individualRegisterUrl; vm.individual = $location.search().individual; vm.cancelModel = function () { vm.modelinstance.dismiss('cancel'); } } vm.cancelModel = function () { vm.modelinstance.dismiss('cancel'); } //send user a new password vm.sendNewPassword = function () { vm.newPasswordModel.applicationId = config.applicationId; vm.newPasswordModel.sysUrl = config.sysUrl; if (vm.newPasswordModel.email) { var email = encodeURIComponent(vm.newPasswordModel.email); //first test if the username entered by the user actually exists, if not tell them datacontext.isEmailAvailable(email).then(function (data) { if (data) { //username exists vm.usernameDoesNotExist = false; //Decode the email back again vm.newPasswordModel.email = decodeURIComponent(vm.newPasswordModel.email); vm.newPasswordModel.sysUrl = config.sysUrl; //send the new password and tell the user datacontext.forgotPassword(vm.newPasswordModel, config.appCode).then(function (data) { if (data == 'Email is not verified') { vm.forgetPasswordMessage = "That email address is yet to be verified."; } else { vm.forgetPasswordMessage = "A message containing a link to reset your password has been sent."; } vm.newPasswordModel.email = ""; }, function (failMessage) { //something went wrong vm.forgetPasswordMessage = failMessage; }); } else { //Decode the email back again vm.newPasswordModel.email = decodeURIComponent(vm.newPasswordModel.email); vm.usernameDoesNotExist = true; //the username doesn't exist so we can't send a new password } }); } if (vm.newPasswordModel.userName) { var username = encodeURIComponent(vm.newPasswordModel.userName); //first test if the username entered by the user actually exists, if not tell them datacontext.isUsernameAvailable(username).then(function (data) { if (data === false) { //username exists vm.usernameDoesNotExist = false; //Decode the email back again vm.newPasswordModel.userName = decodeURIComponent(vm.newPasswordModel.userName); vm.newPasswordModel.sysUrl = config.sysUrl; //send the new password and tell the user datacontext.forgotPassword(vm.newPasswordModel, config.appCode).then(function () { vm.forgetPasswordMessage = "A message containing a link to reset your password has been sent."; vm.newPasswordModel.email = ""; }, function (failMessage) { //something went wrong vm.forgetPasswordMessage = failMessage; }); } else { //Decode the email back again vm.newPasswordModel.userName = decodeURIComponent(vm.newPasswordModel.userName); vm.usernameDoesNotExist = true; //the username doesn't exist so we can't send a new password } }); } } } } })();