Ejemplo n.º 1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            //rGen = new Random();

            FormTable.Visible = true;
            SentTable.Visible = false;

            if (Page.IsPostBack)
            {
                if (Request.Form["userName"] != null && Request.Form["userName"].ToString().Length > 0)
                {
                    FormTable.Visible = false;
                    SentTable.Visible = true;

                    //take username and get password
                    UserDa  da = new UserDa();
                    DataSet ds = da.GetByUserName(userName.Value);


                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string userStatus = da.GetUserStatus(userName.Value);
                        if (userStatus.Equals("Valid"))
                        {
                            string userEmail     = ds.Tables[0].Rows[0]["UserEmail"].ToString();
                            string userFirstName = ds.Tables[0].Rows[0]["UserFirstName"].ToString();
                            string userLastName  = ds.Tables[0].Rows[0]["UserLastName"].ToString();

                            //set new password in database
                            string newPassword = this.SetRandomPassword(userEmail);

                            if (!newPassword.Equals("false"))
                            {
                                //email new random password
                                this.EmailNewPassword(userEmail, userFirstName, userLastName, newPassword);

                                emailMessage.Text = "An email with a new password has been sent to " + userEmail + ".\n\n<br>Please update this password on first login. Thank you.";
                            }
                            else
                            {
                                //update of password failed
                                emailMessage.Text = "There was a problem updating your password. Please contact " + CaisisConfiguration.GetWebConfigValue("adminEmail") + " to request a new password.";
                            }
                        }
                        else if (userStatus.Equals("InvalidDeactivated"))
                        {
                            //Deactivated user
                            emailMessage.Text = "User has been deactivated. Please contact " + CaisisConfiguration.GetWebConfigValue("adminEmail") + ".";
                        }
                        else
                        {
                            //InvalidUnknown. InvalidUsername should never get here because of 'if(ds.Tables[0].Rows.Count > 0)' above.
                            emailMessage.Text = "There was an unknown problem updating your password. Please contact " + CaisisConfiguration.GetWebConfigValue("adminEmail") + " to request a new password.";
                        }
                    }
                    else
                    {
                        emailMessage.Text = "The username you entered does not have an email address on file. Please contact the Administrator to obtain a new password.";
                    }

                    ValidationMsg.Visible = false;
                }
                else
                {
                    ValidationMsg.InnerText = "You must enter your username to request a new password.";
                }
            }
        }