Ejemplo n.º 1
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                if (user != null)
                {
                    var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("ChangeUser"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Usuario no encontrado.");
                }
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response <object>
                {
                    Message = "This email is not assigned to any user."
                }));
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response <object>
                {
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response <object>
            {
                Message = "The password was changed successfully!"
            }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState
                                  ));
            }

            CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);

            Resource.Culture = cultureInfo;

            UserEntity user = await _userHelper.GetUserAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(Resource.UserDoesntExists
                                  ));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                string message = result.Errors.FirstOrDefault().Description;
                return(BadRequest(message.Contains("password") ? Resource.IncorrectCurrentPassword : message
                                  ));
            }

            return(Ok(Resource.PasswordChangedSuccess));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                if (user != null)
                {
                    IdentityResult result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        TempData["Success"] = "Contraseña actualizada exitosamente";
                        return(RedirectToAction(nameof(Details), new { id = user.Id }));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Usuario no encontrado.");
                }
            }

            return(View(model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await _userHelper.GetUserAsync(this.User.Identity.Name);

                if (user != null)
                {
                    var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        await _logRepository.SaveLogs("Success", "Cambiar Clave Usuario", "Account", User.Identity.Name);

                        ViewBag.SweetAlertShowMessage = SweetAlertHelper.ShowMessage("Actualizar Password", "Password Actualizado", SweetAlertMessageType.success);
                        return(this.RedirectToAction("ChangeUser"));
                    }
                    else
                    {
                        await _logRepository.SaveLogs("Error", "Cambiar Clave Usuario", "Account", User.Identity.Name);

                        ViewBag.SweetAlertShowMessage = SweetAlertHelper.ShowMessage("Actualizar Password", result.Errors.FirstOrDefault().Description, SweetAlertMessageType.error);
                    }
                }
                else
                {
                    await _logRepository.SaveLogs("Error", "Cambiar Clave Usuario ", "Account", User.Identity.Name);

                    ViewBag.SweetAlertShowMessage = SweetAlertHelper.ShowMessage("Actualizar Password", "Usuario no encontrado", SweetAlertMessageType.error);
                    //this.ModelState.AddModelError(string.Empty, "User no found.");
                }
            }

            return(this.View(model));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                if (user != null)
                {
                    var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        ViewBag.Message = "Password updated";
                        return(View());
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description); //Mostrar o primeiro erro que aparece
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "User no found.");
                }
            }

            return(View(model));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(User.Identity.Name);

                if (user != null)
                {
                    var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("ChangeUser"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "كلمة المرور الحالية خاطئة");
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "المستخدم غير موجود.");
                }
            }

            return(View(model));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            string email = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            User   user  = await _userHelper.GetUserByEmailAsync(email);

            if (user == null)
            {
                return(NotFound("Error001"));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Error005"
                }));
            }

            return(Ok(new Response {
                IsSuccess = true
            }));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> ChangePasswordMVC(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userHelper.GetUserAsync(User.Identity.Name);

                if (user != null)
                {
                    Microsoft.AspNetCore.Identity.IdentityResult result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("ChangeUser"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "User no found.");
                }
            }

            return(View(model));
        }
Ejemplo n.º 10
0
        internal async Task ChangePassword(ChangePasswordRest changePassword)
        {
            var user = await _userHelper.GetUserByEmailAsync(changePassword.Email);

            if (user == null)
            {
                throw new Exception("Email Not Exists");
            }
            await _userHelper.ChangePasswordAsync(user, changePassword.OldPassword, changePassword.NewPassword);
        }
        public async Task <IActionResult> ResetPasswordFromEditUser(UpdateUserDataViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _converterHelper.ToUserFromEditUserResetPassword(model);

                if (user == null)
                {
                    return(NotFound());
                }

                string newPassword = model.NewPassword;

                var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, newPassword);

                if (result.Succeeded)
                {
                    return(Redirect($"EditUser/{user.Id}"));
                }
            }
            return(RedirectToAction("EditUser", new { id = model.User.Id }));
        }
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);

            Resource.Culture = cultureInfo;

            UserEntity user = await _userHelper.GetUserAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "User doesn't exist"
                              //Message = Resource.UserDoesntExists
                }));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                string message = result.Errors.FirstOrDefault().Description;
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = message.Contains("password") ? "Incorrect password" : message
                              //Message = message.Contains("password") ? Resource.IncorrectCurrentPassword : message
                }));
            }

            return(Ok(new Response
            {
                IsSuccess = true,
                Message = "Changed password success"
                          //Message = Resource.PasswordChangedSuccess
            }));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);

            Resource.Culture = cultureInfo;

            UserEntity user = await _userHelper.GetUserAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = Resource.UserDoesntExists
                }));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                string message = result.Errors.FirstOrDefault().Description;

                //si Contains tiene la palabra "password" entonces mensaje incorrecto,
                //caso contrario nos devuelve un mensaje del sistema(BadRequest)
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = message.Contains("password") ? Resource.IncorrectCurrentPassword : message
                }));
            }

            return(Ok(new Response
            {
                IsSuccess = true,
                Message = Resource.PasswordChangedSuccess
            }));
        }
Ejemplo n.º 14
0
        public async Task<IActionResult> ChangePassword(EditUserViewModel viewModel)
        {
            ViewBag.Title = MessageCenter.webAppTitlePageEditUser;
            if (ModelState.IsValid)
            {
                var usuario = await _userHelper.GetUsuarioTAByEmailAsync(User.Identity.Name);
                var result  = await _userHelper.ChangePasswordAsync(usuario.UserLogin, viewModel.OldPassword, viewModel.NewPassword);
                if (result.Succeeded)
                   { return RedirectToAction("ChangeUser"); }

               ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description); 
                
            }

            return View(viewModel);
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            CultureInfo cultureInfo = new CultureInfo(request.CultureInfo);

            Resource.Culture = cultureInfo;

            UserEntity user = await _userHelper.GetUserAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = Resource.UserNotFoundError
                }));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response
            {
                IsSuccess = true,
                Message = Resource.ChangePasswordSuccess
            }));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }



            UserEntity user = await _userHelper.GetUserAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Error to user"
                }));
            }

            IdentityResult result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response
            {
                IsSuccess = true,
                Message = "Reponse succes"
            }));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> ChangePasswordMVC(ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userHelper.GetUserAsync(User.Identity.Name); //bucamos el user

                var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    return(RedirectToAction("ChangeUser"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description); //manda los errores hasta solucionarlo
                }
            }

            return(View(model));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "Bad request"
                }));
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "El correo ingresado no existe."
                }));
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response <object>
            {
                IsSuccess = true,
                Message = "La contraseña fue cambiada exitosamente!"
            }));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "Bad request"
                }));
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "This email is not assigned to any user."
                }));
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response <object>
            {
                IsSuccess = true,
                Message = "La contraseña cambio de forma correcta!."
            }));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> ChangePasswor([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "اتصال غير جيد"
                }));
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "لم يتم تعيين هذا البريد الإلكتروني لأي مستخدم."
                }));
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response <object>
            {
                IsSuccess = true,
                Message = "تم تغيير كلمة المرور بنجاح!"
            }));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "Bad request"
                }));
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);

            if (user == null)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = "Este email no ha sido asignado a ningun usuario."
                }));
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(new Response <object>
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                }));
            }

            return(Ok(new Response <object>
            {
                IsSuccess = true,
                Message = "El password ha sido cambiado satisfactoriamente!"
            }));
        }
Ejemplo n.º 22
0
        public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordRequest request)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(new Response<object>
                {
                    IsSuccess = false,
                    Message = "Solicitud incorrecta"
                });
            }

            var user = await _userHelper.GetUserByEmailAsync(request.Email);
            if (user == null)
            {
                return BadRequest(new Response<object>
                {
                    IsSuccess = false,
                    Message = "Este correo electrónico no está asignado a ningún usuario"
                });
            }

            var result = await _userHelper.ChangePasswordAsync(user, request.OldPassword, request.NewPassword);
            if (!result.Succeeded)
            {
                return BadRequest(new Response<object>
                {
                    IsSuccess = false,
                    Message = result.Errors.FirstOrDefault().Description
                });
            }

            return Ok(new Response<object>
            {
                IsSuccess = true,
                Message = "La contraseña fue cambiada exitosamente!"
            });
        }
        public async Task <IActionResult> UpdatePassword(ChangePasswordViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await GetCurrentUser();

                if (user == null)
                {
                }
                var result = await _userHelper.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

                if (result.Succeeded)
                {
                    return(this.RedirectToAction(nameof(AccountManager)));
                }
                else
                {
                    this.ModelState.AddModelError(string.Empty, result.Errors.FirstOrDefault().Description);
                }
                this.ModelState.AddModelError(string.Empty, "User no found.");
            }

            return(PartialView(nameof(AccountManager), model));
        }