(function () { 'use strict'; angular .module('RegistrationApp', ['angucomplete-alt']) .controller('RegistrationController', initialize); function initialize($http, ContactNumberService, PageService) { let vm = this; vm.registrationDetail = { type: '', // Either 'Talent', 'Minor' or 'Client' form: 'talentForm' // Either 'talentForm' or 'clientForm' }; vm.scout = {}; vm.agencyEmail = ''; vm.isLoading = false; vm.showOtpForm = false; vm.accountId = undefined; vm.showLoginButton = false; vm.resendOtpButtonDisabled = false; let contactNumberIntlTelInput = {}; init(); vm.setForm = setForm; vm.confirmRegistration = confirmRegistration; vm.register = register; function init() { // Set the affiliation if not empty if (AFFILIATION && AFFILIATION !== 'None') { localStorage.setItem('affiliation', AFFILIATION); } // Init contact number field let input = document.querySelector('#contact-number'); contactNumberIntlTelInput = window.intlTelInput(input); ContactNumberService.setCurrentCountry(contactNumberIntlTelInput); if (localStorage.getItem('accountId')) { vm.accountId = localStorage.getItem('accountId'); vm.showOtpForm = true; } flatpickr('#dateOfBirth', { disableMobile: 'true', }); setForm('talentForm'); } function setForm(form) { const btnTalentForm = document.getElementById('btnTalentForm'); const btnClientForm = document.getElementById('btnClientForm'); const btnToggleClass = 'btn-primary'; if (form === 'talentForm') { vm.registrationDetail.type = 'Talent'; btnTalentForm.classList.remove(btnToggleClass); btnClientForm.classList.add(btnToggleClass); } else { vm.registrationDetail.type = 'Client'; btnTalentForm.classList.add(btnToggleClass); btnClientForm.classList.remove(btnToggleClass); } vm.registrationDetail.form = form; } function confirmRegistration() { if (vm.registrationDetail.type === 'Talent' || vm.registrationDetail.type === 'Minor') { PageService.showModal('registrationConfirmationModal'); } else { register(); } } function enableResendOtpButton() { vm.resendOtpButtonDisabled = false; } function renderResetOtpTimer() { var timerInstance = new easytimer.Timer(); timerInstance.start({countdown: true, startValues: {seconds: 10}}); $('#countdownExample .values').html('(' + timerInstance.getTimeValues().toString(['seconds']) + 's)'); timerInstance.addEventListener('secondsUpdated', function (e) { $('#countdownExample .values').html('(' + timerInstance.getTimeValues().toString(['seconds']) + 's)'); }); timerInstance.addEventListener('targetAchieved', function (e) { $('#countdownExample .values').html(''); document.getElementById('countdownExample').disabled = false; enableResendOtpButton(); }); } function register() { vm.isLoading = true; vm.registrationDetail.countryCode = ContactNumberService.getCountryCode(contactNumberIntlTelInput); vm.registrationDetail.contactNumber = ContactNumberService.getContactNumber(contactNumberIntlTelInput); vm.registrationDetail.affiliation = localStorage.getItem('affiliation'); let request = { url: 'register', method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: $.param(vm.registrationDetail) }; $http(request) .then((response) => { vm.isLoading = false; vm.accountId = response.data.accountId; localStorage.setItem('accountId', response.data.accountId); // vm.registrationMessage = response.data.success; vm.registrationMessage = 'One time password was sent to your email address. Please check your inbox.'; vm.showOtpForm = true; PageService.showModal('registrationMessageModal'); vm.resendOtpButtonDisabled = true; renderResetOtpTimer(); }) .catch((error) => { vm.isLoading = false; if (error.status === 500) { vm.registrationMessage = 'You are having trouble connecting to our server at the moment. Please check your internet connection.'; } else if (error.data && error.data.error) { vm.registrationMessage = error.data.error; } PageService.showModal('registrationMessageModal'); }); PageService.hideModal('registrationConfirmationModal'); } vm.verifyOtp = function () { vm.isLoading = false; let request = { url: 'verify-otp', method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: $.param({otp: vm.registrationDetail.otp, accountId: vm.accountId}) }; $http(request) .then((response) => { vm.registrationMessage = 'OTP successfully verified.'; vm.showOtpForm = false; localStorage.removeItem('accountId'); vm.showLoginButton = true; PageService.showModal('registrationMessageModal'); window.location.href = '/app'; }) .catch((error) => { vm.isLoading = false; if (error.status === 500) { vm.registrationMessage = 'You are having trouble connecting to our server at the moment. Please check your internet connection.'; } else if (error.data && error.data.error) { vm.registrationMessage = error.data.error; } PageService.showModal('registrationMessageModal'); }); }; vm.resendOtp = function () { let request = { url: 'resend-otp', method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, data: $.param({ accountId: localStorage.getItem('accountId'), }) }; $http(request) .then((response) => { vm.registrationMessage = 'One time password was sent to your email address. Please check your inbox.'; vm.showOtpForm = true; PageService.showModal('registrationMessageModal'); vm.resendOtpButtonDisabled = true; renderResetOtpTimer(); }) .catch((error) => { vm.isLoading = false; if (error.status === 500) { vm.registrationMessage = 'You are having trouble connecting to our server at the moment. Please check your internet connection.'; } else if (error.data && error.data.error) { vm.registrationMessage = error.data.error; } PageService.showModal('registrationMessageModal'); }); }; vm.showCancelOtpVerificationModal = function () { vm.showOtpForm = false; PageService.showModal('cancelOtpVerificationModal'); }; vm.cancelOtpVerification = function () { localStorage.removeItem('accountId'); vm.showOtpForm = false; PageService.hideModal('cancelOtpVerificationModal'); }; vm.checkPassword = function () { var pass = document.getElementById('password').value; var rpass = document.getElementById('confirmPassword').value; }; } })(); (function () { 'use strict'; angular.module('RegistrationApp') .filter('trustAsHtml', trustAsHtml); function trustAsHtml($sce) { return function (html) { return $sce.trustAsHtml(html); }; } })(); (function () { 'use strict'; angular .module('RegistrationApp') .service('ContactNumberService', initialize); function initialize($http) { return { getNumber: getNumber, getCountryCode: getCountryCode, getContactNumber: getContactNumber, getCurrentLocation: getCurrentLocation, setCurrentCountry: setCurrentCountry }; function getNumber(contactNumberIntlTelInput) { if (!contactNumberIntlTelInput) { return ''; } return contactNumberIntlTelInput.getNumber(); } function getCountryCode(contactNumberIntlTelInput) { if (!contactNumberIntlTelInput) { return ''; } let countryData = contactNumberIntlTelInput.getSelectedCountryData(); if (!countryData) { return ''; } return ('+' + countryData.dialCode); } function getContactNumber(contactNumberIntlTelInput) { let countryCode = getCountryCode(contactNumberIntlTelInput); let contactNumber = getNumber(contactNumberIntlTelInput); return contactNumber.replace(countryCode, ''); } function getCurrentLocation() { return new Promise((resolve, reject) => { $http.get('http://ip-api.com/json').then((response) => { resolve(response.data); }); }); } function setCurrentCountry(contactNumberIntlTelInput) { if (!contactNumberIntlTelInput) { return; } getCurrentLocation().then((currentLocation) => { if (!currentLocation) { return; } contactNumberIntlTelInput.setCountry(currentLocation.countryCode); }); } } })(); (function () { 'use strict'; angular .module('RegistrationApp') .service('PageService', PageService); function PageService() { return { showModal: showModal, hideModal: hideModal, hideActiveModal: hideActiveModal }; function showModal(modal) { hideActiveModal(); $('#' + modal).modal('show'); setTimeout(() => { let body = $('body'); if (!body.hasClass('modal-open')) { body.addClass('modal-open'); } }, 2000); } function hideModal(modal) { $('#' + modal).modal('hide'); } function hideActiveModal() { $('.modal').modal('hide'); } } })();