From b787bfeeb2abd9e2400474b58ac4eadd1b29f687 Mon Sep 17 00:00:00 2001 From: Tim Brandin Date: Sat, 2 Apr 2016 12:59:50 +0200 Subject: [PATCH] Bugfixes for the hooks. --- CHANGELOG.md | 4 ++++ README.md | 12 ++++++------ imports/accounts_ui.js | 1 + imports/helpers.js | 3 ++- imports/ui/components/Button.jsx | 14 +++++--------- imports/ui/components/LoginForm.jsx | 7 ++----- package.js | 2 +- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1329ac..34f7fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +### v1.1.1 + +* Bugfixes + ### v1.1.0 * Renamed package to std:accounts-ui diff --git a/README.md b/README.md index a2aa259..feeb390 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # React Accounts UI -Current version 1.1.0 +Current version 1.1.1 ## Features @@ -58,19 +58,19 @@ Configure the behavior of `` * **homeRoutePath**    String Set the path to where you would like the user to be redirected after a successful login or sign out. -* **onSubmitHook**    function(error, state) +* **onSubmitHook**    function(error, state)    **client** Called when the LoginForm is being submitted: allows for custom actions to be taken on form submission. error contains possible errors occurred during the submission process, state specifies the LoginForm internal state from which the submission was triggered. A nice use case might be closing the modal or side-menu or dropdown showing LoginForm. -* **preSignUpHook**    function(options) +* **onPreSignUpHook**    function(options)    **client** Called just before submitting the LoginForm for sign-up: allows for custom actions on the data being submitted. A nice use could be extending the user profile object accessing options.profile. to be taken on form submission. The plain text password is also provided for any reasonable use. If you return a promise, the submission will wait until you resolve it. -* **postSignUpHook**    func(userId, info)    **server** +* **onPostSignUpHook**    func(userId, info)    **server** Called server side, just after a successful user account creation, post submitting the pwdForm for sign-up: allows for custom actions on the data being submitted after we are sure a new user was successfully created. A common use might be applying roles to the user, as this is only possible after fully completing user creation in `alanning:roles`. The userId is available as the first parameter, so that user user object may be retrieved. -* **postSignUpHook**    func(userId, info)    **client** +* **onPostSignUpHook**    func(userId, info)    **client** Called client side, just after a successful user account creation, post submitting the pwdForm for sign-up: allows for custom actions on the data being submitted after we are sure a new user was successfully created. Default is **loginPath**. -* **resetPasswordHook**    function() +* **onResetPasswordHook**    function() Change the default redirect behavior when the user clicks the link to reset their email sent from the system, i.e. you want a custom path for the reset password form. Default is **loginPath**. * **onEnrollAccountHook**    function() diff --git a/imports/accounts_ui.js b/imports/accounts_ui.js index 94cf273..47748e7 100644 --- a/imports/accounts_ui.js +++ b/imports/accounts_ui.js @@ -13,6 +13,7 @@ Accounts.ui._options = { requestOfflineToken: {}, forceApprovalPrompt: {}, passwordSignupFields: 'NO_PASSWORD', + minimumPasswordLength: 6, loginPath: '/', signUpPath: null, resetPasswordPath: null, diff --git a/imports/helpers.js b/imports/helpers.js index 4603268..2873319 100644 --- a/imports/helpers.js +++ b/imports/helpers.js @@ -44,9 +44,10 @@ export function passwordSignupFields() { }; export function validatePassword(password){ - if (password.length >= 7) { + if (password.length >= Accounts.ui._options.minimumPasswordLength) { return true; } else { + this.showMessage(T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength), 'warning'); return false; } }; diff --git a/imports/ui/components/Button.jsx b/imports/ui/components/Button.jsx index c217d42..2af3b28 100644 --- a/imports/ui/components/Button.jsx +++ b/imports/ui/components/Button.jsx @@ -2,23 +2,19 @@ import React from 'react'; import { Accounts } from 'meteor/accounts-base'; export class Button extends React.Component { - handleClick(evt) { - let { onClick, href } = this.props; - if (!href) { - evt.preventDefault(); - onClick(evt); - } + shouldComponentUpdate(nextProps) { + return this.props.href == nextProps.href; } render () { - const { label, href = null, type, disabled = false, className } = this.props; + const { label, href = null, type, disabled = false, className, onClick } = this.props; return type == 'link' ? ( - { label } + { label } ) : ( + onClick={ onClick }>{ label } ); } } diff --git a/imports/ui/components/LoginForm.jsx b/imports/ui/components/LoginForm.jsx index baf7c62..2f1fbf7 100644 --- a/imports/ui/components/LoginForm.jsx +++ b/imports/ui/components/LoginForm.jsx @@ -363,7 +363,7 @@ export class LoginForm extends Tracker.Component { showForgotPasswordLink() { return !this.state.user - && this.state.formState != STATES.PASSWORD_RESET + && this.state.formState == STATES.SIGN_IN && _.contains( ["USERNAME_AND_EMAIL", "USERNAME_AND_OPTIONAL_EMAIL", "EMAIL_ONLY"], passwordSignupFields()); @@ -543,7 +543,6 @@ export class LoginForm extends Tracker.Component { options.password = Meteor.uuid(); } else if (!validatePassword(password)) { - this.showMessage(T9n.get("error.minChar"), 'warning'); Accounts.ui._options.onSubmitHook("error.minChar", formState); return; } @@ -578,7 +577,7 @@ export class LoginForm extends Tracker.Component { }; // Allow for Promises to return. - let promise = Accounts.ui._options.preSignUpHook(options); + let promise = Accounts.ui._options.onPreSignUpHook(options); if (promise instanceof Promise) { promise.then(SignUp); } @@ -672,8 +671,6 @@ export class LoginForm extends Tracker.Component { } = this.state; if ( !validatePassword(newPassword) ){ - this.showMessage(T9n.get("error.minChar"), 'warning'); - return; } diff --git a/package.js b/package.js index ddb021b..8009f42 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'std:accounts-ui', - version: '1.1.0', + version: '1.1.1', summary: 'Accounts UI for React in Meteor 1.3', git: 'https://github.com/studiointeract/accounts-ui', documentation: 'README.md'