aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/account/assets
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-16 21:09:05 +0200
committermarvin-borner@live.com2018-04-16 21:09:05 +0200
commitcf14306c2b3f82a81f8d56669a71633b4d4b5fce (patch)
tree86700651aa180026e89a66064b0364b1e4346f3f /main/app/sprinkles/account/assets
parent619b01b3615458c4ed78bfaeabb6b1a47cc8ad8b (diff)
Main merge to user management system - files are now at /main/public/
Diffstat (limited to 'main/app/sprinkles/account/assets')
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js29
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js19
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/register.js94
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js19
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js19
-rwxr-xr-xmain/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js39
6 files changed, 219 insertions, 0 deletions
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
new file mode 100755
index 0000000..8d8d2e7
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/account-settings.js
@@ -0,0 +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();
+ });
+});
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
new file mode 100755
index 0000000..3f24311
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/forgot-password.js
@@ -0,0 +1,19 @@
+/**
+ * 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() {
+
+ // TODO: Process form
+ $("#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
new file mode 100755
index 0000000..d855bb9
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/register.js
@@ -0,0 +1,94 @@
+/**
+ * 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();
+ }, 500);
+ });
+
+ // 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() {
+ // Reload to clear form and show alerts
+ 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
new file mode 100755
index 0000000..5c3eaf8
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/resend-verification.js
@@ -0,0 +1,19 @@
+/**
+ * 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() {
+
+ // TODO: Process form
+ $("#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
new file mode 100755
index 0000000..39cfd16
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/set-or-reset-password.js
@@ -0,0 +1,19 @@
+/**
+ * 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
+ // TODO: forward to landing/last page
+ 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
new file mode 100755
index 0000000..40a8628
--- /dev/null
+++ b/main/app/sprinkles/account/assets/userfrosting/js/pages/sign-in.js
@@ -0,0 +1,39 @@
+/**
+ * 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) {
+ redirectOnLogin(jqXHR);
+ });
+});