fix account link failure now flashes

This commit is contained in:
Berkeley Martinez
2015-08-18 14:48:22 -07:00
parent d9d44ae509
commit b2f4e520cb
3 changed files with 23 additions and 11 deletions

View File

@ -69,7 +69,7 @@
"lodash": "^3.9.3",
"loopback": "https://github.com/FreeCodeCamp/loopback.git#fix/no-password",
"loopback-boot": "^2.8.0",
"loopback-component-passport": "^1.5.0",
"loopback-component-passport": "https://github.com/FreeCodeCamp/loopback-component-passport.git#feature/flashfailure",
"loopback-connector-mongodb": "^1.10.0",
"lusca": "~1.0.2",
"method-override": "~2.3.0",

View File

@ -1,5 +1,9 @@
import{ Observable } from 'rx';
import { observeMethod, observeQuery } from '../utils/rx';
import { getSocialProvider } from '../utils/auth';
import debugFactory from 'debug';
const debug = debugFactory('fcc:userIdent');
export default function({ models }) {
const { User, UserIdentity, UserCredential } = models;
@ -20,15 +24,18 @@ export default function({ models }) {
options = {};
}
const user$ = findUserById(userId);
console.log('provider', provider);
console.log('id', profile.id);
findIdent({
provider: getSocialProvider(provider),
externalId: profile.id
})
const query = {
where: {
provider: getSocialProvider(provider),
externalId: profile.id
}
};
debug('link identity query', query);
findIdent(query)
.flatMap(identity => {
const modified = new Date();
if (!identity || identity.externalId !== profile.id) {
if (!identity) {
return observeQuery(UserIdentity, 'create', {
provider: getSocialProvider(provider),
externalId: profile.id,
@ -40,6 +47,11 @@ export default function({ models }) {
modified
});
}
if (identity.userId !== userId) {
return Observable.throw(
new Error('An account is already linked to that profile')
);
}
identity.credentials = credentials;
return observeQuery(identity, 'updateAttributes', {
profile: getSocialProvider(provider),

View File

@ -1,11 +1,11 @@
.row
.col-xs-12
if messages.errors
if (messages.errors || messages.error)
.alert.alert-danger.fade.in
button.close(type='button', data-dismiss='alert')
span.ion-close-circled
for error in messages.errors
div!= error.msg
for error in (messages.errors || messages.error)
div!= error.msg || error
if messages.info
.alert.alert-info.fade.in
button.close(type='button', data-dismiss='alert')