mirror of
https://github.com/vale981/accounts-ui
synced 2025-03-05 09:51:40 -05:00
Merge pull request #58 from todda00/form-submit-hook
call onSubmitHook after all form submissions
This commit is contained in:
commit
ee0ffeb81f
1 changed files with 39 additions and 16 deletions
|
@ -444,7 +444,9 @@ export class LoginForm extends Tracker.Component {
|
||||||
username = null,
|
username = null,
|
||||||
email = null,
|
email = null,
|
||||||
usernameOrEmail = null,
|
usernameOrEmail = null,
|
||||||
password
|
password,
|
||||||
|
formState,
|
||||||
|
onSubmitHook
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
let loginSelector;
|
let loginSelector;
|
||||||
|
@ -486,6 +488,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
||||||
|
onSubmitHook(error,formState);
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
||||||
}
|
}
|
||||||
|
@ -517,7 +520,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
oauthSignIn(serviceName) {
|
oauthSignIn(serviceName) {
|
||||||
const { formState, waiting, user } = this.state;
|
const { formState, waiting, user, onSubmitHook } = this.state;
|
||||||
//Thanks Josh Owens for this one.
|
//Thanks Josh Owens for this one.
|
||||||
function capitalService() {
|
function capitalService() {
|
||||||
return serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
|
return serviceName.charAt(0).toUpperCase() + serviceName.slice(1);
|
||||||
|
@ -538,6 +541,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
options.forceApprovalPrompt = Accounts.ui._options.forceApprovalPrompt[serviceName];
|
options.forceApprovalPrompt = Accounts.ui._options.forceApprovalPrompt[serviceName];
|
||||||
|
|
||||||
loginWithService(options, (error) => {
|
loginWithService(options, (error) => {
|
||||||
|
onSubmitHook(error,formState);
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"));
|
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -556,7 +560,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
email = null,
|
email = null,
|
||||||
usernameOrEmail = null,
|
usernameOrEmail = null,
|
||||||
password,
|
password,
|
||||||
formState
|
formState,
|
||||||
|
onSubmitHook
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
if (username !== null) {
|
if (username !== null) {
|
||||||
|
@ -594,7 +599,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
else if (!validatePassword(password)) {
|
else if (!validatePassword(password)) {
|
||||||
this.showMessage(T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength), 'warning');
|
this.showMessage(T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength), 'warning');
|
||||||
this.state.onSubmitHook("error.minChar", formState);
|
onSubmitHook("error.minChar", formState);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -608,13 +613,14 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
||||||
if (T9n.get(`error.accounts.${error.reason}`)) {
|
if (T9n.get(`error.accounts.${error.reason}`)) {
|
||||||
this.state.onSubmitHook(`error.accounts.${error.reason}`, formState);
|
onSubmitHook(`error.accounts.${error.reason}`, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.state.onSubmitHook("Unknown error", formState);
|
onSubmitHook("Unknown error", formState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
onSubmitHook(null, formState);
|
||||||
this.setState({
|
this.setState({
|
||||||
formState: STATES.PROFILE,
|
formState: STATES.PROFILE,
|
||||||
message: null,
|
message: null,
|
||||||
|
@ -642,7 +648,9 @@ export class LoginForm extends Tracker.Component {
|
||||||
const {
|
const {
|
||||||
email = '',
|
email = '',
|
||||||
usernameOrEmail = '',
|
usernameOrEmail = '',
|
||||||
waiting
|
waiting,
|
||||||
|
formState,
|
||||||
|
onSubmitHook
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
@ -659,7 +667,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
||||||
}
|
}
|
||||||
|
onSubmitHook(error, formState);
|
||||||
this.setState({ waiting: false });
|
this.setState({ waiting: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -673,24 +681,29 @@ export class LoginForm extends Tracker.Component {
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
||||||
}
|
}
|
||||||
|
onSubmitHook(error, formState);
|
||||||
this.setState({ waiting: false });
|
this.setState({ waiting: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
let errMsg = null;
|
||||||
if (_.contains([ "USERNAME_AND_EMAIL_NO_PASSWORD" ], passwordSignupFields())) {
|
if (_.contains([ "USERNAME_AND_EMAIL_NO_PASSWORD" ], passwordSignupFields())) {
|
||||||
this.showMessage(T9n.get("error.accounts.Invalid email or username"), 'warning');
|
errMsg = T9n.get("error.accounts.Invalid email or username");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("error.accounts.Invalid email"), 'warning');
|
errMsg = T9n.get("error.accounts.Invalid email");
|
||||||
}
|
}
|
||||||
|
this.showMessage(errMsg,'warning');
|
||||||
|
onSubmitHook(errMsg, formState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordReset() {
|
passwordReset() {
|
||||||
const {
|
const {
|
||||||
email = '',
|
email = '',
|
||||||
waiting
|
waiting,
|
||||||
|
formState,
|
||||||
|
onSubmitHook
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
if (waiting) {
|
if (waiting) {
|
||||||
|
@ -707,23 +720,29 @@ export class LoginForm extends Tracker.Component {
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
||||||
}
|
}
|
||||||
|
onSubmitHook(error, formState);
|
||||||
this.setState({ waiting: false });
|
this.setState({ waiting: false });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("error.accounts.Invalid email"), 'warning');
|
const errMsg = T9n.get("error.accounts.Invalid email");
|
||||||
|
onSubmitHook(errMsg, formState);
|
||||||
|
this.showMessage(errMsg,'warning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordChange() {
|
passwordChange() {
|
||||||
const {
|
const {
|
||||||
password,
|
password,
|
||||||
newPassword
|
newPassword,
|
||||||
|
formState,
|
||||||
|
onSubmitHook
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
if ( !validatePassword(newPassword) ){
|
if ( !validatePassword(newPassword) ){
|
||||||
this.showMessage(T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength), 'warning');
|
const errMsg = T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength);
|
||||||
|
this.showMessage(errMsg,'warning');
|
||||||
|
onSubmitHook(errMsg,formState);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,9 +754,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
Accounts.resetPassword(token, newPassword, (error) => {
|
Accounts.resetPassword(token, newPassword, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
||||||
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
||||||
|
onSubmitHook(null, formState);
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
Accounts._loginButtonsSession.set('resetPasswordToken', null);
|
Accounts._loginButtonsSession.set('resetPasswordToken', null);
|
||||||
Accounts._loginButtonsSession.set('enrollAccountToken', null);
|
Accounts._loginButtonsSession.set('enrollAccountToken', null);
|
||||||
|
@ -748,9 +769,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
Accounts.changePassword(password, newPassword, (error) => {
|
Accounts.changePassword(password, newPassword, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
||||||
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
||||||
|
onSubmitHook(null, formState);
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue