public IdentityResult changePassword(passwordModel pm)
        {
            Employee emp = db.Employees.Find(pm.EmpId);

            var userStore = new UserStore<IdentityUser>();
            var UserManager = new UserManager<IdentityUser>(userStore);

            var user = UserManager.FindByName(emp.Email);

            return UserManager.ChangePassword(user.Id, pm.oldPassword, pm.newPassword);
        }
Example #2
0
 protected void ChangePassword_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         UserManager manager = new UserManager();
         IdentityResult result = manager.ChangePassword(User.Identity.GetUserId(), CurrentPassword.Text, NewPassword.Text);
         if (result.Succeeded)
         {
             Response.Redirect("~/Account/Manage?m=ChangePwdSuccess");
         }
         else
         {
             AddErrors(result);
         }
     }
 }
        protected void Btn_Submit_Click(object sender, EventArgs e)
        {
            if(TxtNewPassword.Text.Equals(TxtConfirmPassword.Text,StringComparison.CurrentCulture))
            {
                StatusMessage.Text = "<span class='errorText'>Password & Confirm Password do not match!</span>";
            }

            var userStore = new UserStore<IdentityUser>();
            var manager = new UserManager<IdentityUser>(userStore);

            var result = manager.ChangePassword(this.Page.User.Identity.GetUserId(), TXtCurrentPassword.Text, TxtNewPassword.Text);
            if(result.Succeeded)
            {
                StatusMessage.Text = "<span class='errorText'>we have changed your password successfully!</span>";
            }
            else
            {
                StatusMessage.Text = "<span class='errorText'>Please try after some time, we are having issues!</span>";
            }

        }
        protected void grvUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = grvUsers.Rows[e.RowIndex];
            var id = grvUsers.DataKeys[e.RowIndex].Value.ToString();

            var firstName = ((TextBox)row.FindControl("txtFirstName")).Text;
            var lastName = ((TextBox)row.FindControl("txtLastName")).Text;
            var email = ((TextBox)row.FindControl("txtEmail")).Text;
            var currentPassword = ((TextBox)row.FindControl("txtCurrentPassword")).Text;
            var newPassword = ((TextBox)row.FindControl("txtNewPassword")).Text;
            var role = ((DropDownList)row.FindControl("ddlRoleEdit")).Text;
            var jobClinic = ((DropDownList)row.FindControl("ddlJobClinicEdit")).Text; //TODO: Automatically edit RelationType (exept Writer) on files.
            var isActive = ((CheckBox)row.FindControl("chkIsActive")).Checked;

            var userStore = new UserStore<IdentityUser>();
            var userManager = new UserManager<IdentityUser>(userStore);
            var user = userManager.FindById(id);

            if (user != null && (
                userManager.FindById(SharedClass.CurrentUser).UserName == "Admin" ||
                user.UserName != "Admin"
                ))
            {
                if (newPassword != "")
                {
                    var result = userManager.ChangePassword(id, currentPassword, newPassword);
                }
                userManager.SetEmail(id, email);
                userManager.RemoveFromRoles(id, userManager.GetRoles(id).ToArray());
                userManager.AddToRole(id, role);

                using (Medical_Clinic_Entities mc = new Medical_Clinic_Entities())
                {
                    BSI__Clinic_Employee employee = mc.BSI__Clinic_Employees.Where(o => o.Id == id).First();
                    employee.First_Name = firstName;
                    employee.Last_Name = lastName;
                    employee.Job_Clinic = jobClinic;
                    employee.Is_Active = isActive;

                    mc.SaveChanges();
                }
            }
            grvUsers.EditIndex = -1;
        }