2016-05-28 18:18:28 +02:00
|
|
|
export const loginButtonsSession = Accounts._loginButtonsSession;
|
2016-03-29 02:36:48 +02:00
|
|
|
export const STATES = {
|
|
|
|
SIGN_IN: Symbol('SIGN_IN'),
|
|
|
|
SIGN_UP: Symbol('SIGN_UP'),
|
2016-04-02 14:20:43 +02:00
|
|
|
PROFILE: Symbol('PROFILE'),
|
2016-03-29 02:36:48 +02:00
|
|
|
PASSWORD_CHANGE: Symbol('PASSWORD_CHANGE'),
|
|
|
|
PASSWORD_RESET: Symbol('PASSWORD_RESET')
|
2016-03-28 22:34:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export function getLoginServices() {
|
|
|
|
// First look for OAuth services.
|
|
|
|
const services = Package['accounts-oauth'] ? Accounts.oauth.serviceNames() : [];
|
|
|
|
|
|
|
|
// Be equally kind to all login services. This also preserves
|
|
|
|
// backwards-compatibility.
|
|
|
|
services.sort();
|
|
|
|
|
|
|
|
return _.map(services, function(name){
|
|
|
|
return {name: name};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
// Export getLoginServices using old style globals for accounts-base which
|
|
|
|
// requires it.
|
|
|
|
this.getLoginServices = getLoginServices;
|
|
|
|
|
2016-03-31 15:57:28 +02:00
|
|
|
export function hasPasswordService() {
|
|
|
|
// First look for OAuth services.
|
|
|
|
return !!Package['accounts-password'];
|
|
|
|
};
|
|
|
|
|
2016-05-28 18:18:28 +02:00
|
|
|
export function loginResultCallback(service, err) {
|
|
|
|
if (!err) {
|
|
|
|
|
|
|
|
} else if (err instanceof Accounts.LoginCancelledError) {
|
|
|
|
// do nothing
|
|
|
|
} else if (err instanceof ServiceConfiguration.ConfigError) {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//loginButtonsSession.errorMessage(err.reason || "Unknown error");
|
|
|
|
}
|
|
|
|
|
2016-03-29 01:28:53 +02:00
|
|
|
if (Meteor.isClient) {
|
2016-05-28 18:18:28 +02:00
|
|
|
if (typeof redirect === 'string'){
|
|
|
|
window.location.href = '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof service === 'function'){
|
|
|
|
service();
|
2016-03-28 22:34:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export function passwordSignupFields() {
|
2016-03-31 15:57:28 +02:00
|
|
|
return Accounts.ui._options.passwordSignupFields || "EMAIL_ONLY_NO_PASSWORD";
|
2016-03-28 22:34:50 +02:00
|
|
|
};
|
|
|
|
|
2016-12-18 20:53:19 +01:00
|
|
|
export function validateEmail(email, showMessage, clearMessage) {
|
|
|
|
if (passwordSignupFields() === "USERNAME_AND_OPTIONAL_EMAIL" && email === '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Accounts.ui._options.emailPattern.test(email)) {
|
|
|
|
return true;
|
|
|
|
} else if (!email || email.length === 0) {
|
|
|
|
showMessage(T9n.get("error.emailRequired"), 'warning', false, 'email');
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
showMessage(T9n.get("error.accounts.Invalid email"), 'warning', false, 'email');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function validatePassword(password = '', showMessage, clearMessage){
|
2016-04-02 12:59:50 +02:00
|
|
|
if (password.length >= Accounts.ui._options.minimumPasswordLength) {
|
2016-03-28 22:34:50 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2016-12-18 20:53:19 +01:00
|
|
|
const errMsg = T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength);
|
|
|
|
showMessage(errMsg, 'warning', false, 'password');
|
2016-03-28 22:34:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-18 20:53:19 +01:00
|
|
|
export function validateUsername(username, showMessage, clearMessage) {
|
|
|
|
if ( username ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
showMessage(T9n.get("error.usernameRequired"), 'warning', false, 'username');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 04:37:10 +02:00
|
|
|
export function redirect(redirect) {
|
2016-03-28 22:34:50 +02:00
|
|
|
if (Meteor.isClient) {
|
|
|
|
if (window.history) {
|
2016-03-29 04:37:10 +02:00
|
|
|
Meteor.setTimeout(() => {
|
|
|
|
if (Package['kadira:flow-router']) {
|
|
|
|
Package['kadira:flow-router'].FlowRouter.go(redirect);
|
2016-12-18 20:53:19 +01:00
|
|
|
} else if (Package['kadira:flow-router-ssr']) {
|
2016-03-29 04:37:10 +02:00
|
|
|
Package['kadira:flow-router-ssr'].FlowRouter.go(redirect);
|
2016-12-18 20:53:19 +01:00
|
|
|
} else {
|
2016-03-29 04:37:10 +02:00
|
|
|
window.history.pushState( {} , 'redirect', redirect );
|
|
|
|
}
|
|
|
|
}, 500);
|
2016-03-28 22:34:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-31 15:57:28 +02:00
|
|
|
|
|
|
|
export function capitalize(string) {
|
|
|
|
return string.replace(/\-/, ' ').split(' ').map(word => {
|
|
|
|
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
|
|
}).join(' ');
|
|
|
|
}
|