Changed login so it leads to previously viewed page
This commit is contained in:
parent
c117367974
commit
968a15ef60
4 changed files with 20 additions and 6 deletions
|
@ -14,13 +14,15 @@ App.Presenters.LoginPresenter = function(
|
||||||
var $el = jQuery('#content');
|
var $el = jQuery('#content');
|
||||||
var $messages;
|
var $messages;
|
||||||
var template;
|
var template;
|
||||||
|
var previousRoute;
|
||||||
|
|
||||||
function init() {
|
function init(args) {
|
||||||
topNavigationPresenter.select('login');
|
topNavigationPresenter.select('login');
|
||||||
|
previousRoute = args.previousRoute;
|
||||||
promise.wait(util.promiseTemplate('login-form')).then(function(html) {
|
promise.wait(util.promiseTemplate('login-form')).then(function(html) {
|
||||||
template = _.template(html);
|
template = _.template(html);
|
||||||
if (auth.isLoggedIn()) {
|
if (auth.isLoggedIn()) {
|
||||||
router.navigateToMainPage();
|
finishLogin();
|
||||||
} else {
|
} else {
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
@ -54,12 +56,20 @@ App.Presenters.LoginPresenter = function(
|
||||||
|
|
||||||
auth.loginFromCredentials(userNameOrEmail, password, remember)
|
auth.loginFromCredentials(userNameOrEmail, password, remember)
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
router.navigateToMainPage();
|
finishLogin();
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function finishLogin() {
|
||||||
|
if (previousRoute && !previousRoute.match(/logout|password-reset|activate|register/)) {
|
||||||
|
router.navigate(previousRoute);
|
||||||
|
} else {
|
||||||
|
router.navigateToMainPage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: init,
|
init: init,
|
||||||
render: render,
|
render: render,
|
||||||
|
|
|
@ -49,7 +49,7 @@ App.Presenters.PagedCollectionPresenter = function(_, util, promise, api) {
|
||||||
if (typeof(failCallback) !== 'undefined') {
|
if (typeof(failCallback) !== 'undefined') {
|
||||||
failCallback(response);
|
failCallback(response);
|
||||||
} else {
|
} else {
|
||||||
console.log(Error(response.json && response.json.error || response));
|
console.log(new Error(response.json && response.json.error || response));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ App.Presenters.UserActivationPresenter = function(
|
||||||
|
|
||||||
function reinit(args) {
|
function reinit(args) {
|
||||||
operation = args.operation;
|
operation = args.operation;
|
||||||
console.log(operation);
|
|
||||||
promise.wait(util.promiseTemplate('user-query-form')).then(function(html) {
|
promise.wait(util.promiseTemplate('user-query-form')).then(function(html) {
|
||||||
template = _.template(html);
|
template = _.template(html);
|
||||||
if (args.token) {
|
if (args.token) {
|
||||||
|
|
|
@ -42,7 +42,12 @@ App.Router = function(pathJs, _, jQuery, util, appState) {
|
||||||
|
|
||||||
function inject(path, presenterName, additionalParams) {
|
function inject(path, presenterName, additionalParams) {
|
||||||
pathJs.map(path).to(function() {
|
pathJs.map(path).to(function() {
|
||||||
util.initContentPresenter(presenterName, _.extend(this.params, additionalParams));
|
var finalParams = _.extend(
|
||||||
|
this.params,
|
||||||
|
additionalParams,
|
||||||
|
{previousRoute: pathJs.routes.previous});
|
||||||
|
|
||||||
|
util.initContentPresenter( presenterName, finalParams);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue