Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- importPackage(com.ebasetech.xi.api);
- importPackage(com.ebasetech.xi.services);
- try {
- var eBaseDomain=getSystemVar("EbaseDomain");
- fields.USERID.value=fields.PARAM1_VALUE.value;
- fields.PASSWORD.value=fields.PARAM2_VALUE.value;
- tables.USERS.WHERECLAUSE.value="WHERE LOWER(Username)='" + fields.PARAM1_VALUE.value.toLowerCase() + "' AND CONVERT(VARCHAR(MAX),DecryptByKey(Password))='" + fields.PARAM2_VALUE.value + "'";
- tables.USERS.fetchTable();
- // User account is not enabled
- if (tables.USERS.rowCount > 0 && tables.USERS.ENABLED.value != 1) {
- fields.USERID.value=null;
- fields.ERRORCODE.value = "999";
- fields.ERRORDESCRIPTION.value = "Your Intranet account is disabled. Please contact the system administrator";
- // Add log to indicate failed login
- addIntranetLog(fields.PARAM1_VALUE.value,null,"Failed login because of disabled Intranet Account","INTRANET LOGIN",system.variables.$BROWSER_IP_ADDRESS.value);
- } else if (tables.USERS.rowCount == 1) {
- // Before adding all of the users' role below, make sure that they have access to the HR Menu. If they don't, Ebase will ended up in a never ending loop because
- // the user doesn't have the HR role so they won't be able to access the HR page. This fixes that problem by granting the user access to the HR if they don't have access already
- tables.HasAccessToHRMenu.Username.value=tables.USERS.USERNAME.value;
- tables.HasAccessToHRMenu.fetchTable();
- if (tables.HasAccessToHRMenu.HasAccess.value=='N') {
- // This update will insert a row into users_auth for the current user and the HR menu ID
- resources.HasAccessToHRMenu.update();
- }
- // Required for eBase SecurityManager to know that the authentication was successfull
- fields.USERID.value=tables.USERS.REALNAME.value;
- // Add these values as credentials so they can be referenced in any script
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="REALNAME";
- tables.CREDENTIALS.VALUE.value=tables.USERS.REALNAME.value;
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="USERID";
- tables.CREDENTIALS.VALUE.value=tables.USERS.USERID.value;
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="USERNAME";
- tables.CREDENTIALS.VALUE.value=tables.USERS.USERNAME.value;
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="SECID";
- tables.CREDENTIALS.VALUE.value=tables.USERS.SECID.value;
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="EMAILADDRESS";
- tables.CREDENTIALS.VALUE.value=tables.USERS.EMAIL.value;
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="IGNOREMAINTAINANCEMODE";
- tables.CREDENTIALS.VALUE.value=(tables.USERS.IGNOREMAINTAINANCEMODE.value == 1 ? 'Y' : 'N');
- tables.CREDENTIALS.updateTable();
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value="FORCEPASSWORDRESET";
- tables.CREDENTIALS.VALUE.value=(tables.USERS.FORCEPASSWORDRESET.value == 1 ? 'Y' : 'N');
- tables.CREDENTIALS.updateTable();
- // Get all the menus that this user is authorized for based on their user ID
- tables.GENERATE_USER_MENU.UserID.value=tables.USERS.USERID.value;
- tables.GENERATE_USER_MENU.fetchTable();
- if ( tables.GENERATE_USER_MENU.rowCount > 0 ) {
- var allMenuRows=tables.GENERATE_USER_MENU;
- var menuRows=allMenuRows.getRows();
- while (menuRows.next()) {
- // Add the menu name to the custom roles so it can be used to determine whether a user has access to that menu
- tables.CUSTOMROLES.insertRow();
- tables.CUSTOMROLES.ROLEID.value=allMenuRows.MENUNAME.value;
- tables.CUSTOMROLES.updateTable();
- }
- }
- // Get all of the users' permissions based on their user ID
- tables.Permissions.UserID.value=tables.USERS.USERID.value;
- tables.Permissions.fetchTable();
- var allPermissions=tables.Permissions;
- var allPermissionsRows=allPermissions.getRows();
- while (allPermissionsRows.next()) {
- tables.CREDENTIALS.insertRow();
- tables.CREDENTIALS.ID.value=allPermissions.PermissionName.value.toUpperCase(); // Instead of fixing all places that reference the check to see if the user has the permission, I make this upper case so its always consistent
- tables.CREDENTIALS.VALUE.value=(allPermissions.HasAccess.value==true ? 1 : 0);
- tables.CREDENTIALS.updateTable();
- }
- } else {
- fields.USERID.value = null;
- fields.ERRORCODE.value = "999991";
- fields.ERRORDESCRIPTION.value = "Your username or password is not correct";
- //print("Login failed with the username " + fields.PARAM1_VALUE.value);
- // Add log to indicate failed login
- addIntranetLog(fields.PARAM1_VALUE.value,null,"Failed login because of an incorrect username or password 1","INTRANET LOGIN",null);
- }
- } catch (e) {
- fields.USERID.value = null;
- fields.ERRORCODE.value = "999991";
- fields.ERRORDESCRIPTION.value = "Your username or password is not correct";
- // Add log to indicate failed login
- addIntranetLog(fields.PARAM1_VALUE.value,null,"Failed login because of an incorrect username or password (in catch statement)","INTRANET LOGIN",system.variables.$BROWSER_IP_ADDRESS.value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement