protected void btnAdd_Click(object sender, EventArgs e) { if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "add")) { LoggedIn master = (LoggedIn)this.Master; master.ShowMessage("You are not authorised to Perform any operation on this page. Please contact system administrator.", false); return; } if (ValidData()) { } else { LoggedIn master = (LoggedIn)this.Master; CommonBAL combal = new CommonBAL(); UserBE addUserBE = new UserBE(); UserDAL addUserdAL = new UserDAL(); UserBAL addUserBal = new UserBAL(); int ReturnOutput = 0; addUserBE.LastModifiedBy = ((UserBE)Session["LoggedInUser"]).UserId; addUserBE.UserName = txtUserName.Text; addUserBE.FirstName = txtFName.Text; addUserBE.MiddleName = txtMName.Text; addUserBE.LastName = txtLName.Text; addUserBE.PrimaryEmailId = txtPREmailId.Text; addUserBE.SecondaryEmailId = txtSCEmailId.Text; addUserBE.MobileNo = txtMobileNo.Text; addUserBE.Address1 = txtAddress1.Text; addUserBE.Address2 = txtAddress2.Text; addUserBE.Street = txtStreet.Text; addUserBE.City = txtCity.Text; addUserBE.State1 = txtState.Text; addUserBE.Country = txtCountry.Text; addUserBE.SecretQuest = ddSecretQuest.SelectedValue; addUserBE.SecretAns = txtSecretAns.Text; addUserBE.EncPass = combal.Encrypt(txtPass.Text, false); if (addUserBal.AddUser(addUserBE, ref ReturnOutput)) { if(ReturnOutput==1) { master.ShowMessage("User of this User Name Already exist. ", false); } else if (ReturnOutput == 2) { clearFields(); master.ShowMessage("Record Inserted Successfully.", true); } } else { master.ShowMessage("Unsuccessful", false); } } }
protected void btnSavePassword_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtConfirmPassword.Text)) ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Please enter Password');", true); else if (!txtPassword.Text.Trim().Equals(txtConfirmPassword.Text.Trim())) ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Password does not matched.');", true); else { UserBE userInfo = new UserBE(); UserBAL userBAL = new UserBAL(); CommonBAL combal = new CommonBAL(); string pwd = combal.Encrypt(txtPassword.Text.Trim(), false); int i = userBAL.SaveConfirmation(Request.QueryString["userid"].ToString(), Request.QueryString["key"].ToString(), pwd); if (i > 0) ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Password saved, Please relogin'); location.href ='login.aspx';", true); else ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('try again later');", true); } } catch (Exception ex) { } }
protected void Page_Load(object sender, EventArgs e) { LoggedInUser = (UserBE)Session["LoggedInUser"]; if (LoggedInUser == null) { // return to login page because user has not loggedin or session has timedout... //Response.Redirect("~/Login.aspx"); } if (Session["KOWOLoginId"] != null) { CommonBAL commBAL = new CommonBAL(); bool blnTemp = commBAL.KOTotalViewCountrIncrement(Convert.ToInt16(Session["KOWOLoginId"]), 0); if (!IsPostBack) { hdnKOID.Value = Session["KOWOLoginId"].ToString(); retreiveDATA(); Session["KOWOLoginId"] = null; } } }
protected void Page_Load(object sender, EventArgs e) { //LoggedInUser = (UserBE)Session["LoggedInUser"]; //if (LoggedInUser == null) //{ // if (Session["QuestId"] == null) // { // // return to login page because user has not loggedin or session has timedout... // Response.Redirect("~/Login.aspx"); // } // else // { // //coming from QA_SearchQuestionWOLogin.aspx page - i.e. search w/o login - Quick Search click // } //} if (!IsPostBack) { if (Session["QuestionId"] != null) { CommonBAL commBAL = new CommonBAL(); //am?? bool blnTemp = commBAL.QueriesTotalViewCountrIncrement(Convert.ToInt16(Session["QuestionId"]), 0); hdnQuestId.Value = Session["QuestionId"].ToString(); //Session["QuestIdWOLogin"] = Session["QuestionId"].ToString(); Session["QuestionId"] = null; ShowQuestion(); GetAnswers(); } else { //CV? //Response.Redirect("~/UserMaint/LoggedInHome.aspx"); Response.Redirect("~/QuestAns/QA_HomePageWOLogin.aspx"); } } }
protected void btnLogin_Click(object sender, EventArgs e) { string RealPass = txtPass.Text; if (ValidData()) { return; } UserBE LoggedInUser = new UserBE(); CommonBAL combal = new CommonBAL(); UserBAL userBAL = new UserBAL(); DataTable dt = new DataTable(); // Using screen inputs create UserBE; LoggedInUser.UserName = txtName.Text; LoggedInUser.EncPass = combal.Encrypt(txtPass.Text, false); if (userBAL.Validate(ref LoggedInUser)) { Session["LoggedInUser"] = LoggedInUser; if (Session["LoggedInUser"] != null) { LoggedInUser.UserId = ((UserBE)Session["LoggedInUser"]).UserId; if(userBAL.UserAccessRight(LoggedInUser,ref dt)) { Session["UserAccessRights"] = dt; Response.Redirect(@"~\UserMaint\LoggedInHome.aspx"); } //General master = (General)this.Master; //master.ShowMessage("You are not authorised to access this page. Please contact system administrator.", false); //?? Message through Query String ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('You are not authorised to access this page. Please contact system administrator.');", true); return; } } else { //General master = (General)this.Master; //master.ShowMessage("Incorrect Email or Password.", false); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Incorrect Email or Password.');", true); return; } }
protected void btnSignUp_Click(object sender, EventArgs e) { if (ValidData()) return; UserBE NewUser = new UserBE(); CommonBAL combal = new CommonBAL(); DataTable dt = new DataTable(); General master = (General)this.Master; dt = userBAL.GetUsers().Tables[0]; if (dt.Rows.Count > 0) { DataRow[] dr = dt.Select("UserName='******'"); if (dr.Length > 0) { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('User Name Already Exists.. Please sign up with diffrent user name. ');", true); return; } dr = dt.Select("EmailAddress='" + txtEmail.Text + "'"); if (dr.Length > 0) { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Email Address Already Exists.. ');", true); return; } } // Using screen inputs create UserBE; NewUser.FirstName = txtFName.Text.Trim(); NewUser.LastName = txtLName.Text.Trim(); NewUser.UserName = txtUName.Text.Trim(); NewUser.PrimaryEmailId = txtEmail.Text.Trim(); NewUser.SecretQuest = ddlSecretQuestion.SelectedValue; NewUser.SecretAns = txtAnswer.Text; NewUser.MiddleName = NewUser.SecondaryEmailId = NewUser.MobileNo = NewUser.Address1 = NewUser.Address2 = NewUser.Street = NewUser.City = NewUser.State1 = NewUser.Country = NewUser.EncPass = string.Empty; DataSet ds1 = userBAL.InsertUser(NewUser); if (ds1.Tables.Count > 0) { if (ds1.Tables[0].Rows.Count > 0) { MailMessage Email = new MailMessage(); //???Email.From = new MailAddress("*****@*****.**"); Email.From = new MailAddress("*****@*****.**"); Email.To.Add(txtEmail.Text); Email.Subject = "MuLessons : Just one more step to get started"; string url = Request.Url.OriginalString.Replace("SignUp.aspx", "ConfirmPassword.aspx")+"?userid=" + txtUName.Text + "&key=" + ds1.Tables[0].Rows[0]["MailKey"].ToString(); Email.Body = "Dear " + txtFName.Text + ", <br /><br /> Thanks for signingup with MuLessons. You are almost done with the sign-up process. Please click on below link and complete the sign up process" + "<br /><a href='" + url +"'>Confirm Your Account</a>"; Email.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(); smtpClient.Host = "smtp.gmail.com"; smtpClient.Port = 587; //???smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "c@123456"); smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "c@123456"); smtpClient.EnableSsl = true; smtpClient.Send(Email); string msg = txtFName.Text + ", go to " + txtEmail.Text + " to complete the sign-up process."; txtFName.Text = txtLName.Text = txtUName.Text = txtEmail.Text = txtAnswer.Text = string.Empty; ddlSecretQuestion.SelectedIndex = 0; ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('" + msg + "');", true); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { DataTable dtUserDetails = new DataTable(); CommonBAL commonBAL = new CommonBAL(); General master = (General)this.Master; ForgotPasswordBE forgotpass = new ForgotPasswordBE(); string MessageKey = "forgotpassword"; if (Session["PasswordRequest"] == null) { Response.Redirect("~/Login.aspx"); return; } // 0 - save password request details of 2 panels - log the request // 1 - get emailmessagehtml using emailmessagekey - this is a COmmon routine COMMONDAL/BAL // 2 - get data to be replaced in emailmessagehtml - this is seperate rtn / function // 3 - now you can replace variables in emailmessagehtml by data - this should be separate rtn/func // 4 - now you are ready to prepare to send email using application level Session["CompanySetupData"] // which was prepared in Application_Start event itself - smtp server details // and body of the message will be as in step 3 // and send the message ??? how to handle delivery failures??? // dtUserDetails = (DataTable)Session["PasswordRequest"]; forgotpass.UserName = txtUserName.Text; forgotpass.PrimaryEmailId = txtPREmailID.Text; forgotpass.SecretQuest = lblSecretQuest.Text; forgotpass.SecretAns = dtUserDetails.Rows[0]["SecretAns"].ToString(); SaveForgotPassDetails(forgotpass); if (txtSecretAns.Text == forgotpass.SecretAns) { CompanySetupBE setupBE = new CompanySetupBE(); SmtpServerDetails(ref setupBE); string MailAddressFrom = setupBE.UserName; string MailAddressTo = forgotpass.PrimaryEmailId; MailMessage ms = new MailMessage(MailAddressFrom, MailAddressTo); ms.Subject = "Your Password"; ms.IsBodyHtml = true; ms.Body = HttpUtility.HtmlDecode(GetEmailMessageHTML(MessageKey)); //Add a carbon copy recipient. MailAddress copy = new MailAddress("*****@*****.**"); ms.CC.Add(copy); SmtpClient smtp = new SmtpClient(setupBE.IPAddress, Convert.ToInt32(setupBE.PortNo)); smtp.UseDefaultCredentials = true; smtp.Credentials = new NetworkCredential() { UserName = setupBE.UserName, Password = setupBE.Password }; smtp.EnableSsl = true; try { smtp.Send(ms); ms.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; Session["PasswordRequest"] = null; Session.Clear(); string url = Request.Url.OriginalString.Replace(Request.Url.AbsolutePath, "/Login.aspx?Message=Password has been sent successfully to your Email Address."); ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", "alert('Password has been sent successfully to your Email Address.'); location.href='" + url+"'", true); // Response.Redirect("~/Login.aspx?Message=Password has been sent successfully to your Email Address."); return; } catch (SmtpFailedRecipientsException ex) { for (int i = 0; i < ex.InnerExceptions.Length; i++) { SmtpStatusCode status = ex.InnerExceptions[i].StatusCode; if (status == SmtpStatusCode.MailboxBusy || status == SmtpStatusCode.MailboxUnavailable) { master.ShowMessage("Delivery failed - retrying in 5 seconds.", false); System.Threading.Thread.Sleep(5000); smtp.Send(ms); Session["PasswordRequest"] = null; Session.Clear(); string msg = Request.QueryString["Message"]; Response.Redirect("~/Login.aspx?Message=Password has been sent successfully to your Email Address."); } else { } } } catch (Exception k) { lblMessage1.Text = "Exception"; // master.ShowMessage("Exception", false); } Session["PasswordRequest"] = null; Session.Clear(); Response.Redirect("~/Login.aspx?Message=Password has been sent successfully to your Email Address."); } else { lblMessage1.Text = "Incorrect Answer"; // master.ShowMessage("Incorrect Answer", false); } }
protected void LoadUserDetails(ForgotPasswordBE forgotBE) { DataTable dtUserDetails = new DataTable(); CommonBAL commonBAL = new CommonBAL(); dtUserDetails = (DataTable)Session["PasswordRequest"]; forgotBE.FirstName = dtUserDetails.Rows[0]["FirstName"].ToString(); forgotBE.EncPass = commonBAL.Decrypt(dtUserDetails.Rows[0]["EncPass"].ToString(), false); forgotBE.UserName = dtUserDetails.Rows[0]["UserName"].ToString(); // string Password = commonBAL.Decrypt(forgotBE.EncPass, false); }
protected string GetEmailMessageHTML(string MessageKey) { //ForgotPasswordBE user = new ForgotPasswordBE(); //ForgotPasswordBAL userBAL = new ForgotPasswordBAL(); CommonBAL commonBAL = new CommonBAL(); ForgotPasswordBE forgotBE = new ForgotPasswordBE(); // string EmailMessageKey = MessageKey; string EmailMessageHTML = ""; if (commonBAL.GetEmailMessageHTML(MessageKey, ref EmailMessageHTML)) { LoadUserDetails(forgotBE); EmailMessageHTML = ReplaceVariale(EmailMessageHTML, forgotBE); return EmailMessageHTML; } else { return ""; } }
//protected void lvUserList_ItemUpdating(object sender, ListViewUpdateEventArgs e) //{ // if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "AddRec")) // { // LoggedIn master = (LoggedIn)this.Master; // master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false); // return; // } // UserBE user = new UserBE(); // UserBAL userBAL = new UserBAL(); // CommonBAL CommonBAL = new CommonBAL(); // user.LastModifiedBy = ((UserBE)Session["LoggedInUser"]).UserId; // string UserId = lvUserList.DataKeys[e.ItemIndex].Value.ToString();// // Label userName = lvUserList.Items[e.ItemIndex].FindControl("lbUserName") as Label;// // TextBox firstName = lvUserList.Items[e.ItemIndex].FindControl("txtFName") as TextBox; // TextBox middleName = lvUserList.Items[e.ItemIndex].FindControl("txtMName") as TextBox; // TextBox lastName = lvUserList.Items[e.ItemIndex].FindControl("txtLName") as TextBox; // TextBox primaryEmailId = lvUserList.Items[e.ItemIndex].FindControl("txtPREmailId") as TextBox; // TextBox secondaryEmailId = lvUserList.Items[e.ItemIndex].FindControl("txtSCEmailId") as TextBox; // TextBox mobileNo = lvUserList.Items[e.ItemIndex].FindControl("txtMobileNo") as TextBox; // TextBox address1 = lvUserList.Items[e.ItemIndex].FindControl("txtAddress1") as TextBox; // TextBox address2 = lvUserList.Items[e.ItemIndex].FindControl("txtAddress2") as TextBox; // TextBox street = lvUserList.Items[e.ItemIndex].FindControl("txtStreet") as TextBox; // TextBox city = lvUserList.Items[e.ItemIndex].FindControl("txtCity") as TextBox; // TextBox state1 = lvUserList.Items[e.ItemIndex].FindControl("txtState1") as TextBox; // TextBox country = lvUserList.Items[e.ItemIndex].FindControl("txtCountry") as TextBox; // TextBox secretQuest = lvUserList.Items[e.ItemIndex].FindControl("txtSecretQuest") as TextBox;//? // TextBox secretAns = lvUserList.Items[e.ItemIndex].FindControl("txtSecretAns") as TextBox; // TextBox Pass = lvUserList.Items[e.ItemIndex].FindControl("txtPass") as TextBox;//? // user.UserId = Convert.ToInt32(UserId); // user.UserName = userName.Text; // user.FirstName = firstName.Text; // user.MiddleName = middleName.Text; // user.LastName = lastName.Text; // user.PrimaryEmailId = primaryEmailId.Text; // user.SecondaryEmailId = secondaryEmailId.Text; // user.MobileNo = mobileNo.Text; // user.Address1 = address1.Text; // user.Address2 = address2.Text; // user.Street = street.Text; // user.City = city.Text; // user.State1 = state1.Text; // user.Country = country.Text; // user.SecretQuest = secretQuest.Text; // user.SecretAns = secretAns.Text; // user.EncPass = CommonBAL.Encrypt( Pass.Text,false); // if (userBAL.Modify(user)) // { // lvUserList.EditIndex = -1; // bindLVUser(); // LoggedIn master = (LoggedIn)this.Master; // master.ShowMessage("Record Successfully Updated.", true); // } // else // { // LoggedIn master = (LoggedIn)this.Master; // master.ShowMessage("Unsuccessful",false); // } // recalcNoOfPages(); //} protected void btnUpdate_Click(object sender, EventArgs e) { if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "edit")) { LoggedIn master = (LoggedIn)this.Master; master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false); return; } UserBE user = new UserBE(); UserBAL userBAL = new UserBAL(); CommonBAL CommonBAL = new CommonBAL(); user.LastModifiedBy = ((UserBE)Session["LoggedInUser"]).UserId; user.UserId = Convert.ToInt32(hdnUserUpdateId.Value); user.UserName = txtUserName.Text; user.FirstName = txtFirstName.Text; user.MiddleName = txtMiddleName.Text; user.LastName = txtLName.Text; user.PrimaryEmailId = txtPREmailId.Text; user.SecondaryEmailId = txtSCEmailID.Text; user.MobileNo = txtMobileNo.Text; user.Address1 = txtAddress1.Text; user.Address2 = txtAddress2.Text; user.Street = txtStreet.Text; user.City = txtCity.Text; user.State1 = txtState.Text; user.Country = txtCountry.Text; user.SecretQuest = txtSecretQuest.Text; user.SecretAns = txtSecretAns.Text; user.EncPass = CommonBAL.Encrypt(txtPass.Text, false); if (userBAL.Modify(user)) { lvUserList.EditIndex = -1; bindLVUser(); LoggedIn master = (LoggedIn)this.Master; master.ShowMessage("Record Successfully Updated.", true); } else { LoggedIn master = (LoggedIn)this.Master; master.ShowMessage("Unsuccessful", false); } recalcNoOfPages(); }