mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
Merge pull request #2952 from novaugust/ember-signin-transition
Transition user to original destination on login
This commit is contained in:
commit
0e81f3a20e
@ -1,18 +1,22 @@
|
|||||||
var AuthenticatedRoute = Ember.Route.extend({
|
var AuthenticatedRoute = Ember.Route.extend({
|
||||||
beforeModel: function () {
|
beforeModel: function (transition) {
|
||||||
var user = this.container.lookup('user:current');
|
var user = this.container.lookup('user:current');
|
||||||
|
|
||||||
if (!user || !user.get('isSignedIn')) {
|
if (!user || !user.get('isSignedIn')) {
|
||||||
this.notifications.showError('Please sign in');
|
this.redirectToSignin(transition);
|
||||||
|
|
||||||
this.transitionTo('signin');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
redirectToSignin: function (transition) {
|
||||||
|
this.notifications.showError('Please sign in');
|
||||||
|
if (transition) {
|
||||||
|
this.controllerFor('application').set('loginTransition', transition);
|
||||||
|
}
|
||||||
|
this.transitionTo('signin');
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
error: function (error) {
|
error: function (error) {
|
||||||
if (error.jqXHR && error.jqXHR.status === 401) {
|
if (error.jqXHR && error.jqXHR.status === 401) {
|
||||||
this.transitionTo('signin');
|
this.redirectToSignin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,30 +10,33 @@ var SigninRoute = Ember.Route.extend(styleBody, {
|
|||||||
login: function () {
|
login: function () {
|
||||||
var self = this,
|
var self = this,
|
||||||
controller = this.get('controller'),
|
controller = this.get('controller'),
|
||||||
data = controller.getProperties('email', 'password');
|
data = controller.getProperties('email', 'password'),
|
||||||
|
//Data to check if user came in somewhere besides index
|
||||||
|
appController = this.controllerFor('application'),
|
||||||
|
loginTransition = appController.get('loginTransition');
|
||||||
|
|
||||||
if (!isEmpty(data.email) && !isEmpty(data.password)) {
|
if (!isEmpty(data.email) && !isEmpty(data.password)) {
|
||||||
|
|
||||||
ajax({
|
ajax({
|
||||||
url: this.get('ghostPaths').adminUrl('signin'),
|
url: this.get('ghostPaths').adminUrl('signin'),
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
headers: {
|
headers: {'X-CSRF-Token': this.get('csrf')},
|
||||||
'X-CSRF-Token': this.get('csrf')
|
|
||||||
},
|
|
||||||
data: data
|
data: data
|
||||||
}).then(
|
}).then(function (response) {
|
||||||
function (response) {
|
self.store.pushPayload({users: [response.userData]});
|
||||||
self.store.pushPayload({ users: [response.userData]});
|
return self.store.find('user', response.userData.id);
|
||||||
self.store.find('user', response.userData.id).then(function (user) {
|
}).then(function (user) {
|
||||||
self.send('signedIn', user);
|
self.send('signedIn', user);
|
||||||
self.notifications.clear();
|
self.notifications.clear();
|
||||||
self.transitionTo('posts');
|
if (loginTransition) {
|
||||||
});
|
appController.set('loginTransition', null);
|
||||||
}, function (resp) {
|
loginTransition.retry();
|
||||||
// This path is ridiculous, should be a helper in notifications; e.g. notifications.showAPIError
|
} else {
|
||||||
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
self.transitionTo('posts');
|
||||||
}
|
}
|
||||||
);
|
}).catch(function (resp) {
|
||||||
|
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.notifications.clear();
|
this.notifications.clear();
|
||||||
|
|
||||||
@ -43,4 +46,4 @@ var SigninRoute = Ember.Route.extend(styleBody, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default SigninRoute;
|
export default SigninRoute;
|
Loading…
Reference in New Issue
Block a user