示例#1
0
        public async Task <Retorno> AlterarSenha(AlterarSenhaDTO command)
        {
            try
            {
                var User = await _userManager.FindByNameAsync(command.UserName);

                var usuario = await _signInManager.PasswordSignInAsync(User, command.SenhaAtual, false, true);

                if (!usuario.Succeeded)
                {
                    return(new Retorno(false, "Senha atual não confere.", "Senha atual não confere."));
                }

                var token = await _userManager.GeneratePasswordResetTokenAsync(User);

                var result = await _userManager.ResetPasswordAsync(User, token, command.Password);

                if (!result.Succeeded)
                {
                    return(new Retorno(false, "Não foi possivel atualizar a senha. Tente novamente.", "Não foi possivel atualizar a senha. Tente novamente."));
                }

                return(new Retorno(true, "Senha Atualizados Com Sucesso.", "Senha Atualizados Com Sucesso."));
            }
            catch (Exception ex)
            {
                _log.GerarLogDisc("Erro ao Atualizar a senha do Usuario", ex: ex);
                throw new Exception("Erro ao Atualizar a senha do Usuario", ex);
            }
        }
示例#2
0
        public async Task <ICommandResult> AlterarSenha(AlterarSenhaDTO command, ELogin acoes)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new Retorno(false, "Dados Inválidos!", command.Notifications));
            }

            return(await _repository.AlterarSenha(command));
        }
 public ActionResult alterarSenha(long id, AlterarSenhaDTO alterarSenhaDto)
 {
     try
     {
         _usuarioRepository.alterarSenha(id, alterarSenhaDto);
         return(NoContent());
     } catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#4
0
 public void alterarSenha(long id, AlterarSenhaDTO alterarSenhaDto)
 {
     if (id == alterarSenhaDto.id)
     {
         Usuario usuario = Get(id);
         if (HashService.VerifyHash(alterarSenhaDto.senhaAtual, usuario.Senha))
         {
             if (alterarSenhaDto.novaSenha != alterarSenhaDto.confirmacaoSenha)
             {
                 throw new Exception("Nova senha e confirmação incorretas");
             }
             var novaSenha = HashService.GenerateHash(alterarSenhaDto.novaSenha);
             usuario.Senha = novaSenha;
             Update(usuario);
         }
         else
         {
             throw new Exception("Senha atual incorreta");
         }
     }
 }