mirror of
https://github.com/vale981/accounts-ui
synced 2025-03-04 17:31:41 -05:00
Merge branch 'master' into master
This commit is contained in:
commit
40242c7d38
18 changed files with 236 additions and 213 deletions
33
.versions
33
.versions
|
@ -1,10 +1,10 @@
|
||||||
accounts-base@1.2.15
|
accounts-base@1.2.17
|
||||||
allow-deny@1.0.5
|
allow-deny@1.0.5
|
||||||
babel-compiler@6.14.1
|
babel-compiler@6.18.2
|
||||||
babel-runtime@1.0.1
|
babel-runtime@1.0.1
|
||||||
base64@1.0.10
|
base64@1.0.10
|
||||||
binary-heap@1.0.10
|
binary-heap@1.0.10
|
||||||
blaze@2.1.8
|
blaze@2.3.2
|
||||||
blaze-tools@1.0.9
|
blaze-tools@1.0.9
|
||||||
boilerplate-generator@1.0.11
|
boilerplate-generator@1.0.11
|
||||||
caching-compiler@1.1.9
|
caching-compiler@1.1.9
|
||||||
|
@ -12,35 +12,36 @@ callback-hook@1.0.10
|
||||||
check@1.2.5
|
check@1.2.5
|
||||||
coffeescript@1.0.17
|
coffeescript@1.0.17
|
||||||
ddp@1.2.5
|
ddp@1.2.5
|
||||||
ddp-client@1.3.3
|
ddp-client@1.3.4
|
||||||
ddp-common@1.2.8
|
ddp-common@1.2.8
|
||||||
ddp-rate-limiter@1.0.7
|
ddp-rate-limiter@1.0.7
|
||||||
ddp-server@1.3.13
|
ddp-server@1.3.14
|
||||||
deps@1.0.12
|
deps@1.0.12
|
||||||
diff-sequence@1.0.7
|
diff-sequence@1.0.7
|
||||||
ecmascript@0.6.3
|
ecmascript@0.7.3
|
||||||
ecmascript-runtime@0.3.15
|
ecmascript-runtime@0.3.15
|
||||||
ejson@1.0.13
|
ejson@1.0.13
|
||||||
email@1.1.18
|
email@1.2.1
|
||||||
geojson-utils@1.0.10
|
geojson-utils@1.0.10
|
||||||
html-tools@1.0.10
|
html-tools@1.0.10
|
||||||
htmljs@1.0.10
|
htmljs@1.0.11
|
||||||
id-map@1.0.9
|
id-map@1.0.9
|
||||||
jquery@1.11.10
|
jquery@1.11.10
|
||||||
localstorage@1.0.12
|
localstorage@1.0.12
|
||||||
logging@1.1.17
|
logging@1.1.17
|
||||||
meteor@1.6.1
|
meteor@1.6.1
|
||||||
minimongo@1.0.21
|
minimongo@1.0.23
|
||||||
modules@0.7.9
|
modules@0.8.2
|
||||||
modules-runtime@0.7.9
|
modules-runtime@0.7.10
|
||||||
mongo@1.1.16
|
mongo@1.1.17
|
||||||
mongo-id@1.0.6
|
mongo-id@1.0.6
|
||||||
npm-mongo@2.2.24
|
npm-mongo@2.2.24
|
||||||
observe-sequence@1.0.16
|
observe-sequence@1.0.16
|
||||||
ordered-dict@1.0.9
|
ordered-dict@1.0.9
|
||||||
promise@0.8.8
|
promise@0.8.8
|
||||||
random@1.0.10
|
random@1.0.10
|
||||||
rate-limit@1.0.7
|
rate-limit@1.0.8
|
||||||
|
react-meteor-data@0.2.11
|
||||||
reactive-dict@1.1.8
|
reactive-dict@1.1.8
|
||||||
reactive-var@1.0.11
|
reactive-var@1.0.11
|
||||||
retry@1.0.9
|
retry@1.0.9
|
||||||
|
@ -50,10 +51,10 @@ session@1.1.7
|
||||||
softwarerero:accounts-t9n@1.3.3
|
softwarerero:accounts-t9n@1.3.3
|
||||||
spacebars@1.0.12
|
spacebars@1.0.12
|
||||||
spacebars-compiler@1.0.12
|
spacebars-compiler@1.0.12
|
||||||
std:accounts-ui@1.2.20
|
std:accounts-ui@1.2.22
|
||||||
tmeasday:check-npm-versions@0.3.0
|
tmeasday:check-npm-versions@0.3.0
|
||||||
tracker@1.1.2
|
tracker@1.1.3
|
||||||
ui@1.0.11
|
ui@1.0.11
|
||||||
underscore@1.0.10
|
underscore@1.0.10
|
||||||
webapp@1.3.14
|
webapp@1.3.15
|
||||||
webapp-hashing@1.0.9
|
webapp-hashing@1.0.9
|
||||||
|
|
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,5 +1,19 @@
|
||||||
# ChangeLog
|
# ChangeLog
|
||||||
|
|
||||||
|
### v1.2.22
|
||||||
|
15-Jun-2017
|
||||||
|
|
||||||
|
* Fixed issue with faulty formState proptype.
|
||||||
|
* Fixed issue with faulty object iteration.
|
||||||
|
* Removed lodash dependency.
|
||||||
|
* Removed tracker dependency.
|
||||||
|
|
||||||
|
### v1.2.21
|
||||||
|
26-May-2017
|
||||||
|
|
||||||
|
* Added functionality to include your own translation function.
|
||||||
|
* Replaced dependency on tracker-component with react-meteor-data.
|
||||||
|
|
||||||
### v1.2.20
|
### v1.2.20
|
||||||
13-March-2017
|
13-March-2017
|
||||||
|
|
||||||
|
|
54
README.md
54
README.md
|
@ -1,6 +1,6 @@
|
||||||
# React Accounts UI
|
# React Accounts UI
|
||||||
|
|
||||||
Current version 1.2.20
|
Current version 1.2.22
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
@ -206,52 +206,6 @@ Meteor.startup( () => {
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
As a bonus, here's a component that redirects to the signin route if you're not
|
|
||||||
logged in, using [`Tracker.Component`](https://www.npmjs.com/package/tracker-component).
|
|
||||||
|
|
||||||
`npm i --save tracker-component`
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import React from 'react';
|
|
||||||
import Tracker from 'tracker-component';
|
|
||||||
import { Meteor } from 'meteor/meteor';
|
|
||||||
import { browserHistory } from 'react-router';
|
|
||||||
|
|
||||||
const AdminPage = () => (
|
|
||||||
<h3>Admin</h3>
|
|
||||||
);
|
|
||||||
|
|
||||||
export class Admin extends Tracker.Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.autorun(() => {
|
|
||||||
this.setState({
|
|
||||||
isAuthenticated: Meteor.user()
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillMount() {
|
|
||||||
// Check that the user is logged in before the component mounts
|
|
||||||
if (!this.state.isAuthenticated) {
|
|
||||||
browserHistory.push(null, '/signin');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate() {
|
|
||||||
// Navigate to a sign in page if the user isn't authenticated when data changes
|
|
||||||
if (!this.state.isAuthenticated) {
|
|
||||||
browserHistory.push(null, '/signin');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return <AdminPage {...this.state} />;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
You can learn more about the remaining components here in the tutorial on [React Router Basics](https://themeteorchef.com/snippets/react-router-basics/) by the Meteor Chef.
|
You can learn more about the remaining components here in the tutorial on [React Router Basics](https://themeteorchef.com/snippets/react-router-basics/) by the Meteor Chef.
|
||||||
|
|
||||||
|
|
||||||
|
@ -399,6 +353,7 @@ To install the dependencies added in your package.json run:
|
||||||
// main.jsx
|
// main.jsx
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import { Accounts, STATES } from 'meteor/std:accounts-ui';
|
import { Accounts, STATES } from 'meteor/std:accounts-ui';
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
|
||||||
|
@ -483,6 +438,11 @@ class NewLogin extends Accounts.ui.LoginForm {
|
||||||
return super.fields();
|
return super.fields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translate(text) {
|
||||||
|
// Here you specify your own translation function, e.g.
|
||||||
|
return this.props.t(text);
|
||||||
|
}
|
||||||
|
|
||||||
signUp(options = {}) {
|
signUp(options = {}) {
|
||||||
const { firstname = null } = this.state;
|
const { firstname = null } = this.state;
|
||||||
if (firstname !== null) {
|
if (firstname !== null) {
|
||||||
|
|
|
@ -3,5 +3,4 @@
|
||||||
// checkNpmVersions({
|
// checkNpmVersions({
|
||||||
// "react": ">=0.14.7 || ^15.0.0-rc.2",
|
// "react": ">=0.14.7 || ^15.0.0-rc.2",
|
||||||
// "react-dom": ">=0.14.7 || ^15.0.0-rc.2",
|
// "react-dom": ">=0.14.7 || ^15.0.0-rc.2",
|
||||||
// "tracker-component": "^1.3.13"
|
|
||||||
// });
|
// });
|
||||||
|
|
|
@ -73,21 +73,21 @@ Accounts.ui.config = function(options) {
|
||||||
'emailPattern',
|
'emailPattern',
|
||||||
];
|
];
|
||||||
|
|
||||||
_.each(_.keys(options), function (key) {
|
Object.keys(options).forEach(function (key) {
|
||||||
if (!_.contains(VALID_KEYS, key))
|
if (!VALID_KEYS.includes(key))
|
||||||
throw new Error("Accounts.ui.config: Invalid key: " + key);
|
throw new Error("Accounts.ui.config: Invalid key: " + key);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Deal with `passwordSignupFields`
|
// Deal with `passwordSignupFields`
|
||||||
if (options.passwordSignupFields) {
|
if (options.passwordSignupFields) {
|
||||||
if (_.contains([
|
if ([
|
||||||
"USERNAME_AND_EMAIL",
|
"USERNAME_AND_EMAIL",
|
||||||
"USERNAME_AND_OPTIONAL_EMAIL",
|
"USERNAME_AND_OPTIONAL_EMAIL",
|
||||||
"USERNAME_ONLY",
|
"USERNAME_ONLY",
|
||||||
"EMAIL_ONLY",
|
"EMAIL_ONLY",
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], options.passwordSignupFields)) {
|
].includes(options.passwordSignupFields)) {
|
||||||
Accounts.ui._options.passwordSignupFields = options.passwordSignupFields;
|
Accounts.ui._options.passwordSignupFields = options.passwordSignupFields;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -97,7 +97,8 @@ Accounts.ui.config = function(options) {
|
||||||
|
|
||||||
// Deal with `requestPermissions`
|
// Deal with `requestPermissions`
|
||||||
if (options.requestPermissions) {
|
if (options.requestPermissions) {
|
||||||
_.each(options.requestPermissions, function (scope, service) {
|
Object.keys(options.requestPermissions).forEach(service => {
|
||||||
|
const score = options.requestPermissions[service];
|
||||||
if (Accounts.ui._options.requestPermissions[service]) {
|
if (Accounts.ui._options.requestPermissions[service]) {
|
||||||
throw new Error("Accounts.ui.config: Can't set `requestPermissions` more than once for " + service);
|
throw new Error("Accounts.ui.config: Can't set `requestPermissions` more than once for " + service);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +113,8 @@ Accounts.ui.config = function(options) {
|
||||||
|
|
||||||
// Deal with `requestOfflineToken`
|
// Deal with `requestOfflineToken`
|
||||||
if (options.requestOfflineToken) {
|
if (options.requestOfflineToken) {
|
||||||
_.each(options.requestOfflineToken, function (value, service) {
|
Object.keys(options.requestOfflineToken).forEach(service => {
|
||||||
|
const value = options.requestOfflineToken[service];
|
||||||
if (service !== 'google')
|
if (service !== 'google')
|
||||||
throw new Error("Accounts.ui.config: `requestOfflineToken` only supported for Google login at the moment.");
|
throw new Error("Accounts.ui.config: `requestOfflineToken` only supported for Google login at the moment.");
|
||||||
|
|
||||||
|
@ -127,7 +129,8 @@ Accounts.ui.config = function(options) {
|
||||||
|
|
||||||
// Deal with `forceApprovalPrompt`
|
// Deal with `forceApprovalPrompt`
|
||||||
if (options.forceApprovalPrompt) {
|
if (options.forceApprovalPrompt) {
|
||||||
_.each(options.forceApprovalPrompt, function (value, service) {
|
Object.keys(options.forceApprovalPrompt).forEach(service => {
|
||||||
|
const value = options.forceApprovalPrompt[service];
|
||||||
if (service !== 'google')
|
if (service !== 'google')
|
||||||
throw new Error("Accounts.ui.config: `forceApprovalPrompt` only supported for Google login at the moment.");
|
throw new Error("Accounts.ui.config: `forceApprovalPrompt` only supported for Google login at the moment.");
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,11 @@ Accounts.sendLoginEmail = function (userId, address) {
|
||||||
throw new Error("Can't find user");
|
throw new Error("Can't find user");
|
||||||
// pick the first unverified address if we weren't passed an address.
|
// pick the first unverified address if we weren't passed an address.
|
||||||
if (!address) {
|
if (!address) {
|
||||||
var email = _.find(user.emails || [],
|
var email = (user.emails || []).find(({ verified }) => !verified);
|
||||||
function (e) { return !e.verified; });
|
|
||||||
address = (email || {}).address;
|
address = (email || {}).address;
|
||||||
}
|
}
|
||||||
// make sure we have a valid address
|
// make sure we have a valid address
|
||||||
if (!address || !_.contains(_.pluck(user.emails || [], 'address'), address))
|
if (!address || !(user.emails || []).map(({ address }) => address).includes(address))
|
||||||
throw new Error("No such email address for user.");
|
throw new Error("No such email address for user.");
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function getLoginServices() {
|
||||||
// backwards-compatibility.
|
// backwards-compatibility.
|
||||||
services.sort();
|
services.sort();
|
||||||
|
|
||||||
return _.map(services, function(name){
|
return services.map(function(name){
|
||||||
return {name: name};
|
return {name: name};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -64,10 +64,10 @@ export function validateEmail(email, showMessage, clearMessage) {
|
||||||
if (Accounts.ui._options.emailPattern.test(email)) {
|
if (Accounts.ui._options.emailPattern.test(email)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!email || email.length === 0) {
|
} else if (!email || email.length === 0) {
|
||||||
showMessage(T9n.get("error.emailRequired"), 'warning', false, 'email');
|
showMessage("error.emailRequired", 'warning', false, 'email');
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
showMessage(T9n.get("error.accounts.Invalid email"), 'warning', false, 'email');
|
showMessage("error.accounts.Invalid email", 'warning', false, 'email');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,8 @@ export function validatePassword(password = '', showMessage, clearMessage){
|
||||||
if (password.length >= Accounts.ui._options.minimumPasswordLength) {
|
if (password.length >= Accounts.ui._options.minimumPasswordLength) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const errMsg = T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength);
|
// const errMsg = T9n.get("error.minChar").replace(/7/, Accounts.ui._options.minimumPasswordLength);
|
||||||
|
const errMsg = "error.minChar"
|
||||||
showMessage(errMsg, 'warning', false, 'password');
|
showMessage(errMsg, 'warning', false, 'password');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +88,7 @@ export function validateUsername(username, showMessage, clearMessage, formState)
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const fieldName = (passwordSignupFields() === 'USERNAME_ONLY' || formState === STATES.SIGN_UP) ? 'username' : 'usernameOrEmail';
|
const fieldName = (passwordSignupFields() === 'USERNAME_ONLY' || formState === STATES.SIGN_UP) ? 'username' : 'usernameOrEmail';
|
||||||
showMessage(T9n.get("error.usernameRequired"), 'warning', false, fieldName);
|
showMessage("error.usernameRequired", 'warning', false, fieldName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ const VALID_KEYS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const validateKey = function (key) {
|
export const validateKey = function (key) {
|
||||||
if (!_.contains(VALID_KEYS, key))
|
if (!VALID_KEYS.includes(key))
|
||||||
throw new Error("Invalid key in loginButtonsSession: " + key);
|
throw new Error("Invalid key in loginButtonsSession: " + key);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ export const KEY_PREFIX = "Meteor.loginButtons.";
|
||||||
Accounts._loginButtonsSession = {
|
Accounts._loginButtonsSession = {
|
||||||
set: function(key, value) {
|
set: function(key, value) {
|
||||||
validateKey(key);
|
validateKey(key);
|
||||||
if (_.contains(['errorMessage', 'infoMessage'], key))
|
if (['errorMessage', 'infoMessage'].includes(key))
|
||||||
throw new Error("Don't set errorMessage or infoMessage directly. Instead, use errorMessage() or infoMessage().");
|
throw new Error("Don't set errorMessage or infoMessage directly. Instead, use errorMessage() or infoMessage().");
|
||||||
|
|
||||||
this._set(key, value);
|
this._set(key, value);
|
||||||
|
@ -68,7 +68,7 @@ if (Meteor.isClient){
|
||||||
//
|
//
|
||||||
Accounts.onPageLoadLogin(function (attemptInfo) {
|
Accounts.onPageLoadLogin(function (attemptInfo) {
|
||||||
// Ignore if we have a left over login attempt for a service that is no longer registered.
|
// Ignore if we have a left over login attempt for a service that is no longer registered.
|
||||||
if (_.contains(_.pluck(getLoginServices(), "name"), attemptInfo.type))
|
if (getLoginServices().map(({ name }) => name).includes(attemptInfo.type))
|
||||||
loginResultCallback(attemptInfo.type, attemptInfo.error);
|
loginResultCallback(attemptInfo.type, attemptInfo.error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
let Link;
|
let Link;
|
||||||
try { Link = require('react-router').Link; } catch(e) {}
|
try { Link = require('react-router').Link; } catch(e) {}
|
||||||
|
|
||||||
export class Button extends React.Component {
|
export class Button extends React.Component {
|
||||||
propTypes: {
|
|
||||||
onClick: PropTypes.func
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
|
@ -34,4 +30,8 @@ export class Button extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button.propTypes = {
|
||||||
|
onClick: PropTypes.func
|
||||||
|
};
|
||||||
|
|
||||||
Accounts.ui.Button = Button;
|
Accounts.ui.Button = Button;
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
export class Field extends React.Component {
|
export class Field extends React.Component {
|
||||||
propTypes: {
|
|
||||||
onChange: PropTypes.func
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -74,4 +70,8 @@ export class Field extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Field.propTypes = {
|
||||||
|
onChange: PropTypes.func
|
||||||
|
};
|
||||||
|
|
||||||
Accounts.ui.Field = Field;
|
Accounts.ui.Field = Field;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
import './Fields.jsx';
|
import './Fields.jsx';
|
||||||
import './Buttons.jsx';
|
import './Buttons.jsx';
|
||||||
|
@ -11,14 +11,6 @@ import './SocialButtons.jsx';
|
||||||
import './FormMessages.jsx';
|
import './FormMessages.jsx';
|
||||||
|
|
||||||
export class Form extends React.Component {
|
export class Form extends React.Component {
|
||||||
propTypes: {
|
|
||||||
oauthServices: PropTypes.object,
|
|
||||||
fields: PropTypes.object.isRequired,
|
|
||||||
buttons: PropTypes.object.isRequired,
|
|
||||||
error: PropTypes.string,
|
|
||||||
ready: PropTypes.bool
|
|
||||||
};
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let form = this.form;
|
let form = this.form;
|
||||||
if (form) {
|
if (form) {
|
||||||
|
@ -36,6 +28,7 @@ export class Form extends React.Component {
|
||||||
buttons,
|
buttons,
|
||||||
error,
|
error,
|
||||||
messages,
|
messages,
|
||||||
|
translate,
|
||||||
ready = true,
|
ready = true,
|
||||||
className
|
className
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
@ -48,7 +41,7 @@ export class Form extends React.Component {
|
||||||
>
|
>
|
||||||
<Accounts.ui.Fields fields={ fields } />
|
<Accounts.ui.Fields fields={ fields } />
|
||||||
<Accounts.ui.Buttons buttons={ buttons } />
|
<Accounts.ui.Buttons buttons={ buttons } />
|
||||||
<Accounts.ui.PasswordOrService oauthServices={ oauthServices } />
|
<Accounts.ui.PasswordOrService oauthServices={ oauthServices } translate={ translate } />
|
||||||
<Accounts.ui.SocialButtons oauthServices={ oauthServices } />
|
<Accounts.ui.SocialButtons oauthServices={ oauthServices } />
|
||||||
<Accounts.ui.FormMessages messages={messages} />
|
<Accounts.ui.FormMessages messages={messages} />
|
||||||
</form>
|
</form>
|
||||||
|
@ -56,4 +49,13 @@ export class Form extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Form.propTypes = {
|
||||||
|
oauthServices: PropTypes.object,
|
||||||
|
fields: PropTypes.object.isRequired,
|
||||||
|
buttons: PropTypes.object.isRequired,
|
||||||
|
translate: PropTypes.func.isRequired,
|
||||||
|
error: PropTypes.string,
|
||||||
|
ready: PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
Accounts.ui.Form = Form;
|
Accounts.ui.Form = Form;
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
|
|
||||||
|
function isObject(obj) {
|
||||||
|
return obj === Object(obj);
|
||||||
|
}
|
||||||
|
|
||||||
export class FormMessage extends React.Component {
|
export class FormMessage extends React.Component {
|
||||||
render () {
|
render () {
|
||||||
let { message, type, className = "message", style = {}, deprecated } = this.props;
|
let { message, type, className = "message", style = {}, deprecated } = this.props;
|
||||||
|
@ -9,7 +13,7 @@ export class FormMessage extends React.Component {
|
||||||
// Found backwords compatibility issue.
|
// Found backwords compatibility issue.
|
||||||
console.warn('You are overriding Accounts.ui.Form and using FormMessage, the use of FormMessage in Form has been depreacted in v1.2.11, update your implementation to use FormMessages: https://github.com/studiointeract/accounts-ui/#deprecations');
|
console.warn('You are overriding Accounts.ui.Form and using FormMessage, the use of FormMessage in Form has been depreacted in v1.2.11, update your implementation to use FormMessages: https://github.com/studiointeract/accounts-ui/#deprecations');
|
||||||
}
|
}
|
||||||
message = _.isObject(message) ? message.message : message; // If message is object, then try to get message from it
|
message = isObject(message) ? message.message : message; // If message is object, then try to get message from it
|
||||||
return message ? (
|
return message ? (
|
||||||
<div style={ style }
|
<div style={ style }
|
||||||
className={[ className, type ].join(' ')}>{ message }</div>
|
className={[ className, type ].join(' ')}>{ message }</div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React, { PropTypes, Component } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import Tracker from 'tracker-component';
|
import { createContainer } from 'meteor/react-meteor-data';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
import { T9n } from 'meteor/softwarerero:accounts-t9n';
|
import { T9n } from 'meteor/softwarerero:accounts-t9n';
|
||||||
import { KEY_PREFIX } from '../../login_session.js';
|
import { KEY_PREFIX } from '../../login_session.js';
|
||||||
|
@ -18,7 +18,15 @@ import {
|
||||||
capitalize
|
capitalize
|
||||||
} from '../../helpers.js';
|
} from '../../helpers.js';
|
||||||
|
|
||||||
export class LoginForm extends Tracker.Component {
|
function indexBy(array, key) {
|
||||||
|
const result = {};
|
||||||
|
array.forEach(function(obj) {
|
||||||
|
result[obj[key]] = obj;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoginForm extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
let {
|
let {
|
||||||
|
@ -45,6 +53,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook,
|
onPreSignUpHook: props.onPreSignUpHook || Accounts.ui._options.onPreSignUpHook,
|
||||||
onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook,
|
onPostSignUpHook: props.onPostSignUpHook || Accounts.ui._options.onPostSignUpHook,
|
||||||
};
|
};
|
||||||
|
this.translate = this.translate.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -76,17 +85,6 @@ export class LoginForm extends Tracker.Component {
|
||||||
this.setState(prevState => ({
|
this.setState(prevState => ({
|
||||||
...this.getDefaultFieldValues(),
|
...this.getDefaultFieldValues(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Listen for the user to login/logout.
|
|
||||||
this.autorun(() => {
|
|
||||||
|
|
||||||
// Add the services list to the user.
|
|
||||||
this.subscribe('servicesList');
|
|
||||||
this.setState({
|
|
||||||
user: Accounts.user()
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps, nextContext) {
|
componentWillReceiveProps(nextProps, nextContext) {
|
||||||
|
@ -99,13 +97,20 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps, prevState) {
|
componentDidUpdate(prevProps, prevState) {
|
||||||
if (!prevState.user !== !this.state.user) {
|
if (!prevProps.user !== !this.props.user) {
|
||||||
this.setState({
|
this.setState({
|
||||||
formState: this.state.user ? STATES.PROFILE : STATES.SIGN_IN
|
formState: this.props.user ? STATES.PROFILE : STATES.SIGN_IN
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translate(text) {
|
||||||
|
// if (this.props.t) {
|
||||||
|
// return this.props.t(text);
|
||||||
|
// }
|
||||||
|
return T9n.get(text);
|
||||||
|
}
|
||||||
|
|
||||||
validateField(field, value) {
|
validateField(field, value) {
|
||||||
const { formState } = this.state;
|
const { formState } = this.state;
|
||||||
switch(field) {
|
switch(field) {
|
||||||
|
@ -131,8 +136,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getUsernameOrEmailField() {
|
getUsernameOrEmailField() {
|
||||||
return {
|
return {
|
||||||
id: 'usernameOrEmail',
|
id: 'usernameOrEmail',
|
||||||
hint: T9n.get('enterUsernameOrEmail'),
|
hint: this.translate('enterUsernameOrEmail'),
|
||||||
label: T9n.get('usernameOrEmail'),
|
label: this.translate('usernameOrEmail'),
|
||||||
required: true,
|
required: true,
|
||||||
defaultValue: this.state.username || "",
|
defaultValue: this.state.username || "",
|
||||||
onChange: this.handleChange.bind(this, 'usernameOrEmail'),
|
onChange: this.handleChange.bind(this, 'usernameOrEmail'),
|
||||||
|
@ -143,8 +148,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getUsernameField() {
|
getUsernameField() {
|
||||||
return {
|
return {
|
||||||
id: 'username',
|
id: 'username',
|
||||||
hint: T9n.get('enterUsername'),
|
hint: this.translate('enterUsername'),
|
||||||
label: T9n.get('username'),
|
label: this.translate('username'),
|
||||||
required: true,
|
required: true,
|
||||||
defaultValue: this.state.username || "",
|
defaultValue: this.state.username || "",
|
||||||
onChange: this.handleChange.bind(this, 'username'),
|
onChange: this.handleChange.bind(this, 'username'),
|
||||||
|
@ -155,8 +160,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getEmailField() {
|
getEmailField() {
|
||||||
return {
|
return {
|
||||||
id: 'email',
|
id: 'email',
|
||||||
hint: T9n.get('enterEmail'),
|
hint: this.translate('enterEmail'),
|
||||||
label: T9n.get('email'),
|
label: this.translate('email'),
|
||||||
type: 'email',
|
type: 'email',
|
||||||
required: true,
|
required: true,
|
||||||
defaultValue: this.state.email || "",
|
defaultValue: this.state.email || "",
|
||||||
|
@ -168,8 +173,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getPasswordField() {
|
getPasswordField() {
|
||||||
return {
|
return {
|
||||||
id: 'password',
|
id: 'password',
|
||||||
hint: T9n.get('enterPassword'),
|
hint: this.translate('enterPassword'),
|
||||||
label: T9n.get('password'),
|
label: this.translate('password'),
|
||||||
type: 'password',
|
type: 'password',
|
||||||
required: true,
|
required: true,
|
||||||
defaultValue: this.state.password || "",
|
defaultValue: this.state.password || "",
|
||||||
|
@ -181,8 +186,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getSetPasswordField() {
|
getSetPasswordField() {
|
||||||
return {
|
return {
|
||||||
id: 'newPassword',
|
id: 'newPassword',
|
||||||
hint: T9n.get('enterPassword'),
|
hint: this.translate('enterPassword'),
|
||||||
label: T9n.get('choosePassword'),
|
label: this.translate('choosePassword'),
|
||||||
type: 'password',
|
type: 'password',
|
||||||
required: true,
|
required: true,
|
||||||
onChange: this.handleChange.bind(this, 'newPassword')
|
onChange: this.handleChange.bind(this, 'newPassword')
|
||||||
|
@ -192,8 +197,8 @@ export class LoginForm extends Tracker.Component {
|
||||||
getNewPasswordField() {
|
getNewPasswordField() {
|
||||||
return {
|
return {
|
||||||
id: 'newPassword',
|
id: 'newPassword',
|
||||||
hint: T9n.get('enterNewPassword'),
|
hint: this.translate('enterNewPassword'),
|
||||||
label: T9n.get('newPassword'),
|
label: this.translate('newPassword'),
|
||||||
type: 'password',
|
type: 'password',
|
||||||
required: true,
|
required: true,
|
||||||
onChange: this.handleChange.bind(this, 'newPassword'),
|
onChange: this.handleChange.bind(this, 'newPassword'),
|
||||||
|
@ -225,11 +230,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPasswordService() && formState == STATES.SIGN_IN) {
|
if (hasPasswordService() && formState == STATES.SIGN_IN) {
|
||||||
if (_.contains([
|
if ([
|
||||||
"USERNAME_AND_EMAIL",
|
"USERNAME_AND_EMAIL",
|
||||||
"USERNAME_AND_OPTIONAL_EMAIL",
|
"USERNAME_AND_OPTIONAL_EMAIL",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getUsernameOrEmailField());
|
loginFields.push(this.getUsernameOrEmailField());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,48 +242,48 @@ export class LoginForm extends Tracker.Component {
|
||||||
loginFields.push(this.getUsernameField());
|
loginFields.push(this.getUsernameField());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.contains([
|
if ([
|
||||||
"EMAIL_ONLY",
|
"EMAIL_ONLY",
|
||||||
"EMAIL_ONLY_NO_PASSWORD"
|
"EMAIL_ONLY_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getEmailField());
|
loginFields.push(this.getEmailField());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_.contains([
|
if (![
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getPasswordField());
|
loginFields.push(this.getPasswordField());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPasswordService() && formState == STATES.SIGN_UP) {
|
if (hasPasswordService() && formState == STATES.SIGN_UP) {
|
||||||
if (_.contains([
|
if ([
|
||||||
"USERNAME_AND_EMAIL",
|
"USERNAME_AND_EMAIL",
|
||||||
"USERNAME_AND_OPTIONAL_EMAIL",
|
"USERNAME_AND_OPTIONAL_EMAIL",
|
||||||
"USERNAME_ONLY",
|
"USERNAME_ONLY",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getUsernameField());
|
loginFields.push(this.getUsernameField());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.contains([
|
if ([
|
||||||
"USERNAME_AND_EMAIL",
|
"USERNAME_AND_EMAIL",
|
||||||
"EMAIL_ONLY",
|
"EMAIL_ONLY",
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getEmailField());
|
loginFields.push(this.getEmailField());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.contains(["USERNAME_AND_OPTIONAL_EMAIL"], passwordSignupFields())) {
|
if (["USERNAME_AND_OPTIONAL_EMAIL"].includes(passwordSignupFields())) {
|
||||||
loginFields.push(Object.assign(this.getEmailField(), {required: false}));
|
loginFields.push(Object.assign(this.getEmailField(), {required: false}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_.contains([
|
if (![
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
loginFields.push(this.getPasswordField());
|
loginFields.push(this.getPasswordField());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,8 +302,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (this.showEnrollAccountForm()) {
|
if (this.showEnrollAccountForm()) {
|
||||||
loginFields.push(this.getSetPasswordField());
|
loginFields.push(this.getSetPasswordField());
|
||||||
}
|
}
|
||||||
|
return indexBy(loginFields, 'id');
|
||||||
return _.indexBy(loginFields, 'id');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons() {
|
buttons() {
|
||||||
|
@ -309,13 +313,14 @@ export class LoginForm extends Tracker.Component {
|
||||||
changePasswordPath = Accounts.ui._options.changePasswordPath,
|
changePasswordPath = Accounts.ui._options.changePasswordPath,
|
||||||
profilePath = Accounts.ui._options.profilePath,
|
profilePath = Accounts.ui._options.profilePath,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { formState, waiting, user } = this.state;
|
const { user } = this.props;
|
||||||
|
const { formState, waiting } = this.state;
|
||||||
let loginButtons = [];
|
let loginButtons = [];
|
||||||
|
|
||||||
if (user && formState == STATES.PROFILE) {
|
if (user && formState == STATES.PROFILE) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'signOut',
|
id: 'signOut',
|
||||||
label: T9n.get('signOut'),
|
label: this.translate('signOut'),
|
||||||
disabled: waiting,
|
disabled: waiting,
|
||||||
onClick: this.signOut.bind(this)
|
onClick: this.signOut.bind(this)
|
||||||
});
|
});
|
||||||
|
@ -324,7 +329,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (this.showCreateAccountLink()) {
|
if (this.showCreateAccountLink()) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'switchToSignUp',
|
id: 'switchToSignUp',
|
||||||
label: T9n.get('signUp'),
|
label: this.translate('signUp'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: signUpPath,
|
href: signUpPath,
|
||||||
onClick: this.switchToSignUp.bind(this)
|
onClick: this.switchToSignUp.bind(this)
|
||||||
|
@ -334,7 +339,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (formState == STATES.SIGN_UP || formState == STATES.PASSWORD_RESET) {
|
if (formState == STATES.SIGN_UP || formState == STATES.PASSWORD_RESET) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'switchToSignIn',
|
id: 'switchToSignIn',
|
||||||
label: T9n.get('signIn'),
|
label: this.translate('signIn'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: loginPath,
|
href: loginPath,
|
||||||
onClick: this.switchToSignIn.bind(this)
|
onClick: this.switchToSignIn.bind(this)
|
||||||
|
@ -344,22 +349,22 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (this.showForgotPasswordLink()) {
|
if (this.showForgotPasswordLink()) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'switchToPasswordReset',
|
id: 'switchToPasswordReset',
|
||||||
label: T9n.get('forgotPassword'),
|
label: this.translate('forgotPassword'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: resetPasswordPath,
|
href: resetPasswordPath,
|
||||||
onClick: this.switchToPasswordReset.bind(this)
|
onClick: this.switchToPasswordReset.bind(this)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user && !_.contains([
|
if (user && ![
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())
|
].includes(passwordSignupFields())
|
||||||
&& formState == STATES.PROFILE
|
&& formState == STATES.PROFILE
|
||||||
&& (user.services && 'password' in user.services)) {
|
&& (user.services && 'password' in user.services)) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'switchToChangePassword',
|
id: 'switchToChangePassword',
|
||||||
label: T9n.get('changePassword'),
|
label: this.translate('changePassword'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: changePasswordPath,
|
href: changePasswordPath,
|
||||||
onClick: this.switchToChangePassword.bind(this)
|
onClick: this.switchToChangePassword.bind(this)
|
||||||
|
@ -369,7 +374,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (formState == STATES.SIGN_UP) {
|
if (formState == STATES.SIGN_UP) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'signUp',
|
id: 'signUp',
|
||||||
label: T9n.get('signUp'),
|
label: this.translate('signUp'),
|
||||||
type: hasPasswordService() ? 'submit' : 'link',
|
type: hasPasswordService() ? 'submit' : 'link',
|
||||||
className: 'active',
|
className: 'active',
|
||||||
disabled: waiting,
|
disabled: waiting,
|
||||||
|
@ -380,7 +385,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (this.showSignInLink()) {
|
if (this.showSignInLink()) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'signIn',
|
id: 'signIn',
|
||||||
label: T9n.get('signIn'),
|
label: this.translate('signIn'),
|
||||||
type: hasPasswordService() ? 'submit' : 'link',
|
type: hasPasswordService() ? 'submit' : 'link',
|
||||||
className: 'active',
|
className: 'active',
|
||||||
disabled: waiting,
|
disabled: waiting,
|
||||||
|
@ -391,7 +396,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (formState == STATES.PASSWORD_RESET) {
|
if (formState == STATES.PASSWORD_RESET) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'emailResetLink',
|
id: 'emailResetLink',
|
||||||
label: T9n.get('resetYourPassword'),
|
label: this.translate('resetYourPassword'),
|
||||||
type: 'submit',
|
type: 'submit',
|
||||||
disabled: waiting,
|
disabled: waiting,
|
||||||
onClick: this.passwordReset.bind(this)
|
onClick: this.passwordReset.bind(this)
|
||||||
|
@ -401,7 +406,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (this.showPasswordChangeForm() || this.showEnrollAccountForm()) {
|
if (this.showPasswordChangeForm() || this.showEnrollAccountForm()) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'changePassword',
|
id: 'changePassword',
|
||||||
label: (this.showPasswordChangeForm() ? T9n.get('changePassword') : T9n.get('setPassword')),
|
label: (this.showPasswordChangeForm() ? this.translate('changePassword') : this.translate('setPassword')),
|
||||||
type: 'submit',
|
type: 'submit',
|
||||||
disabled: waiting,
|
disabled: waiting,
|
||||||
onClick: this.passwordChange.bind(this)
|
onClick: this.passwordChange.bind(this)
|
||||||
|
@ -410,7 +415,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (Accounts.user()) {
|
if (Accounts.user()) {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'switchToSignOut',
|
id: 'switchToSignOut',
|
||||||
label: T9n.get('cancel'),
|
label: this.translate('cancel'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
href: profilePath,
|
href: profilePath,
|
||||||
onClick: this.switchToSignOut.bind(this)
|
onClick: this.switchToSignOut.bind(this)
|
||||||
|
@ -418,7 +423,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
} else {
|
} else {
|
||||||
loginButtons.push({
|
loginButtons.push({
|
||||||
id: 'cancelResetPassword',
|
id: 'cancelResetPassword',
|
||||||
label: T9n.get('cancel'),
|
label: this.translate('cancel'),
|
||||||
type: 'link',
|
type: 'link',
|
||||||
onClick: this.cancelResetPassword.bind(this),
|
onClick: this.cancelResetPassword.bind(this),
|
||||||
});
|
});
|
||||||
|
@ -435,7 +440,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
b.type != undefined);
|
b.type != undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
return _.indexBy(loginButtons, 'id');
|
return indexBy(loginButtons, 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
showSignInLink(){
|
showSignInLink(){
|
||||||
|
@ -457,11 +462,9 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
showForgotPasswordLink() {
|
showForgotPasswordLink() {
|
||||||
return !this.state.user
|
return !this.props.user
|
||||||
&& this.state.formState == STATES.SIGN_IN
|
&& this.state.formState == STATES.SIGN_IN
|
||||||
&& _.contains(
|
&& ["USERNAME_AND_EMAIL", "USERNAME_AND_OPTIONAL_EMAIL", "EMAIL_ONLY"].includes(passwordSignupFields());
|
||||||
["USERNAME_AND_EMAIL", "USERNAME_AND_OPTIONAL_EMAIL", "EMAIL_ONLY"],
|
|
||||||
passwordSignupFields());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -587,7 +590,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_.contains([ "USERNAME_AND_EMAIL_NO_PASSWORD" ], passwordSignupFields())) {
|
if (["USERNAME_AND_EMAIL_NO_PASSWORD"].includes(passwordSignupFields())) {
|
||||||
this.loginWithoutPassword();
|
this.loginWithoutPassword();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -610,7 +613,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_.contains([ "EMAIL_ONLY_NO_PASSWORD" ], passwordSignupFields())) {
|
if (["EMAIL_ONLY_NO_PASSWORD"].includes(passwordSignupFields())) {
|
||||||
this.loginWithoutPassword();
|
this.loginWithoutPassword();
|
||||||
error = true;
|
error = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -618,7 +621,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_.contains([ "EMAIL_ONLY_NO_PASSWORD" ], passwordSignupFields())
|
if (!["EMAIL_ONLY_NO_PASSWORD"].includes(passwordSignupFields())
|
||||||
&& !this.validateField('password', password)) {
|
&& !this.validateField('password', password)) {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
|
@ -627,7 +630,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
Meteor.loginWithPassword(loginSelector, password, (error, result) => {
|
||||||
onSubmitHook(error,formState);
|
onSubmitHook(error,formState);
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loginResultCallback(() => this.state.onSignedInHook());
|
loginResultCallback(() => this.state.onSignedInHook());
|
||||||
|
@ -658,11 +661,12 @@ export class LoginForm extends Tracker.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _.indexBy(oauthButtons, 'id');
|
return indexBy(oauthButtons, 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
oauthSignIn(serviceName) {
|
oauthSignIn(serviceName) {
|
||||||
const { formState, waiting, user, onSubmitHook } = this.state;
|
const { user } = this.props;
|
||||||
|
const { formState, waiting, 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);
|
||||||
|
@ -683,10 +687,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
options.forceApprovalPrompt = Accounts.ui._options.forceApprovalPrompt[serviceName];
|
options.forceApprovalPrompt = Accounts.ui._options.forceApprovalPrompt[serviceName];
|
||||||
|
|
||||||
this.clearMessages();
|
this.clearMessages();
|
||||||
|
const self = this
|
||||||
loginWithService(options, (error) => {
|
loginWithService(options, (error) => {
|
||||||
onSubmitHook(error,formState);
|
onSubmitHook(error,formState);
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"));
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error");
|
||||||
} else {
|
} else {
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
this.clearDefaultFieldValues();
|
this.clearDefaultFieldValues();
|
||||||
|
@ -720,10 +725,10 @@ export class LoginForm extends Tracker.Component {
|
||||||
options.username = username;
|
options.username = username;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_.contains([
|
if ([
|
||||||
"USERNAME_AND_EMAIL",
|
"USERNAME_AND_EMAIL",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields()) && !this.validateField('username', username) ) {
|
].includes(passwordSignupFields()) && !this.validateField('username', username) ) {
|
||||||
if (this.state.formState == STATES.SIGN_UP) {
|
if (this.state.formState == STATES.SIGN_UP) {
|
||||||
this.state.onSubmitHook("error.accounts.usernameRequired", this.state.formState);
|
this.state.onSubmitHook("error.accounts.usernameRequired", this.state.formState);
|
||||||
}
|
}
|
||||||
|
@ -737,10 +742,10 @@ export class LoginForm extends Tracker.Component {
|
||||||
options.email = email;
|
options.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_.contains([
|
if ([
|
||||||
"EMAIL_ONLY_NO_PASSWORD",
|
"EMAIL_ONLY_NO_PASSWORD",
|
||||||
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
"USERNAME_AND_EMAIL_NO_PASSWORD"
|
||||||
], passwordSignupFields())) {
|
].includes(passwordSignupFields())) {
|
||||||
// Generate a random password.
|
// Generate a random password.
|
||||||
options.password = Meteor.uuid();
|
options.password = Meteor.uuid();
|
||||||
} else if (!this.validateField('password', password)) {
|
} else if (!this.validateField('password', password)) {
|
||||||
|
@ -753,12 +758,12 @@ export class LoginForm extends Tracker.Component {
|
||||||
const SignUp = function(_options) {
|
const SignUp = function(_options) {
|
||||||
Accounts.createUser(_options, (error) => {
|
Accounts.createUser(_options, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
if (T9n.get(`error.accounts.${error.reason}`)) {
|
if (this.translate(`error.accounts.${error.reason}`)) {
|
||||||
onSubmitHook(`error.accounts.${error.reason}`, formState);
|
onSubmitHook(`error.accounts.${error.reason}`, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
onSubmitHook("Unknown error", formState);
|
onSubmitHook("unknown_error", formState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -804,10 +809,10 @@ export class LoginForm extends Tracker.Component {
|
||||||
|
|
||||||
Accounts.loginWithoutPassword({ email: email }, (error) => {
|
Accounts.loginWithoutPassword({ email: email }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(this.translate("info.emailSent"), 'success', 5000);
|
||||||
this.clearDefaultFieldValues();
|
this.clearDefaultFieldValues();
|
||||||
}
|
}
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
|
@ -818,10 +823,10 @@ export class LoginForm extends Tracker.Component {
|
||||||
|
|
||||||
Accounts.loginWithoutPassword({ email: usernameOrEmail, username: usernameOrEmail }, (error) => {
|
Accounts.loginWithoutPassword({ email: usernameOrEmail, username: usernameOrEmail }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(this.translate("info.emailSent"), 'success', 5000);
|
||||||
this.clearDefaultFieldValues();
|
this.clearDefaultFieldValues();
|
||||||
}
|
}
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
|
@ -829,11 +834,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let errMsg = null;
|
let errMsg = null;
|
||||||
if (_.contains([ "USERNAME_AND_EMAIL_NO_PASSWORD" ], passwordSignupFields())) {
|
if (["USERNAME_AND_EMAIL_NO_PASSWORD"].includes(passwordSignupFields())) {
|
||||||
errMsg = T9n.get("error.accounts.Invalid email or username");
|
errMsg = this.translate("error.accounts.invalid_email");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
errMsg = T9n.get("error.accounts.Invalid email");
|
errMsg = this.translate("error.accounts.invalid_email");
|
||||||
}
|
}
|
||||||
this.showMessage(errMsg,'warning');
|
this.showMessage(errMsg,'warning');
|
||||||
onSubmitHook(errMsg, formState);
|
onSubmitHook(errMsg, formState);
|
||||||
|
@ -858,10 +863,10 @@ export class LoginForm extends Tracker.Component {
|
||||||
|
|
||||||
Accounts.forgotPassword({ email: email }, (error) => {
|
Accounts.forgotPassword({ email: email }, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
this.showMessage(T9n.get(`error.accounts.${error.reason}`) || T9n.get("Unknown error"), 'error');
|
this.showMessage(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get("info.emailSent"), 'success', 5000);
|
this.showMessage(this.translate("info.emailSent"), 'success', 5000);
|
||||||
this.clearDefaultFieldValues();
|
this.clearDefaultFieldValues();
|
||||||
}
|
}
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
|
@ -891,11 +896,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
if (token) {
|
if (token) {
|
||||||
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(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
this.showMessage(this.translate('info.passwordChanged'), 'success', 5000);
|
||||||
onSubmitHook(null, formState);
|
onSubmitHook(null, formState);
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
Accounts._loginButtonsSession.set('resetPasswordToken', null);
|
Accounts._loginButtonsSession.set('resetPasswordToken', null);
|
||||||
|
@ -907,11 +912,11 @@ export class LoginForm extends Tracker.Component {
|
||||||
else {
|
else {
|
||||||
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(`error.accounts.${error.reason}` || "unknown_error", 'error');
|
||||||
onSubmitHook(error, formState);
|
onSubmitHook(error, formState);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.showMessage(T9n.get('info.passwordChanged'), 'success', 5000);
|
this.showMessage('info.passwordChanged', 'success', 5000);
|
||||||
onSubmitHook(null, formState);
|
onSubmitHook(null, formState);
|
||||||
this.setState({ formState: STATES.PROFILE });
|
this.setState({ formState: STATES.PROFILE });
|
||||||
this.clearDefaultFieldValues();
|
this.clearDefaultFieldValues();
|
||||||
|
@ -921,7 +926,7 @@ export class LoginForm extends Tracker.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
showMessage(message, type, clearTimeout, field){
|
showMessage(message, type, clearTimeout, field){
|
||||||
message = message.trim();
|
message = this.translate(message).trim();
|
||||||
if (message) {
|
if (message) {
|
||||||
this.setState(({ messages = [] }) => {
|
this.setState(({ messages = [] }) => {
|
||||||
messages.push({
|
messages.push({
|
||||||
|
@ -994,9 +999,34 @@ export class LoginForm extends Tracker.Component {
|
||||||
buttons={this.buttons()}
|
buttons={this.buttons()}
|
||||||
{...this.state}
|
{...this.state}
|
||||||
message={message}
|
message={message}
|
||||||
|
translate={text => this.translate(text)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LoginForm.propTypes = {
|
||||||
|
formState: PropTypes.symbol,
|
||||||
|
loginPath: PropTypes.string,
|
||||||
|
signUpPath: PropTypes.string,
|
||||||
|
resetPasswordPath: PropTypes.string,
|
||||||
|
profilePath: PropTypes.string,
|
||||||
|
changePasswordPath: PropTypes.string,
|
||||||
|
};
|
||||||
|
LoginForm.defaultProps = {
|
||||||
|
formState: null,
|
||||||
|
loginPath: null,
|
||||||
|
signUpPath: null,
|
||||||
|
resetPasswordPath: null,
|
||||||
|
profilePath: null,
|
||||||
|
changePasswordPath: null,
|
||||||
|
};
|
||||||
|
|
||||||
Accounts.ui.LoginForm = LoginForm;
|
Accounts.ui.LoginForm = LoginForm;
|
||||||
|
|
||||||
|
export default createContainer(() => {
|
||||||
|
// Listen for the user to login/logout and the services list to the user.
|
||||||
|
Meteor.subscribe('servicesList');
|
||||||
|
return ({
|
||||||
|
user: Accounts.user(),
|
||||||
|
});
|
||||||
|
}, LoginForm);
|
||||||
|
|
|
@ -5,10 +5,6 @@ import { T9n } from 'meteor/softwarerero:accounts-t9n';
|
||||||
import { hasPasswordService } from '../../helpers.js';
|
import { hasPasswordService } from '../../helpers.js';
|
||||||
|
|
||||||
export class PasswordOrService extends React.Component {
|
export class PasswordOrService extends React.Component {
|
||||||
propTypes: {
|
|
||||||
oauthServices: PropTypes.object
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
|
@ -19,6 +15,13 @@ export class PasswordOrService extends React.Component {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
translate(text) {
|
||||||
|
if (this.props.translate) {
|
||||||
|
return this.props.translate(text);
|
||||||
|
}
|
||||||
|
return T9n.get(text);
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { className = "password-or-service", style = {} } = this.props;
|
let { className = "password-or-service", style = {} } = this.props;
|
||||||
let { hasPasswordService, services } = this.state;
|
let { hasPasswordService, services } = this.state;
|
||||||
|
@ -30,7 +33,7 @@ export class PasswordOrService extends React.Component {
|
||||||
if (hasPasswordService && services.length > 0) {
|
if (hasPasswordService && services.length > 0) {
|
||||||
return (
|
return (
|
||||||
<div style={ style } className={ className }>
|
<div style={ style } className={ className }>
|
||||||
{ `${T9n.get('orUse')} ${ labels.join(' / ') }` }
|
{ `${this.translate('orUse')} ${ labels.join(' / ') }` }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,4 +41,8 @@ export class PasswordOrService extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PasswordOrService.propTypes = {
|
||||||
|
oauthServices: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
Accounts.ui.PasswordOrService = PasswordOrService;
|
Accounts.ui.PasswordOrService = PasswordOrService;
|
||||||
|
|
|
@ -3,8 +3,10 @@ import './imports/accounts_ui.js';
|
||||||
import './imports/login_session.js';
|
import './imports/login_session.js';
|
||||||
import { STATES } from './imports/helpers.js';
|
import { STATES } from './imports/helpers.js';
|
||||||
import './imports/api/client/loginWithoutPassword.js';
|
import './imports/api/client/loginWithoutPassword.js';
|
||||||
|
import LoginForm from './imports/ui/components/LoginForm.jsx';
|
||||||
|
|
||||||
import './imports/ui/components/LoginForm.jsx';
|
export {
|
||||||
|
LoginForm as default,
|
||||||
export { Accounts, STATES };
|
Accounts,
|
||||||
export default Accounts;
|
STATES,
|
||||||
|
};
|
||||||
|
|
|
@ -4,8 +4,10 @@ import './imports/login_session.js';
|
||||||
import { redirect, STATES } from './imports/helpers.js';
|
import { redirect, STATES } from './imports/helpers.js';
|
||||||
import './imports/api/server/loginWithoutPassword.js';
|
import './imports/api/server/loginWithoutPassword.js';
|
||||||
import './imports/api/server/servicesListPublication.js';
|
import './imports/api/server/servicesListPublication.js';
|
||||||
|
import LoginForm from './imports/ui/components/LoginForm.jsx';
|
||||||
|
|
||||||
import './imports/ui/components/LoginForm.jsx';
|
export {
|
||||||
|
LoginForm as default,
|
||||||
export { Accounts, redirect, STATES };
|
Accounts,
|
||||||
export default Accounts;
|
STATES,
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Package.describe({
|
Package.describe({
|
||||||
name: 'std:accounts-ui',
|
name: 'std:accounts-ui',
|
||||||
version: '1.2.20',
|
version: '1.2.22',
|
||||||
summary: 'Accounts UI for React in Meteor 1.3+',
|
summary: 'Accounts UI for React in Meteor 1.3+',
|
||||||
git: 'https://github.com/studiointeract/accounts-ui',
|
git: 'https://github.com/studiointeract/accounts-ui',
|
||||||
documentation: 'README.md'
|
documentation: 'README.md'
|
||||||
|
@ -9,13 +9,12 @@ Package.describe({
|
||||||
Package.onUse(function(api) {
|
Package.onUse(function(api) {
|
||||||
api.versionsFrom('1.3');
|
api.versionsFrom('1.3');
|
||||||
api.use('ecmascript');
|
api.use('ecmascript');
|
||||||
api.use('tracker');
|
|
||||||
api.use('underscore');
|
|
||||||
api.use('accounts-base');
|
api.use('accounts-base');
|
||||||
api.use('check');
|
api.use('check');
|
||||||
api.use('random');
|
api.use('random');
|
||||||
api.use('email');
|
api.use('email');
|
||||||
api.use('session');
|
api.use('session');
|
||||||
|
api.use('react-meteor-data@0.2.11');
|
||||||
api.use('softwarerero:accounts-t9n');
|
api.use('softwarerero:accounts-t9n');
|
||||||
api.use('tmeasday:check-npm-versions@0.3.0');
|
api.use('tmeasday:check-npm-versions@0.3.0');
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
"prop-types": "^15.5.8"
|
"prop-types": "^15.5.8"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"react": ">=0.14.7 || ^15.0.0",
|
"react": "^15.0.0",
|
||||||
"react-dom": ">=0.14.7 || ^15.0.0",
|
"react-dom": "^15.0.0",
|
||||||
"tracker-component": "^1.3.16"
|
"react-addons-pure-render-mixin": "^15.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue