mirror of
https://github.com/documize/community.git
synced 2025-08-08 06:55:28 +02:00
Fix sso authentication error by refactoring folders route
This commit is contained in:
parent
a7894d6800
commit
f41517872b
4 changed files with 95 additions and 98 deletions
|
@ -7,10 +7,9 @@ export default Ember.Route.extend({
|
|||
this.get("session").authenticate('authenticator:documize', token)
|
||||
.then(() => {
|
||||
this.transitionTo('folders.folder');
|
||||
})
|
||||
.catch(() => {
|
||||
}, () => {
|
||||
this.transitionTo('auth.login');
|
||||
console.log(">>>>> Documize SSO failure");
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -11,45 +11,50 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
},
|
||||
|
||||
afterModel: function (model) {
|
||||
let self = this;
|
||||
// TODO: replace with ES6 features (remove self this)
|
||||
// TODO: replace is.* with Ember utilities
|
||||
// TODO: flatten if/else
|
||||
// TODO: make sure chain is maintained by returning promies
|
||||
|
||||
if (is.empty(this.paramsFor('folders.folder'))) {
|
||||
var lastFolder = this.get('localStorage').getSessionItem("folder");
|
||||
let lastFolder = this.get('localStorage').getSessionItem("folder");
|
||||
|
||||
if (is.not.undefined(lastFolder)) {
|
||||
this.get('folderService').getFolder(lastFolder).then(function(folder) {
|
||||
if (is.undefined(folder) || is.null(folder)) {
|
||||
self.transitionTo('auth.login');
|
||||
}
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}, function() {
|
||||
if (model.length > 0) {
|
||||
var folder = model[0];
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
} else {
|
||||
self.transitionTo('auth.login');
|
||||
//If folder lastFolder is defined
|
||||
if (Ember.isPresent(lastFolder)) {
|
||||
return this.get('folderService').getFolder(lastFolder).then((folder) => {
|
||||
//if Response is null or undefined redirect to login else transitionTo dashboard
|
||||
if (Ember.isNone(folder)) {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
this.folder = folder;
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}).catch(() => {
|
||||
//if there was an error redirect to login
|
||||
this.transitionTo('auth.login');
|
||||
});
|
||||
} else {
|
||||
}
|
||||
|
||||
// If model has any folders redirect to dashboard
|
||||
if (model.length > 0) {
|
||||
var folder = model[0];
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
} else
|
||||
{
|
||||
let folder = model[0];
|
||||
this.folder = folder;
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
}
|
||||
|
||||
// has no folders, create default folder
|
||||
this.get('folderService').add({ name: "My Space" }).then(function(folder) {
|
||||
self.folder = folder;
|
||||
self.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
return this.get('folderService').add({ name: "My Space" }).then((folder) => {
|
||||
this.folder = folder;
|
||||
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var folderId = this.paramsFor('folders.folder').folder_id;
|
||||
this.get('folderService').getFolder(folderId).then(function(folder) {
|
||||
self.folder = folder;
|
||||
|
||||
//If folder route has params
|
||||
if (Ember.isPresent(this.paramsFor('folders.folder'))) {
|
||||
|
||||
let folderId = this.paramsFor('folders.folder').folder_id;
|
||||
|
||||
return this.get('folderService').getFolder(folderId).then((folder) => {
|
||||
this.folder = folder;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ export default function () {
|
|||
this.namespace = 'api'; // make this `api`, for example, if your API is namespaced
|
||||
// this.timing = 400; // delay for each request, automatically set to 0 during testing
|
||||
|
||||
this.logging = true;
|
||||
|
||||
this.get('/public/meta', function (schema) {
|
||||
return schema.db.meta[0];
|
||||
});
|
||||
|
@ -128,37 +130,7 @@ export default function () {
|
|||
let expectedAuthorization = "Basic OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==";
|
||||
|
||||
if (expectedAuthorization == authorization) {
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
};
|
||||
} else if (expectedAuthorization != authorization) {
|
||||
return new Mirage.Response(400);
|
||||
} else {
|
||||
console.log("SSO login success");
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
|
@ -189,6 +161,39 @@ export default function () {
|
|||
};
|
||||
}
|
||||
|
||||
if (expectedAuthorization != authorization) {
|
||||
return new Mirage.Response(401, { 'Content-Type': 'application/json' }, { message: 'Bad Request' });
|
||||
}
|
||||
|
||||
return {
|
||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiIiLCJleHAiOjE0NjQwMjM2NjcsImlzcyI6IkRvY3VtaXplIiwib3JnIjoiVnpNdXlFd18zV3FpYWZjRCIsInN1YiI6IndlYmFwcCIsInVzZXIiOiJWek11eUV3XzNXcWlhZmNFIn0.NXZ6bo8mtvdZF_b9HavbidVUJqhmBA1zr0fSAPvbah0",
|
||||
"user": {
|
||||
"id": "VzMuyEw_3WqiafcE",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"firstname": "Lennex",
|
||||
"lastname": "Zinyando",
|
||||
"email": "brizdigital@gmail.com",
|
||||
"initials": "LZ",
|
||||
"active": true,
|
||||
"editor": true,
|
||||
"admin": true,
|
||||
"accounts": [{
|
||||
"id": "VzMuyEw_3WqiafcF",
|
||||
"created": "2016-05-11T15:08:24Z",
|
||||
"revised": "2016-05-11T15:08:24Z",
|
||||
"admin": true,
|
||||
"editor": true,
|
||||
"userId": "VzMuyEw_3WqiafcE",
|
||||
"orgId": "VzMuyEw_3WqiafcD",
|
||||
"company": "EmberSherpa",
|
||||
"title": "EmberSherpa",
|
||||
"message": "This Documize instance contains all our team documentation",
|
||||
"domain": ""
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
this.get('/users/VzMuyEw_3WqiafcE/permissions', (schema) => {
|
||||
|
@ -440,15 +445,4 @@ export default function () {
|
|||
return {};
|
||||
});
|
||||
|
||||
/**
|
||||
very helpful for debugging
|
||||
*/
|
||||
this.handledRequest = function (verb, path) {
|
||||
console.log(`👊${verb} ${path}`);
|
||||
};
|
||||
|
||||
this.unhandledRequest = function (verb, path) {
|
||||
console.log(`🔥${verb} ${path}`);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ test('successful sso login authenticates redirects to dashboard', function (asse
|
|||
server.createList('folder', 2);
|
||||
|
||||
visit('/auth/sso/OmJyaXpkaWdpdGFsQGdtYWlsLmNvbTp6aW55YW5kbzEyMw==');
|
||||
// return pauseTest();
|
||||
|
||||
andThen(function () {
|
||||
assert.equal(currentURL(), '/s/VzMuyEw_3WqiafcG/my-project', 'SSO login successful');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue