Compare commits
2 commits
3849566772
...
743f08189c
Author | SHA1 | Date | |
---|---|---|---|
|
743f08189c | ||
|
34aab31921 |
7 changed files with 79 additions and 49 deletions
|
@ -8,7 +8,7 @@ import Button from '../../../common/Button';
|
||||||
function SignupForm(props) {
|
function SignupForm(props) {
|
||||||
const {
|
const {
|
||||||
fields: {
|
fields: {
|
||||||
username, email, password, confirmPassword
|
username, /* email, */ password, confirmPassword
|
||||||
},
|
},
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
submitting,
|
submitting,
|
||||||
|
@ -33,7 +33,7 @@ function SignupForm(props) {
|
||||||
<span className="form-error">{username.error}</span>
|
<span className="form-error">{username.error}</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<p className="form__field">
|
{/* <p className="form__field">
|
||||||
<label htmlFor="email" className="form__label">{props.t('SignupForm.Email')}</label>
|
<label htmlFor="email" className="form__label">{props.t('SignupForm.Email')}</label>
|
||||||
<input
|
<input
|
||||||
className="form__input"
|
className="form__input"
|
||||||
|
@ -45,7 +45,7 @@ function SignupForm(props) {
|
||||||
{email.touched && email.error && (
|
{email.touched && email.error && (
|
||||||
<span className="form-error">{email.error}</span>
|
<span className="form-error">{email.error}</span>
|
||||||
)}
|
)}
|
||||||
</p>
|
</p> */}
|
||||||
<p className="form__field">
|
<p className="form__field">
|
||||||
<label htmlFor="password" className="form__label">{props.t('SignupForm.Password')}</label>
|
<label htmlFor="password" className="form__label">{props.t('SignupForm.Password')}</label>
|
||||||
<input
|
<input
|
||||||
|
@ -84,7 +84,7 @@ function SignupForm(props) {
|
||||||
SignupForm.propTypes = {
|
SignupForm.propTypes = {
|
||||||
fields: PropTypes.shape({
|
fields: PropTypes.shape({
|
||||||
username: PropTypes.object.isRequired, // eslint-disable-line
|
username: PropTypes.object.isRequired, // eslint-disable-line
|
||||||
email: PropTypes.object.isRequired, // eslint-disable-line
|
// email: PropTypes.object.isRequired, // eslint-disable-line
|
||||||
password: PropTypes.object.isRequired, // eslint-disable-line
|
password: PropTypes.object.isRequired, // eslint-disable-line
|
||||||
confirmPassword: PropTypes.object.isRequired, // eslint-disable-line
|
confirmPassword: PropTypes.object.isRequired, // eslint-disable-line
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
|
|
@ -9,9 +9,9 @@ import * as UserActions from '../actions';
|
||||||
import SignupForm from '../components/SignupForm';
|
import SignupForm from '../components/SignupForm';
|
||||||
import apiClient from '../../../utils/apiClient';
|
import apiClient from '../../../utils/apiClient';
|
||||||
import { validateSignup } from '../../../utils/reduxFormUtils';
|
import { validateSignup } from '../../../utils/reduxFormUtils';
|
||||||
import SocialAuthButton from '../components/SocialAuthButton';
|
// import SocialAuthButton from '../components/SocialAuthButton';
|
||||||
import Nav from '../../../components/Nav';
|
import Nav from '../../../components/Nav';
|
||||||
import ResponsiveForm from '../components/ResponsiveForm';
|
// import ResponsiveForm from '../components/ResponsiveForm';
|
||||||
|
|
||||||
|
|
||||||
class SignupView extends React.Component {
|
class SignupView extends React.Component {
|
||||||
|
@ -123,9 +123,9 @@ SignupView.defaultProps = {
|
||||||
|
|
||||||
export default withTranslation()(reduxForm({
|
export default withTranslation()(reduxForm({
|
||||||
form: 'signup',
|
form: 'signup',
|
||||||
fields: ['username', 'email', 'password', 'confirmPassword'],
|
fields: ['username', /* 'email', */ 'password', 'confirmPassword'],
|
||||||
onSubmitFail,
|
onSubmitFail,
|
||||||
validate: validateSignup,
|
validate: validateSignup,
|
||||||
asyncValidate,
|
asyncValidate,
|
||||||
asyncBlurFields: ['username', 'email']
|
asyncBlurFields: ['username'/* , 'email' */]
|
||||||
}, mapStateToProps, mapDispatchToProps)(SignupView));
|
}, mapStateToProps, mapDispatchToProps)(SignupView));
|
||||||
|
|
|
@ -28,9 +28,11 @@ function validateNameEmail(formProps, errors) {
|
||||||
errors.username = i18n.t('ReduxFormUtils.errorValidUsername');
|
errors.username = i18n.t('ReduxFormUtils.errorValidUsername');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!formProps.email) {
|
// if (!formProps.email) {
|
||||||
errors.email = i18n.t('ReduxFormUtils.errorEmptyEmail');
|
// errors.email = i18n.t('ReduxFormUtils.errorEmptyEmail');
|
||||||
} else if (
|
// } else
|
||||||
|
if (
|
||||||
|
formProps.email &&
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
!formProps.email.match(EMAIL_REGEX)) {
|
!formProps.email.match(EMAIL_REGEX)) {
|
||||||
errors.email = i18n.t('ReduxFormUtils.errorInvalidEmail');
|
errors.email = i18n.t('ReduxFormUtils.errorInvalidEmail');
|
||||||
|
|
26
docker-entrypoint.sh
Normal file
26
docker-entrypoint.sh
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "HALLO!"
|
||||||
|
echo "Starting the mongodb daemon"
|
||||||
|
/usr/bin/mongod --fork --syslog
|
||||||
|
|
||||||
|
# echo "navigating to volume /var/www"
|
||||||
|
# cd /var/www
|
||||||
|
# echo "Creating soft link"
|
||||||
|
# ln -s /opt/mysite mysite
|
||||||
|
|
||||||
|
# a2enmod headers
|
||||||
|
# service apache2 restart
|
||||||
|
|
||||||
|
# a2ensite mysite.conf
|
||||||
|
# a2dissite 000-default.conf
|
||||||
|
# service apache2 reload
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
exec npm run start:prod
|
||||||
|
else
|
||||||
|
exec "$1"
|
||||||
|
fi
|
|
@ -24,7 +24,7 @@ passport.deserializeUser((id, done) => {
|
||||||
* Sign in using Email/Username and Password.
|
* Sign in using Email/Username and Password.
|
||||||
*/
|
*/
|
||||||
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
|
passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => {
|
||||||
User.findByEmailOrUsername(email)
|
User.findByUsername(email)
|
||||||
.then((user) => { // eslint-disable-line consistent-return
|
.then((user) => { // eslint-disable-line consistent-return
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return done(null, false, { msg: `Email ${email} not found.` });
|
return done(null, false, { msg: `Email ${email} not found.` });
|
||||||
|
|
|
@ -12,7 +12,7 @@ export * from './user.controller/apiKey';
|
||||||
|
|
||||||
export function userResponse(user) {
|
export function userResponse(user) {
|
||||||
return {
|
return {
|
||||||
email: user.email,
|
// email: user.email,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
preferences: user.preferences,
|
preferences: user.preferences,
|
||||||
apiKeys: user.apiKeys,
|
apiKeys: user.apiKeys,
|
||||||
|
@ -36,31 +36,32 @@ export function findUserByUsername(username, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUser(req, res, next) {
|
export function createUser(req, res, next) {
|
||||||
const { username, email } = req.body;
|
const { username, _ } = req.body;
|
||||||
const { password } = req.body;
|
const { password } = req.body;
|
||||||
const emailLowerCase = email.toLowerCase();
|
// const emailLowerCase = email ? email.toLowerCase() : null;
|
||||||
const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date.now() + (3600000 * 24); // 24 hours
|
const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date.now() + (3600000 * 24); // 24 hours
|
||||||
random((tokenError, token) => {
|
random((tokenError, token) => {
|
||||||
const user = new User({
|
const user = new User({
|
||||||
username,
|
username,
|
||||||
email: emailLowerCase,
|
// email: emailLowerCase,
|
||||||
password,
|
password,
|
||||||
verified: User.EmailConfirmation.Sent,
|
verified: User.EmailConfirmation.Sent,
|
||||||
verifiedToken: token,
|
verifiedToken: token,
|
||||||
verifiedTokenExpires: EMAIL_VERIFY_TOKEN_EXPIRY_TIME,
|
verifiedTokenExpires: EMAIL_VERIFY_TOKEN_EXPIRY_TIME,
|
||||||
});
|
});
|
||||||
|
|
||||||
User.findByEmailAndUsername(email, username, (err, existingUser) => {
|
User.findByUsername(username, (err, existingUser) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(404).send({ error: err });
|
res.status(404).send({ error: err });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingUser) {
|
if (existingUser) {
|
||||||
const fieldInUse = existingUser.email.toLowerCase() === emailLowerCase ? 'Email' : 'Username';
|
const fieldInUse = 'Username';
|
||||||
res.status(422).send({ error: `${fieldInUse} is in use` });
|
res.status(422).send({ error: `${fieldInUse} is in use` });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user.save((saveErr) => {
|
user.save((saveErr) => {
|
||||||
if (saveErr) {
|
if (saveErr) {
|
||||||
next(saveErr);
|
next(saveErr);
|
||||||
|
@ -73,17 +74,17 @@ export function createUser(req, res, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
||||||
const mailOptions = renderEmailConfirmation({
|
// const mailOptions = renderEmailConfirmation({
|
||||||
body: {
|
// body: {
|
||||||
domain: `${protocol}://${req.headers.host}`,
|
// domain: `${protocol}://${req.headers.host}`,
|
||||||
link: `${protocol}://${req.headers.host}/verify?t=${token}`
|
// link: `${protocol}://${req.headers.host}/verify?t=${token}`
|
||||||
},
|
// },
|
||||||
to: req.user.email,
|
// to: req.user.email,
|
||||||
});
|
// });
|
||||||
|
|
||||||
mail.send(mailOptions, (mailErr, result) => { // eslint-disable-line no-unused-vars
|
// mail.send(mailOptions, (mailErr, result) => { // eslint-disable-line no-unused-vars
|
||||||
res.json(userResponse(req.user));
|
res.json(userResponse(req.user));
|
||||||
});
|
// });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -142,18 +143,19 @@ export function resetPasswordInitiate(req, res) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
random,
|
random,
|
||||||
(token, done) => {
|
(token, done) => {
|
||||||
User.findByEmail(req.body.email, (err, user) => {
|
// disable since we don't use email
|
||||||
if (!user) {
|
// User.findByEmail(req.body.email, (err, user) => {
|
||||||
res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' });
|
// if (!user) {
|
||||||
return;
|
// res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' });
|
||||||
}
|
// return;
|
||||||
user.resetPasswordToken = token;
|
// }
|
||||||
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
|
// user.resetPasswordToken = token;
|
||||||
|
// user.resetPasswordExpires = Date.now() + 3600000; // 1 hour
|
||||||
|
|
||||||
user.save((saveErr) => {
|
// user.save((saveErr) => {
|
||||||
done(saveErr, token, user);
|
// done(saveErr, token, user);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
},
|
},
|
||||||
(token, user, done) => {
|
(token, user, done) => {
|
||||||
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http';
|
||||||
|
|
|
@ -50,7 +50,7 @@ const userSchema = new Schema({
|
||||||
verifiedToken: String,
|
verifiedToken: String,
|
||||||
verifiedTokenExpires: Date,
|
verifiedTokenExpires: Date,
|
||||||
github: { type: String },
|
github: { type: String },
|
||||||
email: { type: String, unique: true },
|
email: { type: String },
|
||||||
tokens: Array,
|
tokens: Array,
|
||||||
apiKeys: { type: [apiKeySchema] },
|
apiKeys: { type: [apiKeySchema] },
|
||||||
preferences: {
|
preferences: {
|
||||||
|
@ -192,10 +192,10 @@ userSchema.statics.findByUsername = function findByUsername(username, cb) {
|
||||||
* @return {Promise<Object>} - Returns Promise fulfilled by User document
|
* @return {Promise<Object>} - Returns Promise fulfilled by User document
|
||||||
*/
|
*/
|
||||||
userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, cb) {
|
userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value, cb) {
|
||||||
const isEmail = value.indexOf('@') > -1;
|
// const isEmail = value.indexOf('@') > -1;
|
||||||
if (isEmail) {
|
// if (isEmail) {
|
||||||
return this.findByEmail(value, cb);
|
// return this.findByEmail(value, cb);
|
||||||
}
|
// }
|
||||||
return this.findByUsername(value, cb);
|
return this.findByUsername(value, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -210,11 +210,11 @@ userSchema.statics.findByEmailOrUsername = function findByEmailOrUsername(value,
|
||||||
* @return {Promise<Object>} - Returns Promise fulfilled by User document
|
* @return {Promise<Object>} - Returns Promise fulfilled by User document
|
||||||
*/
|
*/
|
||||||
userSchema.statics.findByEmailAndUsername = function findByEmailAndUsername(email, username, cb) {
|
userSchema.statics.findByEmailAndUsername = function findByEmailAndUsername(email, username, cb) {
|
||||||
const query = {
|
const query = { username // override username only as we don't want to register email addresses
|
||||||
$or: [
|
// $or: [
|
||||||
{ email },
|
// { email },
|
||||||
{ username }
|
// { username }
|
||||||
]
|
// ]
|
||||||
};
|
};
|
||||||
return this.findOne(query).collation({ locale: 'en', strength: 2 }).exec(cb);
|
return this.findOne(query).collation({ locale: 'en', strength: 2 }).exec(cb);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue