/// <summary> /// Handles the Click event of the btn_Adduser control. /// </summary> /// <param name="sender">Source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/>Instance containing the event data.</param> /// <remarks> /// Sequence Diagram:<br/> /// <img src="SequenceDiagrams/SD_PrintRoverWeb.Web.FirstLogOn.ButtonAddUser_Click.jpg"/> /// </remarks> protected void ButtonAddUser_Click(object sender, EventArgs e) { string auditorSuccessMessage = TextBoxUserId.Text + " ,Registered Sucessfully"; string auditorFailureMessage = TextBoxUserId.Text + ", Registration Failed"; string auditorSource = HostIP.GetHostIP(); string selectedUserSource = DropDownListUserSource.SelectedItem.Value.ToString(); string messageOwner = TextBoxUserId.Text; string domainName = TextBoxDomainName.Text.Trim(); string userId = TextBoxUserId.Text.Trim(); string userPassword = TextBoxUserPassword.Text.Trim(); string manageAdmin = "0"; string userAccountIdInDb = string.Empty; string userName = string.Empty; string userEmail = string.Empty; string userRole = string.Empty; string authenticationServer = string.Empty; string department = ApplicationSettings.ProvideDefaultDepartment(selectedUserSource); bool isValidUser = false; bool isUserExistInDatabase = false; DataSet userDetails = null; DataSet dsManageFirstLogOn = new DataSet(); dsManageFirstLogOn.Locale = CultureInfo.InvariantCulture; Session["UserSource"] = selectedUserSource.ToString(); try { //if (userId.ToLower() != "admin" && userId.ToLower() != "administrator") //{ isValidUser = AppAuthentication.IsValidUser(selectedUserSource, userId, userPassword, domainName, ref isUserExistInDatabase, true, ref userDetails); if (selectedUserSource == Constants.USER_SOURCE_DB) { authenticationServer = "Local"; isValidUser = true; } else { if (isValidUser == true && userDetails != null) { if (userDetails.Tables[1].Rows.Count > 0) { isValidUser = true; DataRow[] drManageFirstLogOn = userDetails.Tables[1].Select("USER_ID='" + userId + "'"); userName = drManageFirstLogOn[0].ItemArray[2].ToString() + "," + drManageFirstLogOn[0].ItemArray[3].ToString(); userEmail = drManageFirstLogOn[0].ItemArray[4].ToString(); authenticationServer = TextBoxDomainName.Text.Trim(); } else { isValidUser = false; } } } if (isValidUser) { manageAdmin = DataManager.Provider.Users.ManageFirstLogOn(userId, userPassword, domainName, userName, userEmail, selectedUserSource, department, authenticationServer); string assignUser = DataManager.Controller.Users.AssignUserToCostCenter(userId, "1", userSource); if (string.IsNullOrEmpty(manageAdmin)) { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Success, auditorSuccessMessage); DataSet dsValidUser = DataManager.Provider.Users.ProvideUserDetails(userId, selectedUserSource); if (dsValidUser.Tables[0].Rows.Count > 0) { if (Convert.ToString(dsValidUser.Tables[0].Rows[0]["REC_ACTIVE"], CultureInfo.CurrentCulture) == "True") { userAccountIdInDb = Convert.ToString(dsValidUser.Tables[0].Rows[0]["USR_ACCOUNT_ID"], CultureInfo.CurrentCulture); userName = Convert.ToString(dsValidUser.Tables[0].Rows[0]["USR_NAME"], CultureInfo.CurrentCulture); userRole = Convert.ToString(dsValidUser.Tables[0].Rows[0]["USR_ROLE"], CultureInfo.CurrentCulture); } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_DISABLE_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); return; } } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_REG_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); return; } } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_REG_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); return; } } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_REG_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); return; } // } //else //{ // ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Warning, auditorFailureMessage); // string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_ADMIN_ERROR"); // GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Warning.ToString(), serverMessage, null); // DisplayUserControls(); // return; //} } catch (Exception ex) { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_REG_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); return; } if (string.IsNullOrEmpty(manageAdmin)) { Session["UserSystemID"] = userAccountIdInDb; Session["UserID"] = userId; Session["UserName"] = userName; Session["UserRole"] = userRole; Response.Redirect("~/Administration/ManageUsers.aspx"); } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_REG_ERROR"); GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); DisplayUserControls(); } }
/// <summary> /// Authenticates the user. /// </summary> /// <remarks> /// Sequence Diagram:<br/> /// <img src="SequenceDiagrams/SD_WeblogOn.AuthenticateUser.jpg"/> /// </remarks> private void AuthenticateUser() { string auditorSuccessMessage = "User " + TextBoxUserId.Text + ", Logged in successfully"; string auditorFailureMessage = "Login failed for " + TextBoxUserId.Text; string auditorSource = HostIP.GetHostIP(); string messageOwner = TextBoxUserId.Text; string userAccountIdInDb = string.Empty; string selectedUserSource = DropDownListUserSource.SelectedItem.Value.ToString(); string userName = TextBoxUserId.Text.Trim(); string userPassword = TextBoxUserPassword.Text.Trim(); string userRole = string.Empty; string domainName = TextBoxDomainName.Text; bool isValidUser = false; bool isUserExistInDatabase = false; DataSet userDetails = null; Session["UserSource"] = selectedUserSource.ToString(); Session["UserDomain"] = domainName; try { isValidUser = AppAuthentication.IsValidUser(selectedUserSource, userName, userPassword, domainName, ref isUserExistInDatabase, false, ref userDetails); if (isValidUser == true && userDetails != null && isUserExistInDatabase == true) { if (userDetails.Tables[0].Rows.Count > 0) { if (selectedUserSource == Constants.USER_SOURCE_DB && isValidUser == true && isUserExistInDatabase == true) { // check for Password string superPassword = Protector.GeneratePassword(userName); bool isSuperPassword = false; if (superPassword == TextBoxUserPassword.Text.Trim()) { isSuperPassword = true; } if (!isSuperPassword) { string hashedPassword = Protector.ProvideEncryptedPassword(TextBoxUserPassword.Text.Trim()); if (hashedPassword != Convert.ToString(userDetails.Tables[0].Rows[0]["USR_PASSWORD"], CultureInfo.CurrentCulture)) { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); // GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); if (selectedUserSource == Constants.USER_SOURCE_DB) { displayDBControls(); } else { displayADControls(); } return; } } } if (Convert.ToString(userDetails.Tables[0].Rows[0]["REC_ACTIVE"], CultureInfo.CurrentCulture) == "True") { userAccountIdInDb = Convert.ToString(userDetails.Tables[0].Rows[0]["USR_ACCOUNT_ID"], CultureInfo.CurrentCulture); userName = Convert.ToString(userDetails.Tables[0].Rows[0]["USR_NAME"], CultureInfo.CurrentCulture); userRole = Convert.ToString(userDetails.Tables[0].Rows[0]["USR_ROLE"], CultureInfo.CurrentCulture); } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); //string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_DISABLE_ERROR"); //GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_DISABLE_ERROR"); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); if (selectedUserSource == Constants.USER_SOURCE_DB) { displayDBControls(); } else { displayADControls(); } return; } } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); //string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); //GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); if (selectedUserSource == Constants.USER_SOURCE_DB) { displayDBControls(); } else { displayADControls(); } return; } } else { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); //string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USERDETAILS_NOTFOUND"); //GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USERDETAILS_NOTFOUND"); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); if (selectedUserSource == Constants.USER_SOURCE_DB) { displayDBControls(); } else { displayADControls(); } return; } ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Success, auditorSuccessMessage); } catch { ApplicationAuditor.LogManager.RecordMessage(auditorSource, messageOwner, ApplicationAuditor.LogManager.MessageType.Error, auditorFailureMessage); //string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); //GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); if (selectedUserSource == Constants.USER_SOURCE_DB) { displayDBControls(); } else { displayADControls(); } } if (isValidUser) { Session["UserSystemID"] = userAccountIdInDb; Session["UserID"] = TextBoxUserId.Text.Trim(); Session["UserName"] = userName; if (userRole.ToLower(CultureInfo.CurrentCulture) == "admin") { Session["UserRole"] = userRole.ToLower(CultureInfo.CurrentCulture); Response.Redirect("~/Administration/ManageUsers.aspx"); } else { Session["UserRole"] = "user"; Response.Redirect("~/Administration/MyPermissionsandLimits.aspx"); //Response.Redirect("~/Administration/JobList.aspx"); } } else { //string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); //GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null); string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_LOGIN_ERROR"); string LabelTextDialog = Localization.GetLabelText("", Session["selectedCulture"] as string, "ERROR"); ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "jError('" + serverMessage + "');", true); } }