ui5_easy_use
Version:
CLI tool for SAP ui5 and SAPUI5 projects to initialize apps, generate pages, insert form and table components, manage routing, and automate i18n bindings
43 lines (34 loc) • 1.14 kB
JavaScript
sap.ui.define(["sap/m/MessageBox"], function (MessageBox) {
"use strict";
return class AuthService {
constructor(component) {
this._componentJS = component;
this.userModel = this._componentJS.userModel;
this.currentUser = null;
this.token = null;
}
async login(credentials) {
if (!this._hasCredentials(credentials)) {
MessageBox.error("Login failed");
return false;
}
this.token = "secure-token-123";
this.currentUser = await this.userModel.getuserInfo(credentials.username, credentials.password);
this.userModel.userData = this.currentUser;
return true;
}
logout() {
this.token = null;
this.currentUser = null;
}
isAuthenticated() {
return !!this.token;
}
getUser() {
return this.currentUser;
}
_hasCredentials(credentials) {
return Boolean(credentials && credentials.username && credentials.password);
}
};
});