Change update email endpoint

This commit is contained in:
Berkeley Martinez
2016-05-02 17:20:41 -07:00
parent 5830d69613
commit e65d55a3f7
3 changed files with 16 additions and 18 deletions

View File

@ -308,20 +308,18 @@ module.exports = function(User) {
User.prototype.updateEmail = function updateEmail(email) { User.prototype.updateEmail = function updateEmail(email) {
if (this.email && this.email === email) { if (this.email && this.email === email) {
debug('same email as current User', email);
return Promise.reject(new Error( return Promise.reject(new Error(
`${email} is already associated with this account.` `${email} is already associated with this account.`
)); ));
} }
return User.doesExist(null, email) return User.doesExist(null, email)
.then(exists => { .then(exists => {
if (!exists) { if (exists) {
return this.update$({ email }).toPromise(); return Promise.reject(
new Error(`${email} is already associated with another account.`)
);
} }
debug('same email as another User', email); return this.update$({ email }).toPromise();
return Promise.reject(new Error(
`${email} is already associated with an account.`
));
}); });
}; };
@ -344,7 +342,7 @@ module.exports = function(User) {
} }
], ],
http: { http: {
path: '/email-update', path: '/update-email',
verb: 'POST' verb: 'POST'
} }
} }

View File

@ -149,7 +149,7 @@ module.exports = function(app) {
router.get('/email-signup', getEmailSignup); router.get('/email-signup', getEmailSignup);
router.get('/email-signin', getEmailSignin); router.get('/email-signin', getEmailSignin);
router.get('/deprecated-signin', getDepSignin); router.get('/deprecated-signin', getDepSignin);
router.get('/email-update', getUpdateEmail); router.get('/update-email', getUpdateEmail);
router.get( router.get(
'/toggle-lockdown-mode', '/toggle-lockdown-mode',
sendNonUserToMap, sendNonUserToMap,

View File

@ -8,12 +8,12 @@ block content
span.ion-close-circled#flash-close span.ion-close-circled#flash-close
#flash-content #flash-content
h2.text-center Update your email address here: h2.text-center Update your email address here:
form.form-horizontal.email-update(method='POST', action='/api/users/#{user.id}/email-update', name="updateEmailForm") form.form-horizontal.email-update(method='POST', action='/api/users/#{user.id}/update-email', name="updateEmailForm")
.row .row
.col-sm-6.col-sm-offset-3 .col-sm-6.col-sm-offset-3
input(type='hidden', name='_csrf', value=_csrf) input(type='hidden', name='_csrf', value=_csrf)
.form-group .form-group
input.input-lg.form-control(type='email', name='email', id='email', placeholder='Enter your new email', autofocus, required, autocomplete="off") input.input-lg.form-control(type='email', name='email', id='email', value=user.email || '', placeholder=user.email || 'Enter your new email', autofocus, required, autocomplete="off")
.form-group .form-group
button.btn.btn-lg.btn-primary.btn-block(type='submit') button.btn.btn-lg.btn-primary.btn-block(type='submit')
| Update my Email | Update my Email
@ -41,7 +41,7 @@ block content
$('#flash-content').html(data.error.message); $('#flash-content').html(data.error.message);
$('#flash-board') $('#flash-board')
.removeClass('alert-success') .removeClass('alert-success')
.addClass('alert-danger') .addClass('alert-info')
.fadeIn(); .fadeIn();
} }
}) })