Merge branch 'fix/theme-flash' of https://github.com/BerkeleyTrue/FreeCodeCamp into BerkeleyTrue-fix/theme-flash
Conflicts: common/models/user.js
This commit is contained in:
@ -486,6 +486,91 @@ module.exports = function(User) {
|
||||
}
|
||||
);
|
||||
|
||||
User.prototype.updateEmail = function updateEmail(email) {
|
||||
if (this.email && this.email === email) {
|
||||
return Promise.reject(new Error(
|
||||
`${email} is already associated with this account.`
|
||||
));
|
||||
}
|
||||
return User.doesExist(null, email)
|
||||
.then(exists => {
|
||||
if (exists) {
|
||||
return Promise.reject(
|
||||
new Error(`${email} is already associated with another account.`)
|
||||
);
|
||||
}
|
||||
return this.update$({ email }).toPromise();
|
||||
});
|
||||
};
|
||||
|
||||
User.remoteMethod(
|
||||
'updateEmail',
|
||||
{
|
||||
isStatic: false,
|
||||
description: 'updates the email of the user object',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
returns: [
|
||||
{
|
||||
arg: 'status',
|
||||
type: 'object'
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: '/update-email',
|
||||
verb: 'POST'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
User.themes = {
|
||||
night: true,
|
||||
default: true
|
||||
};
|
||||
User.prototype.updateTheme = function updateTheme(theme) {
|
||||
if (!this.constructor.themes[theme]) {
|
||||
const err = new Error(
|
||||
'Theme is not valid.'
|
||||
);
|
||||
err.messageType = 'info';
|
||||
err.userMessage = err.message;
|
||||
return Promise.reject(err);
|
||||
}
|
||||
return this.update$({ theme })
|
||||
.map({ updatedTo: theme })
|
||||
.toPromise();
|
||||
};
|
||||
|
||||
User.remoteMethod(
|
||||
'updateTheme',
|
||||
{
|
||||
isStatic: false,
|
||||
description: 'updates the users chosen theme',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'theme',
|
||||
type: 'string',
|
||||
required: true
|
||||
}
|
||||
],
|
||||
returns: [
|
||||
{
|
||||
arg: 'status',
|
||||
type: 'object'
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: '/update-theme',
|
||||
verb: 'POST'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// user.updateTo$(updateData: Object) => Observable[Number]
|
||||
User.prototype.update$ = function update$(updateData) {
|
||||
const id = this.getId();
|
||||
|
Reference in New Issue
Block a user