@expressive-analytics/deep-thought-authentication
Version:
Typescript conversion of Deep Thought Authentication
49 lines (48 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DTAuthenticationService = void 0;
const deep_thought_service_1 = require("@expressive-analytics/deep-thought-service");
const DTUser_1 = require("./DTUser");
class DTAuthenticationService extends deep_thought_service_1.DTService {
actionAuthenticate() {
const session = deep_thought_service_1.DTSession.shared();
const u = this.castUser(this.db.filter({
"alias": [this.db.ilike, this.params.stringParam("alias")],
"is_active": 1
}));
if (u.verifyPassword(this.params.stringParam("password"))) {
session.$set("pvd_user_id", u.$get("id"));
return u;
}
else {
this.response.error(401);
session.unset("pvd_user_id");
return undefined;
}
}
actionPasswordResetToken() {
throw new Error("method not implemented!");
}
actionResetPassword() {
throw new Error("method not implemented!");
}
currentUserID() {
const s = deep_thought_service_1.DTSession.shared();
return s.$get("pvd_user_id");
}
actionCurrentUser() {
const id = this.currentUserID();
try {
this.castUser(this.db.filter({ id }));
}
catch (e) { }
return null;
}
castUser(qb) {
return DTUser_1.DTUserModel.query(qb);
}
actionLogout() {
deep_thought_service_1.DTSession.destroy();
}
}
exports.DTAuthenticationService = DTAuthenticationService;