2020-06-05 22:03:37 +00:00
|
|
|
"use strict";
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
const router = require("../router.js");
|
|
|
|
const api = require("../api.js");
|
|
|
|
const tags = require("../tags.js");
|
|
|
|
const pools = require("../pools.js");
|
|
|
|
const uri = require("../util/uri.js");
|
|
|
|
const topNavigation = require("../models/top_navigation.js");
|
|
|
|
const LoginView = require("../views/login_view.js");
|
2016-03-28 20:33:20 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
class LoginController {
|
2016-03-31 22:20:34 +00:00
|
|
|
constructor() {
|
2016-05-08 15:25:55 +00:00
|
|
|
api.forget();
|
2020-06-05 22:03:37 +00:00
|
|
|
topNavigation.activate("login");
|
|
|
|
topNavigation.setTitle("Login");
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
this._loginView = new LoginView();
|
2020-06-05 22:03:37 +00:00
|
|
|
this._loginView.addEventListener("submit", (e) => this._evtLogin(e));
|
2016-04-06 15:56:34 +00:00
|
|
|
}
|
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
_evtLogin(e) {
|
|
|
|
this._loginView.clearMessages();
|
|
|
|
this._loginView.disableForm();
|
2016-04-09 17:53:53 +00:00
|
|
|
api.forget();
|
2020-06-05 22:03:37 +00:00
|
|
|
api.login(e.detail.name, e.detail.password, e.detail.remember).then(
|
|
|
|
() => {
|
2017-01-20 20:51:04 +00:00
|
|
|
const ctx = router.show(uri.formatClientLink());
|
2020-06-05 22:03:37 +00:00
|
|
|
ctx.controller.showSuccess("Logged in");
|
2019-07-24 14:42:37 +00:00
|
|
|
// reload tag category color map, this is required when `tag_categories:list` has a permission other than anonymous
|
|
|
|
tags.refreshCategoryColorMap();
|
2020-05-04 02:53:28 +00:00
|
|
|
pools.refreshCategoryColorMap();
|
2020-06-05 22:03:37 +00:00
|
|
|
},
|
|
|
|
(error) => {
|
2017-01-08 01:12:38 +00:00
|
|
|
this._loginView.showError(error.message);
|
2016-06-14 08:31:48 +00:00
|
|
|
this._loginView.enableForm();
|
2020-06-05 22:03:37 +00:00
|
|
|
}
|
|
|
|
);
|
2016-04-06 15:56:34 +00:00
|
|
|
}
|
2016-06-14 08:31:48 +00:00
|
|
|
}
|
2016-04-08 11:17:00 +00:00
|
|
|
|
2016-06-14 08:31:48 +00:00
|
|
|
class LogoutController {
|
|
|
|
constructor() {
|
2016-04-09 17:53:53 +00:00
|
|
|
api.forget();
|
2016-04-08 11:17:00 +00:00
|
|
|
api.logout();
|
2017-01-20 20:51:04 +00:00
|
|
|
const ctx = router.show(uri.formatClientLink());
|
2020-06-05 22:03:37 +00:00
|
|
|
ctx.controller.showSuccess("Logged out");
|
2016-04-08 11:17:00 +00:00
|
|
|
}
|
2016-03-19 20:37:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
module.exports = (router) => {
|
|
|
|
router.enter(["login"], (ctx, next) => {
|
2016-06-14 08:31:48 +00:00
|
|
|
ctx.controller = new LoginController();
|
|
|
|
});
|
2020-06-05 22:03:37 +00:00
|
|
|
router.enter(["logout"], (ctx, next) => {
|
2016-06-14 08:31:48 +00:00
|
|
|
ctx.controller = new LogoutController();
|
|
|
|
});
|
|
|
|
};
|