2019-03-21 12:33:14 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
2019-08-12 11:11:10 +03:00
|
|
|
import fetch from 'fetch';
|
2019-06-18 13:47:21 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2019-03-21 12:33:14 +03:00
|
|
|
|
2019-05-20 16:15:46 +03:00
|
|
|
export default AuthenticatedRoute.extend({
|
2019-08-12 11:11:10 +03:00
|
|
|
config: service(),
|
|
|
|
settings: service(),
|
2019-06-18 13:47:21 +03:00
|
|
|
ui: service(),
|
|
|
|
|
2019-08-12 11:11:10 +03:00
|
|
|
_hasLoggedIn: false,
|
|
|
|
|
2019-03-21 20:55:58 +03:00
|
|
|
model() {
|
|
|
|
return (new Date()).valueOf();
|
2019-05-20 18:16:19 +03:00
|
|
|
},
|
|
|
|
|
2019-08-12 11:11:10 +03:00
|
|
|
afterModel() {
|
|
|
|
if (this.settings.get('isPrivate') && !this._hasLoggedIn) {
|
|
|
|
let privateLoginUrl = `${this.config.get('blogUrl')}/private/?r=%2F`;
|
2019-06-18 13:47:21 +03:00
|
|
|
|
2019-08-12 11:11:10 +03:00
|
|
|
return fetch(privateLoginUrl, {
|
|
|
|
method: 'POST',
|
|
|
|
mode: 'cors',
|
|
|
|
redirect: 'manual',
|
2019-09-09 19:01:12 +03:00
|
|
|
credentials: 'include',
|
2019-08-12 11:11:10 +03:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
},
|
|
|
|
body: `password=${this.settings.get('password')}`
|
|
|
|
}).then(() => {
|
|
|
|
this._hasLoggedIn = true;
|
|
|
|
});
|
|
|
|
}
|
2019-06-18 13:47:21 +03:00
|
|
|
},
|
|
|
|
|
2019-05-20 18:16:19 +03:00
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Site'
|
|
|
|
};
|
2019-03-21 20:55:58 +03:00
|
|
|
}
|
2019-03-21 12:33:14 +03:00
|
|
|
});
|