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]});
|
||||||
self.store.find('user', response.userData.id).then(function (user) {
|
return self.store.find('user', response.userData.id);
|
||||||
|
}).then(function (user) {
|
||||||
self.send('signedIn', user);
|
self.send('signedIn', user);
|
||||||
self.notifications.clear();
|
self.notifications.clear();
|
||||||
|
if (loginTransition) {
|
||||||
|
appController.set('loginTransition', null);
|
||||||
|
loginTransition.retry();
|
||||||
|
} else {
|
||||||
self.transitionTo('posts');
|
self.transitionTo('posts');
|
||||||
});
|
|
||||||
}, function (resp) {
|
|
||||||
// This path is ridiculous, should be a helper in notifications; e.g. notifications.showAPIError
|
|
||||||
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
|
||||||
}
|
}
|
||||||
);
|
}).catch(function (resp) {
|
||||||
|
self.notifications.showAPIError(resp, 'There was a problem logging in, please try again.');
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.notifications.clear();
|
this.notifications.clear();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user