From 92b7dd3335a6572debeacfb5faa82c63a5e67888 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 8 Jun 2018 20:03:25 +0200 Subject: Some minor fixes --- .../userfrosting/js/pages/account-settings.js | 58 +++---- .../userfrosting/js/pages/forgot-password.js | 36 ++-- .../assets/userfrosting/js/pages/register.js | 186 ++++++++++----------- .../userfrosting/js/pages/resend-verification.js | 36 ++-- .../userfrosting/js/pages/set-or-reset-password.js | 36 ++-- .../assets/userfrosting/js/pages/sign-in.js | 146 ++++++++-------- 6 files changed, 249 insertions(+), 249 deletions(-) (limited to 'main/app/sprinkles/account/assets') diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js index ed75c7b..f1e9845 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js @@ -1,29 +1,29 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target page: account/settings - */ -$(document).ready(function () { - - // Apply select2 to locale field - $('.js-select2').select2(); - - $("#account-settings").ufForm({ - validators: page.validators.account_settings, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function () { - // Reload the page on success - window.location.reload(); - }); - - $("#profile-settings").ufForm({ - validators: page.validators.profile_settings, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function () { - // Reload the page on success - window.location.reload(); - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/settings + */ +$(document).ready(function () { + + // Apply select2 to locale field + $('.js-select2').select2(); + + $("#account-settings").ufForm({ + validators: page.validators.account_settings, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function () { + // Reload the page on success + window.location.reload(); + }); + + $("#profile-settings").ufForm({ + validators: page.validators.profile_settings, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function () { + // Reload the page on success + window.location.reload(); + }); +}); diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js index 95247fc..6eaa401 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js @@ -1,18 +1,18 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target page: account/forgot-password - */ -$(document).ready(function () { - - $("#request-password-reset").ufForm({ - validators: page.validators.forgot_password, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function () { - // Forward to login page on success - window.location.replace(site.uri.public + "/account/sign-in"); - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/forgot-password + */ +$(document).ready(function () { + + $("#request-password-reset").ufForm({ + validators: page.validators.forgot_password, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function () { + // Forward to login page on success + window.location.replace(site.uri.public + "/account/sign-in"); + }); +}); diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/register.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/register.js index a311305..4539d9b 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/register.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/register.js @@ -1,93 +1,93 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target page: account/register - */ -$(document).ready(function () { - // TOS modal - $(this).find('.js-show-tos').click(function () { - $("body").ufModal({ - sourceUrl: site.uri.public + "/modals/account/tos", - msgTarget: $("#alerts-page") - }); - }); - - // Auto-generate username when name is filled in - var autoGenerate = true; - $("#register").find('input[name=first_name], input[name=last_name]').on('input change', function () { - if (!autoGenerate) { - return; - } - - var form = $("#register"); - - var firstName = form.find('input[name=first_name]').val().trim(); - var lastName = form.find('input[name=last_name]').val().trim(); - - if (!firstName && !lastName) { - return; - } - - var userName = getSlug(firstName + ' ' + lastName, { - separator: '.' - }); - // Set slug - form.find('input[name=user_name]').val(userName); - }); - - // Autovalidate username field on a delay - var timer; - $("#register").find('input[name=first_name], input[name=last_name], input[name=user_name]').on('input change', function () { - clearTimeout(timer); // Clear the timer so we don't end up with dupes. - timer = setTimeout(function () { // assign timer a new timeout - $("#register").find('input[name=user_name]').valid(); - }, 50); - }); - - // Enable/disable username suggestions in registration page - $("#register").find('#form-register-username-suggest').on('click', function (e) { - e.preventDefault(); - var form = $("#register"); - $.getJSON(site.uri.public + '/account/suggest-username') - .done(function (data) { - // Set suggestion - form.find('input[name=user_name]').val(data.user_name); - }); - }); - - // Turn off autogenerate when someone enters stuff manually in user_name - $("#register").find('input[name=user_name]').on('input', function () { - autoGenerate = false; - }); - - // Add remote rule for checking usernames on the fly - var registrationValidators = $.extend( - true, // deep extend - page.validators.register, - { - rules: { - user_name: { - remote: { - url: site.uri.public + '/account/check-username', - dataType: 'text' - } - } - } - } - ); - - // Handles form submission - $("#register").ufForm({ - validators: registrationValidators, - msgTarget: $("#alerts-page"), - keyupDelay: 500 - }).on("submitSuccess.ufForm", function () { - window.location.reload(); - }).on("submitError.ufForm", function () { - // Reload captcha - $("#captcha").captcha(); - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/register + */ +$(document).ready(function () { + // TOS modal + $(this).find('.js-show-tos').click(function () { + $("body").ufModal({ + sourceUrl: site.uri.public + "/modals/account/tos", + msgTarget: $("#alerts-page") + }); + }); + + // Auto-generate username when name is filled in + var autoGenerate = true; + $("#register").find('input[name=first_name], input[name=last_name]').on('input change', function () { + if (!autoGenerate) { + return; + } + + var form = $("#register"); + + var firstName = form.find('input[name=first_name]').val().trim(); + var lastName = form.find('input[name=last_name]').val().trim(); + + if (!firstName && !lastName) { + return; + } + + var userName = getSlug(firstName + ' ' + lastName, { + separator: '.' + }); + // Set slug + form.find('input[name=user_name]').val(userName); + }); + + // Autovalidate username field on a delay + var timer; + $("#register").find('input[name=first_name], input[name=last_name], input[name=user_name]').on('input change', function () { + clearTimeout(timer); // Clear the timer so we don't end up with dupes. + timer = setTimeout(function () { // assign timer a new timeout + $("#register").find('input[name=user_name]').valid(); + }, 50); + }); + + // Enable/disable username suggestions in registration page + $("#register").find('#form-register-username-suggest').on('click', function (e) { + e.preventDefault(); + var form = $("#register"); + $.getJSON(site.uri.public + '/account/suggest-username') + .done(function (data) { + // Set suggestion + form.find('input[name=user_name]').val(data.user_name); + }); + }); + + // Turn off autogenerate when someone enters stuff manually in user_name + $("#register").find('input[name=user_name]').on('input', function () { + autoGenerate = false; + }); + + // Add remote rule for checking usernames on the fly + var registrationValidators = $.extend( + true, // deep extend + page.validators.register, + { + rules: { + user_name: { + remote: { + url: site.uri.public + '/account/check-username', + dataType: 'text' + } + } + } + } + ); + + // Handles form submission + $("#register").ufForm({ + validators: registrationValidators, + msgTarget: $("#alerts-page"), + keyupDelay: 500 + }).on("submitSuccess.ufForm", function () { + window.location.reload(); + }).on("submitError.ufForm", function () { + // Reload captcha + $("#captcha").captcha(); + }); +}); diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js index 7da85fa..a6db823 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js @@ -1,18 +1,18 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target page: account/resend-verification - */ -$(document).ready(function () { - - $("#request-verification-email").ufForm({ - validators: page.validators.resend_verification, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function () { - // Forward to login page on success - window.location.replace(site.uri.public + "/account/sign-in"); - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/resend-verification + */ +$(document).ready(function () { + + $("#request-verification-email").ufForm({ + validators: page.validators.resend_verification, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function () { + // Forward to login page on success + window.location.replace(site.uri.public + "/account/sign-in"); + }); +}); diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js index 62fbf4b..f5e2227 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js @@ -1,18 +1,18 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target pages: account/set-password, account/reset-password - */ -$(document).ready(function () { - - $("#set-or-reset-password").ufForm({ - validators: page.validators.set_password, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function () { - // Forward to home page on success - window.location.replace(site.uri.public + "/account/sign-in"); - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target pages: account/set-password, account/reset-password + */ +$(document).ready(function () { + + $("#set-or-reset-password").ufForm({ + validators: page.validators.set_password, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function () { + // Forward to home page on success + window.location.replace(site.uri.public + "/account/sign-in"); + }); +}); diff --git a/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js b/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js index 769a1b3..7362d6d 100644 --- a/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js +++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js @@ -1,73 +1,73 @@ -/** - * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. - * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} - * - * This script depends on validation rules specified in pages/partials/page.js.twig. - * - * Target page: account/sign-in - */ -$(document).ready(function () { - /** - * If there is a redirect parameter in the query string, redirect to that page. - * Otherwise, if there is a UF-Redirect header, redirect to that page. - * Otherwise, redirect to the home page. - */ - function redirectOnLogin(jqXHR) { - var components = URI.parse(window.location.href); - var query = URI.parseQuery(components['query']); - - if (query && query['redirect']) { - // Strip leading slashes from redirect strings - var redirectString = site.uri.public + '/' + query['redirect'].replace(/^\/+/, ""); - // Strip excess trailing slashes for clean URLs. e.g. if redirect=%2F - redirectString = redirectString.replace(/\/+$/, "/"); - // Redirect - window.location.replace(redirectString); - } else if (jqXHR.getResponseHeader('UF-Redirect')) { - window.location.replace(jqXHR.getResponseHeader('UF-Redirect')); - } else { - window.location.replace(site.uri.public); - } - } - - $("#sign-in").ufForm({ - validators: page.validators.login, - msgTarget: $("#alerts-page") - }).on("submitSuccess.ufForm", function (event, data, textStatus, jqXHR) { - if (localStorage.getItem("PrivateKey") === null && localStorage.getItem("🔒") === null) { - // GENERATE KEYS - var openpgp = window.openpgp; - var options; - var randomString = Math.random().toString(36).substr(2, 11); // PRIVKEY ENCRYPTION KEY - openpgp.initWorker({path: '/assets-raw/core/assets/SiteAssets/js/openpgp.worker.js'}); - options = { - userIds: [{name: $("input[name=user_name]").val()}], - curve: "curve25519", - passphrase: randomString - }; - openpgp.generateKey(options).then(function (key) { - localStorage.setItem("PrivateKey", key.privateKeyArmored); - localStorage.setItem("🔒", randomString); - - console.log(key.publicKeyArmored); - console.log(key.privateKeyArmored); - // SAVE PUBLIC KEY TO DATABASE - var data = { - csrf_name: site.csrf.name, - csrf_value: site.csrf.value, - PublicKey: key.publicKeyArmored - }; - $.ajax({ - type: 'POST', - dataType: "json", - url: site.uri.public + '/api/users/u/' + $("input[name=user_name]").val() + '/publickey', - data: data, - async: false - }); - redirectOnLogin(jqXHR); - }); - } else { - redirectOnLogin(jqXHR); - } - }); -}); +/** + * Page-specific Javascript file. Should generally be included as a separate asset bundle in your page template. + * example: {{ assets.js('js/pages/sign-in-or-register') | raw }} + * + * This script depends on validation rules specified in pages/partials/page.js.twig. + * + * Target page: account/sign-in + */ +$(document).ready(function () { + /** + * If there is a redirect parameter in the query string, redirect to that page. + * Otherwise, if there is a UF-Redirect header, redirect to that page. + * Otherwise, redirect to the home page. + */ + function redirectOnLogin(jqXHR) { + var components = URI.parse(window.location.href); + var query = URI.parseQuery(components['query']); + + if (query && query['redirect']) { + // Strip leading slashes from redirect strings + var redirectString = site.uri.public + '/' + query['redirect'].replace(/^\/+/, ""); + // Strip excess trailing slashes for clean URLs. e.g. if redirect=%2F + redirectString = redirectString.replace(/\/+$/, "/"); + // Redirect + window.location.replace(redirectString); + } else if (jqXHR.getResponseHeader('UF-Redirect')) { + window.location.replace(jqXHR.getResponseHeader('UF-Redirect')); + } else { + window.location.replace(site.uri.public); + } + } + + $("#sign-in").ufForm({ + validators: page.validators.login, + msgTarget: $("#alerts-page") + }).on("submitSuccess.ufForm", function (event, data, textStatus, jqXHR) { + if (localStorage.getItem("PrivateKey") === null && localStorage.getItem("🔒") === null) { + // GENERATE KEYS + var openpgp = window.openpgp; + var options; + var randomString = Math.random().toString(36).substr(2, 11); // PRIVKEY ENCRYPTION KEY + openpgp.initWorker({path: '/assets-raw/core/assets/SiteAssets/js/openpgp.worker.js'}); + options = { + userIds: [{name: $("input[name=user_name]").val()}], + curve: "curve25519", + passphrase: randomString + }; + openpgp.generateKey(options).then(function (key) { + localStorage.setItem("PrivateKey", key.privateKeyArmored); + localStorage.setItem("🔒", randomString); + + console.log(key.publicKeyArmored); + console.log(key.privateKeyArmored); + // SAVE PUBLIC KEY TO DATABASE + var data = { + csrf_name: site.csrf.name, + csrf_value: site.csrf.value, + PublicKey: key.publicKeyArmored + }; + $.ajax({ + type: 'POST', + dataType: "json", + url: site.uri.public + '/api/users/u/' + $("input[name=user_name]").val() + '/publickey', + data: data, + async: false + }); + redirectOnLogin(jqXHR); + }); + } else { + redirectOnLogin(jqXHR); + } + }); +}); -- cgit v1.2.3