fix account link failure now flashes
This commit is contained in:
@ -69,7 +69,7 @@
|
|||||||
"lodash": "^3.9.3",
|
"lodash": "^3.9.3",
|
||||||
"loopback": "https://github.com/FreeCodeCamp/loopback.git#fix/no-password",
|
"loopback": "https://github.com/FreeCodeCamp/loopback.git#fix/no-password",
|
||||||
"loopback-boot": "^2.8.0",
|
"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",
|
"loopback-connector-mongodb": "^1.10.0",
|
||||||
"lusca": "~1.0.2",
|
"lusca": "~1.0.2",
|
||||||
"method-override": "~2.3.0",
|
"method-override": "~2.3.0",
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
|
import{ Observable } from 'rx';
|
||||||
import { observeMethod, observeQuery } from '../utils/rx';
|
import { observeMethod, observeQuery } from '../utils/rx';
|
||||||
import { getSocialProvider } from '../utils/auth';
|
import { getSocialProvider } from '../utils/auth';
|
||||||
|
import debugFactory from 'debug';
|
||||||
|
|
||||||
|
const debug = debugFactory('fcc:userIdent');
|
||||||
|
|
||||||
export default function({ models }) {
|
export default function({ models }) {
|
||||||
const { User, UserIdentity, UserCredential } = models;
|
const { User, UserIdentity, UserCredential } = models;
|
||||||
@ -20,15 +24,18 @@ export default function({ models }) {
|
|||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
const user$ = findUserById(userId);
|
const user$ = findUserById(userId);
|
||||||
console.log('provider', provider);
|
const query = {
|
||||||
console.log('id', profile.id);
|
where: {
|
||||||
findIdent({
|
provider: getSocialProvider(provider),
|
||||||
provider: getSocialProvider(provider),
|
externalId: profile.id
|
||||||
externalId: profile.id
|
}
|
||||||
})
|
};
|
||||||
|
|
||||||
|
debug('link identity query', query);
|
||||||
|
findIdent(query)
|
||||||
.flatMap(identity => {
|
.flatMap(identity => {
|
||||||
const modified = new Date();
|
const modified = new Date();
|
||||||
if (!identity || identity.externalId !== profile.id) {
|
if (!identity) {
|
||||||
return observeQuery(UserIdentity, 'create', {
|
return observeQuery(UserIdentity, 'create', {
|
||||||
provider: getSocialProvider(provider),
|
provider: getSocialProvider(provider),
|
||||||
externalId: profile.id,
|
externalId: profile.id,
|
||||||
@ -40,6 +47,11 @@ export default function({ models }) {
|
|||||||
modified
|
modified
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (identity.userId !== userId) {
|
||||||
|
return Observable.throw(
|
||||||
|
new Error('An account is already linked to that profile')
|
||||||
|
);
|
||||||
|
}
|
||||||
identity.credentials = credentials;
|
identity.credentials = credentials;
|
||||||
return observeQuery(identity, 'updateAttributes', {
|
return observeQuery(identity, 'updateAttributes', {
|
||||||
profile: getSocialProvider(provider),
|
profile: getSocialProvider(provider),
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
.row
|
.row
|
||||||
.col-xs-12
|
.col-xs-12
|
||||||
if messages.errors
|
if (messages.errors || messages.error)
|
||||||
.alert.alert-danger.fade.in
|
.alert.alert-danger.fade.in
|
||||||
button.close(type='button', data-dismiss='alert')
|
button.close(type='button', data-dismiss='alert')
|
||||||
span.ion-close-circled
|
span.ion-close-circled
|
||||||
for error in messages.errors
|
for error in (messages.errors || messages.error)
|
||||||
div!= error.msg
|
div!= error.msg || error
|
||||||
if messages.info
|
if messages.info
|
||||||
.alert.alert-info.fade.in
|
.alert.alert-info.fade.in
|
||||||
button.close(type='button', data-dismiss='alert')
|
button.close(type='button', data-dismiss='alert')
|
||||||
|
Reference in New Issue
Block a user