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 $messages;
|
||||
var template;
|
||||
var previousRoute;
|
||||
|
||||
function init() {
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('login');
|
||||
previousRoute = args.previousRoute;
|
||||
promise.wait(util.promiseTemplate('login-form')).then(function(html) {
|
||||
template = _.template(html);
|
||||
if (auth.isLoggedIn()) {
|
||||
router.navigateToMainPage();
|
||||
finishLogin();
|
||||
} else {
|
||||
render();
|
||||
}
|
||||
|
@ -54,12 +56,20 @@ App.Presenters.LoginPresenter = function(
|
|||
|
||||
auth.loginFromCredentials(userNameOrEmail, password, remember)
|
||||
.then(function(response) {
|
||||
router.navigateToMainPage();
|
||||
finishLogin();
|
||||
}).fail(function(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 {
|
||||
init: init,
|
||||
render: render,
|
||||
|
|
|
@ -49,7 +49,7 @@ App.Presenters.PagedCollectionPresenter = function(_, util, promise, api) {
|
|||
if (typeof(failCallback) !== 'undefined') {
|
||||
failCallback(response);
|
||||
} 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) {
|
||||
operation = args.operation;
|
||||
console.log(operation);
|
||||
promise.wait(util.promiseTemplate('user-query-form')).then(function(html) {
|
||||
template = _.template(html);
|
||||
if (args.token) {
|
||||
|
|
|
@ -42,7 +42,12 @@ App.Router = function(pathJs, _, jQuery, util, appState) {
|
|||
|
||||
function inject(path, presenterName, additionalParams) {
|
||||
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