mirror of
https://github.com/flarum/framework.git
synced 2025-05-17 11:52:34 +08:00

* Replace gulp with webpack and npm scripts for JS compilation * Set up Travis CI to commit compiled JS * Restructure `js` directory; only one instance of npm, forum/admin are "submodules" * Refactor JS initializers into Application subclasses * Maintain partial compatibility API (importing from absolute paths) for extensions * Remove minification responsibility from PHP asset compiler * Restructure `less` directory
50 lines
1017 B
JavaScript
50 lines
1017 B
JavaScript
/**
|
|
* The `Session` class defines the current user session. It stores a reference
|
|
* to the current authenticated user, and provides methods to log in/out.
|
|
*/
|
|
export default class Session {
|
|
constructor(user, csrfToken) {
|
|
/**
|
|
* The current authenticated user.
|
|
*
|
|
* @type {User|null}
|
|
* @public
|
|
*/
|
|
this.user = user;
|
|
|
|
/**
|
|
* The CSRF token.
|
|
*
|
|
* @type {String|null}
|
|
* @public
|
|
*/
|
|
this.csrfToken = csrfToken;
|
|
}
|
|
|
|
/**
|
|
* Attempt to log in a user.
|
|
*
|
|
* @param {String} identification The username/email.
|
|
* @param {String} password
|
|
* @param {Object} [options]
|
|
* @return {Promise}
|
|
* @public
|
|
*/
|
|
login(data, options = {}) {
|
|
return app.request(Object.assign({
|
|
method: 'POST',
|
|
url: app.forum.attribute('baseUrl') + '/login',
|
|
data
|
|
}, options));
|
|
}
|
|
|
|
/**
|
|
* Log the user out.
|
|
*
|
|
* @public
|
|
*/
|
|
logout() {
|
|
window.location = app.forum.attribute('baseUrl') + '/logout?token=' + this.csrfToken;
|
|
}
|
|
}
|