Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions src/wwwroot/controllers/RegistrationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"Slug",
'$location',
'vcRecaptchaService',
'clerk'
'clerk',
'resources'
];

function RegistrationCtrl($scope, $rootScope, RELAY_CONFIG, signup, utils, $translate, $timeout, Slug, $location, vcRecaptchaService, clerk) {
function RegistrationCtrl($scope, $rootScope, RELAY_CONFIG, signup, utils, $translate, $timeout, Slug, $location, vcRecaptchaService, clerk, resources) {
var vm = this;
vm.submitRegistration = submitRegistration;
vm.emailRegistered = null;
Expand All @@ -28,6 +29,10 @@
vm.setCaptchaResponse = setCaptchaResponse;
vm.setWidgetId = setWidgetId;
vm.reloadCaptcha = reloadCaptcha;
vm.regexPhoneNumber = "^\\+?([0-9][\\s-]?(\\([0-9]+\\))*)+[0-9]$";
vm.regexCountryCode = "^\\+?\\d{1,3}\\s?$";
vm.regexAreaCode = "^\\(?0?\\d{1,4}\\)?\\s?$";
vm.regexLocalPhone = "^[\\d]+(?:\\s?[\\d]+){1,5}$";

var customAccountName = false;
vm.accountNameUpdated = function () {
Expand All @@ -41,9 +46,58 @@
var useClerkAuth = RELAY_CONFIG.useClerkAuthentication || false;
vm.recaptchaAvailable = !useClerkAuth && !!vcRecaptchaService;

resources.ensureIndustries();
resources.ensureCountries();
vm.resources = resources.data;

function validatePhoneFields() {
if (!$scope.form) {
return true;
}

var countryModelCtrl = $scope.form.countryPhoneNumber;
var areaModelCtrl = $scope.form.areaPhoneNumber;
var phoneModelCtrl = $scope.form.phoneNumber;

var countryVal = countryModelCtrl ? (countryModelCtrl.$modelValue || '') : '';
var areaVal = areaModelCtrl ? (areaModelCtrl.$modelValue || '') : '';
var phoneVal = phoneModelCtrl ? (phoneModelCtrl.$modelValue || '') : '';

var isEmpty = function (value) {
return !value || !value.toString().trim();
};

var countryRegex = new RegExp(vm.regexCountryCode);
var areaRegex = new RegExp(vm.regexAreaCode);
var phoneRegex = new RegExp(vm.regexLocalPhone);

var isCountryValid = isEmpty(countryVal) ? true : countryRegex.test(countryVal);
var isAreaValid = isEmpty(areaVal) ? true : areaRegex.test(areaVal);
var isPhoneValid = isEmpty(phoneVal) ? true : phoneRegex.test(phoneVal);

if (countryModelCtrl) {
countryModelCtrl.$setValidity('mask', true);
countryModelCtrl.$setValidity('country_code', isCountryValid);
}
if (areaModelCtrl) {
areaModelCtrl.$setValidity('mask', true);
areaModelCtrl.$setValidity('area_code', isAreaValid);
}
if (phoneModelCtrl) {
phoneModelCtrl.$setValidity('mask', true);
phoneModelCtrl.$setValidity('phone_number_field', isPhoneValid);
}

return isCountryValid && isAreaValid && isPhoneValid;
}

function submitRegistration(form) {
vm.submitted = true; // To show error messages

if (!validatePhoneFields()) {
return;
}

if (useClerkAuth) {
validatePasswordConfirmation();
if (form.$invalid) {
Expand Down Expand Up @@ -72,6 +126,16 @@
origin: $location.search().origin
};

var selectedCountry = $scope.form && $scope.form.country ? $scope.form.country.$modelValue : null;
var selectedIndustry = $scope.form && $scope.form.industry ? $scope.form.industry.$modelValue : null;
var countryCodePart = $scope.form && $scope.form.countryPhoneNumber ? ($scope.form.countryPhoneNumber.$modelValue || '') : '';
var areaCodePart = $scope.form && $scope.form.areaPhoneNumber ? ($scope.form.areaPhoneNumber.$modelValue || '') : '';
var phonePart = $scope.form && $scope.form.phoneNumber ? ($scope.form.phoneNumber.$modelValue || '') : '';

newUser.country_code = selectedCountry ? selectedCountry.code : null;
newUser.industry_code = selectedIndustry ? selectedIndustry.code : null;
newUser.phone_number = countryCodePart + '-' + areaCodePart + '-' + phonePart;

clerk.signUp(newUser)
.then(function (result) {
if (result.registered && result.needsVerification) {
Expand Down
3 changes: 3 additions & 0 deletions src/wwwroot/locales/en-translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
"validation_error_email_already_exist": "There is already an user with that email address.",
"validation_error_ilegal_date": "Invalid Expiration Date.",
"validation_error_mask": "Invalid Format.",
"validation_error_country_code": "Enter a valid country code (1-3 digits).",
"validation_error_area_code": "Enter a valid area code (1-4 digits).",
"validation_error_phone_number_field": "The number you entered doesn’t look valid; please make sure it has enough digits.",
"validation_error_invalid_card_number": "Invalid Credit Card number.",
"validation_error_payment_failure": "We couldn't process the payment, please check your information.",
"validation_error_pattern": "Please check the text",
Expand Down
3 changes: 3 additions & 0 deletions src/wwwroot/locales/es-translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ window['relay-translation-es'] = {
"validation_error_email_already_exist": "Ya existe un usuario con esa dirección de email.",
"validation_error_ilegal_date": "Escribe una fecha de expiración válida.",
"validation_error_mask": "Escribe un formato válido.",
"validation_error_country_code": "Ingresa un código de país válido (1-3 dígitos).",
"validation_error_area_code": "Ingresa un código de área válido (1-4 dígitos).",
"validation_error_phone_number_field": "El número ingresado no es válido; asegúrate de que tenga suficientes dígitos.",
"validation_error_invalid_card_number": "Escribe una tarjeta de crédito válida.",
"validation_error_payment_failure": "No pudimos realizar el pago, por favor revisa tu información.",
"validation_error_pattern": "Por favor revisa el texto ingresado",
Expand Down
40 changes: 40 additions & 0 deletions src/wwwroot/partials/signup/registration-w-password.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@ <h2>{{'registration_title' | translate}}</h2>
-->
</div>
</div>
<div class="flex input-container margin--bottom-inputs">
<div class="width--full margin-right">
<label class="flex" for="registration-industry">{{'industry_text' | translate}}:</label>
<ui-select id="registration-industry" ng-model="selected.value" name="industry" title="{{'select_choose_industry' | translate}}" on-select="form.industry.$modelValue = $model" required>
<ui-select-match placeholder="{{ 'select_choose_industry' | translate }}">
<span ng-bind-html="$select.selected.name"></span>
</ui-select-match>
<ui-select-choices repeat="item in (vm.resources.industries | filter: $select.search) track by item.code">
<span class="select-option" ng-bind-html="item.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
<span class="input--error" ng-show="(vm.submitted ||form.industry.$dirty) && form.industry.$error.required"><i class="arrow--up"></i>{{'validation_error_required' | translate}}</span>
</div>
<div class="width--full">
<label class="flex" for="registration-country">{{'country_text' | translate}}:</label>
<ui-select id="registration-country" ng-model="selected.value" name="country" title="{{'select_choose_country' | translate}}" on-select="form.country.$modelValue = $model" ng-disabled="disabled" required>
<ui-select-match placeholder="{{ 'select_choose_country' | translate }}">
<span ng-bind-html="$select.selected.name"></span>
</ui-select-match>
<ui-select-choices repeat="item in (vm.resources.countries | filter: $select.search)">
<span class="select-option" ng-bind-html="item.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
<span class="input--error" ng-show="(vm.submitted ||form.country.$dirty) && form.country.$error.required"><i class="arrow--up"></i>{{'validation_error_required' | translate}}</span>
</div>
</div>
<div class="flex input-container">
<div class="width--full margin-right">
<label class="flex" for="countryPhoneNumber">{{'country_phone_number' | translate}}:</label>
<input class="input input--extra-small width--full" ng-model="vm.countryPhoneNumber" name="countryPhoneNumber" validation-errors-fluid required />
</div>
<div class="width--full margin-right">
<label class="flex" for="areaPhoneNumber">{{'area_phone_number' | translate}}:</label>
<input class="input input--extra-small width--full" ng-model="vm.areaPhoneNumber" name="areaPhoneNumber" validation-errors-fluid required />
</div>
<div class="width--full">
<label class="flex" for="phoneNumber">{{'phone_number' | translate}}:</label>
<input class="input input--extra-medium width--full" ng-model="vm.phoneNumber" name="phoneNumber" validation-errors-fluid required />
</div>
</div>
<div class="flex input-container">
<div class="width--full margin-right">
<label class="flex" for="password">{{'registration_pass_label' | translate}}:</label>
Expand Down
50 changes: 49 additions & 1 deletion src/wwwroot/services/clerk.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@
return deferred.promise;
}

function _getApiKey(token) {
return $http({
actionDescription: 'action_get_temp_api_key',
method: 'POST',
url: RELAY_CONFIG.baseUrl + '/user/apikeys',
headers: {
'Content-Type': 'text/plain',
'Authorization': 'token ' + token
}
})
}

function login(credentials) {
return _instance().then(function(clerk) {
return clerk.client.signIn
Expand Down Expand Up @@ -126,6 +138,9 @@
'password': newUser.password,
'account_name': newUser.account_name,
'company_name': newUser.company || null,
'country_code': newUser.country_code || null,
'industry_code': newUser.industry_code || null,
'phone_number': newUser.phone_number || null,
'terms_and_conditions_version': newUser.termsAndConditions,
'origin': newUser.origin || null
}
Expand Down Expand Up @@ -242,6 +257,35 @@
'password': _pendingUserRegistration.password,
'account_name': _pendingUserRegistration.account_name,
'company_name': _pendingUserRegistration.company || null,
'country_code': _pendingUserRegistration.country_code || null,
'industry_code': _pendingUserRegistration.industry_code || null,
'phone_number': _pendingUserRegistration.phone_number || null,
'terms_and_conditions_version': _pendingUserRegistration.termsAndConditions,
'origin': _pendingUserRegistration.origin || null,
'clerk_user_id': clerkUserId
}
});
}

function _notifyUserRegistration(apiKey, clerkUserId) {
return $http({
actionDescription: 'action_notify_user_registration',
method: 'POST',
url: RELAY_CONFIG.baseUrl + '/user/notify',
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + apiKey
},
data: {
'user_email': _pendingUserRegistration.user_email,
'firstName': _pendingUserRegistration.firstName,
'lastName': _pendingUserRegistration.lastName,
'password': _pendingUserRegistration.password,
'account_name': _pendingUserRegistration.account_name,
'company_name': _pendingUserRegistration.company || null,
'country_code': _pendingUserRegistration.country_code || null,
'industry_code': _pendingUserRegistration.industry_code || null,
'phone_number': _pendingUserRegistration.phone_number || null,
'terms_and_conditions_version': _pendingUserRegistration.termsAndConditions,
'origin': _pendingUserRegistration.origin || null,
'clerk_user_id': clerkUserId
Expand Down Expand Up @@ -305,7 +349,11 @@
return _registerUserInRelay(emailVerifiedResponse.createdUserId).then(function() {
return clerk.setActive({ session: emailVerifiedResponse.createdSessionId }).then(function () {
return clerk.session.getToken({ template: 'legacy-api' }).then(function (token) {
return { verified: true, token: token };
return _getApiKey(token).then(function(apiKeyResponse) {
return _notifyUserRegistration(apiKeyResponse.data.api_key, emailVerifiedResponse.createdUserId).then(function() {
return { verified: true, token: token };
});
});
});
});
});
Expand Down