Esempio n. 1
0
        private void btnUpdateUser_Click(object sender, EventArgs e)
        {
            try
            {
                MembershipUser user = new MembershipUser(userProvider.Name, txtUsername.Text, txtUserId.Text, txtEmail.Text, txtPasswordQuestion.Text,
                                                         txtComment.Text, chkApproved.Checked, chkIsLockedOut.Checked, Convert.ToDateTime(txtDateCreate.Text), Convert.ToDateTime(txtLastLoginDate.Text),
                                                         Convert.ToDateTime(txtLastActivityDate.Text), Convert.ToDateTime(txtLastPasswordChagedDate.Text), Convert.ToDateTime(txtLastLockedOutDate.Text));

                userProvider.UpdateUser(user, txtPasswordAnswer.Text, txtComment.Text);

                MessageBox.Show("User updated successfully", "Update user", MessageBoxButtons.OK, MessageBoxIcon.Information);

                loadUsers();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show("Failed to update user, " + ex.Message, "Update user", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Failed to update user, " + ex.Message, "Update user", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update user, " + ex.Message, "Update user", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 2
0
        public ActionResult ResetPassword(string userId, string password)
        {
            if (Request.IsAuthenticated)
            {
                return(RedirectToAction("Main", "Main"));
            }
            if (userId != null && password != null)
            {
                int idUser;
                if (Int32.TryParse(userId, out idUser))
                {
                    User user = myOSBB.Users.FirstOrDefault(u => u.Id == idUser);
                    if (user.CodeForResetPassword == password)
                    {
                        ViewBag.UserId            = user.Id;
                        user.CodeForResetPassword = null;
                        CustomMembershipProvider customMembershipProvider = new CustomMembershipProvider();
                        customMembershipProvider.UpdateUser(user.Id, user.Login, user.Password,
                                                            user.FirstName, user.LastName, user.MiddleName, user.Email, user.Phone, user.CodeForResetPassword);
                        return(View());
                    }
                    else
                    {
                        return(RedirectToAction("Main", "Main"));
                    }
                }
                else
                {
                    return(RedirectToAction("Main", "Main"));
                }
            }

            return(RedirectToAction("Main", "Main"));
        }
Esempio n. 3
0
        protected void btnUpdateUser_Click(object sender, EventArgs e)
        {
            hidTAB.Value = "#tab1";
            try
            {
                bool updateUser = mp.UpdateUser(this.txtUsername.Text, this.txtfName.Text, this.txtlName.Text, this.ddlRoleName.SelectedValue, this.txtEmail.Text, Convert.ToDecimal(this.hidUerID.Value));

                if (updateUser == true)
                {
                    this.lblUsrMsg.Text = MessageFormatter.GetFormattedSuccessMessage("User Updated Succesfully!");
                    clearForm();
                    GridView2.DataBind();
                }
                else
                {
                    this.lblUsrMsg.Text = MessageFormatter.GetFormattedErrorMessage("Error Updating User!");
                    clearForm();
                }
            }
            catch (Exception ex)
            {
                this.lblUsrMsg.Text = MessageFormatter.GetFormattedErrorMessage("Error:" + ex.Message);
                clearForm();
            }


            this.txtUsername.Enabled = true; this.txtPassword.Enabled = true;
            // this.txtConfirmPasswd.Enabled = true;
            this.btnUpdateUser.Visible = false;
            this.btnCreateUser.Visible = true;
            Usrs.Attributes.Add("class", "active");
        }
Esempio n. 4
0
        public ActionResult ResetPassword(ResetPassword model)
        {
            if (ModelState.IsValid)
            {
                User user = myOSBB.Users.FirstOrDefault(u => u.Id == model.UserId);
                if (user == null)
                {
                    ViewBag.EmailError = "Користувача з такою поштовою скринькою не існує";
                    return(View("ForgotPassword"));
                }
                if (model.Password == model.PasswordConfirm)
                {
                    user.Password = Crypto.HashPassword(model.Password);
                }
                CustomMembershipProvider customMembershipProvider = new CustomMembershipProvider();
                customMembershipProvider.UpdateUser(user.Id, user.Login, user.Password,
                                                    user.FirstName, user.LastName, user.MiddleName, user.Email, user.Phone, user.CodeForResetPassword);

                return(RedirectToAction("Login", "Account"));
            }
            return(View(model));
        }
Esempio n. 5
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = myOSBB.Users.FirstOrDefault(u => u.Email == model.Email);
                if (user == null)
                {
                    ViewBag.EmailError = "Користувача з такою поштовою скринькою не існує";
                    return(View("ForgotPassword"));
                }
                Random R = new Random();
                user.CodeForResetPassword = Crypto.HashPassword(((long)R.Next(0, 100000) * (long)R.Next(0, 100000)).ToString().PadLeft(10, '0'));
                CustomMembershipProvider customMembershipProvider = new CustomMembershipProvider();
                customMembershipProvider.UpdateUser(user.Id, user.Login, user.Password,
                                                    user.FirstName, user.LastName, user.MiddleName, user.Email, user.Phone, user.CodeForResetPassword);
                EmailService emailService = new EmailService();
                var          callbackUrl  = Url.Action("ResetPassword", "Account",
                                                       new { userId = user.Id, password = user.CodeForResetPassword }, protocol: Request.Url.Scheme);
                emailService.SendEmail(user.Email, "Зміна паролю", "Для зміни пароля перейдіть по посиланню " + callbackUrl + "\"");

                return(RedirectToAction("ForgotPasswordConfirmation", "Account"));
            }
            return(View(model));
        }