Пример #1
0
        public IHttpActionResult ChangePassword(RequestChangePassword request)
        {
            try
            {
                bool autorization = false;
                if (Request.Headers.Authorization != null)
                {
                    string Jwt = Request.Headers.Authorization.Parameter;
                    autorization = new BJwt().ConsultarJwt(Jwt);
                }

                if (!autorization)
                {
                    Resultado res = new Resultado()
                    {
                        Mensaje = "Token Invalido", Respuesta = 0
                    };
                    return(Ok(res));
                }
                Resultado resultado = new BUser().ChangePassword(request);
                if (resultado.Respuesta == 1)
                {
                    return(Ok(resultado));
                }
                else
                {
                    return(BadRequest(resultado.Mensaje));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Пример #2
0
 public Resultado ChangePassword(RequestChangePassword request)
 {
     try
     {
         var changed = new DUsuario().ChangePassword(request);
         if (changed)
         {
             return(new Resultado()
             {
                 Respuesta = 1, Mensaje = "Contraseña cambiada", Valores = null
             });
         }
         return(new Resultado()
         {
             Respuesta = 0, Mensaje = "Datos ingresados invalidos", Valores = null
         });
     }
     catch (Exception ex)
     {
         return(new Resultado()
         {
             Respuesta = 0, Mensaje = "Error", Valores = ex
         });
     }
 }
        private async Task ChangePassword()
        {
            try
            {
                if (ValidateData())
                {
                    RequestChangePassword request = new RequestChangePassword
                    {
                        NewPassword = NewPassword,
                        OldPassword = Password,
                        UserName    = Email
                    };
                    ResponseChangePassword response = await apiService.ChangePassword(request);

                    if (response.Success && response.StatusCode == 0)
                    {
                        Password = string.Empty;
                        Email    = string.Empty;
                        await dialogService.ShowMessage("", "Contraseña cambiada con éxito");

                        await navigationService.Navigate(AppPages.LoginPage);
                    }
                }
            }
            catch (Exception e)
            {
                ServiceLocator.Current.GetInstance <IExceptionService>().RegisterException(e);
            }
        }
Пример #4
0
        public IActionResult RecoverPassword(string email, [FromServices] LorgusContext context, [FromServices] IEmailSender emailSender)
        {
            var user = context.User.FirstOrDefault(u => u.Email.ToLower() == email.ToLower());

            var emailTitle = "Recuperação de Senha";

            if (user is null)
            {
                ViewData["messageError"] = "E-mail não encontrado!";

                return(View());
            }

            var request = new RequestChangePassword
            {
                Date   = DateTime.Now,
                UserId = user.UserId,
                RequestChangePasswordId = Guid.NewGuid().ToString()
            };

            var requestPassword = context.RequestChangePassword.Add(request);

            context.SaveChanges();

            var attachments = new List <Attachment>
            {
                new Attachment($"{_env.WebRootPath}/images/logo.png")
                {
                    ContentId = "Logo"
                }
            };

            var replacements = new Dictionary <string, string>
            {
                { "{{name}}", user.FullName },
                { "{{action_url}}", Url.Action("ResetPassword", "Account", new { id = request.RequestChangePasswordId }, Request.Scheme) },
                { "{{logo}}", "Logo" },
                { "{{date}}", DateTime.UtcNow.AddHours(-3).ToString("dd/MM/yyyy HH:mm:ss") },
            };

            var to = new MailAddress(user.Email, user.FullName);

            var body = System.IO.File.ReadAllText($"Templates/EmailRecoveryPasswordTemplate.html");

            try
            {
                emailSender.Send(to, body, emailTitle, replacements, attachments);

                TempData["messageSuccess"] = "Recuperação enviada com sucesso!";
            }
            catch (Exception)
            {
                TempData["messageError"] = "Não foi possível enviar a Recuperação!";
            }

            return(RedirectToAction("Login"));
        }
Пример #5
0
        public IActionResult Create([FromForm] User model, [FromServices] LorgusContext context, [FromServices] IEmailSender emailSender)
        {
            model.Phone = Regex.Replace(model.Phone, @"\D+", string.Empty);

            model.AccessLevelId = 2;

            context.User.Add(model);

            context.SaveChanges();

            var request = new RequestChangePassword
            {
                Date   = DateTime.Now,
                UserId = model.UserId,
                RequestChangePasswordId = Guid.NewGuid().ToString()
            };

            var requestPassword = context.RequestChangePassword.Add(request);

            context.SaveChanges();

            var attachments = new List <Attachment>
            {
                new Attachment($"{_env.WebRootPath}/images/logo.png")
                {
                    ContentId = "Logo"
                }
            };

            var replacements = new Dictionary <string, string>
            {
                { "{{name}}", model.FullName },
                { "{{action_url}}", Url.Action("ResetPassword", "Account", new { id = request.RequestChangePasswordId }, Request.Scheme) },
                { "{{logo}}", "Logo" },
                { "{{date}}", DateTime.UtcNow.AddHours(-3).ToString("dd/MM/yyyy HH:mm:ss") },
            };

            var to = new MailAddress(model.Email, model.FullName);

            var body = System.IO.File.ReadAllText($"Templates/EmailNewUserTemplate.html");

            try
            {
                emailSender.Send(to, body, "Bem vindo a Lorgus", replacements, attachments);
            }
            catch
            {
            }

            return(RedirectToAction(nameof(Index)));
        }
Пример #6
0
        public bool ChangePassword(User entity, RequestChangePassword user)
        {
            if (string.IsNullOrEmpty(user.Token) && entity.Password != GetMd5Hash(user.Password))
            {
                return(false);
            }

            entity.Password = GetMd5Hash(user.NewPassword);
            entity.Token    = string.Empty;

            UserRepository.Update(entity);

            return(true);
        }
Пример #7
0
        /// <summary>
        /// Handles the Click event of the btnOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool   sendRequest = true;
                string error       = "";
                if (txtNewPass.Password != txtConfPass.Password)
                {
                    sendRequest = false;
                    error       = "The confirmation password that you entered does not match the password that you entered."
                                  + "Please ensure that the password and confirmation match exactly";
                }

                if (sendRequest)
                {
                    var changepassword = (ProtocolManagers.Instance().ProtocolManager[ServerType.Configserver.ToString()] as ConfServerProtocol).Request(
                        RequestChangePassword.Create(_dataContext.UserName, txtOldPass.Password, txtConfPass.Password));
                    if (changepassword is EventPasswordChanged)
                    {
                        _logger.Info((changepassword as EventPasswordChanged).ToString());
                        this.DialogResult = true;
                        this.Close();
                    }
                    else if (changepassword is Genesyslab.Platform.Configuration.Protocols.ConfServer.Events.EventError)
                    {
                        error = (changepassword as Genesyslab.Platform.Configuration.Protocols.ConfServer.Events.EventError).Description;
                        _dataContext.CSErrorMessage   = error;
                        _dataContext.CSErrorRowHeight = GridLength.Auto;
                        StartTimerForError();
                        _logger.Info(error);
                    }
                }
                else
                {
                    _dataContext.CSErrorMessage   = error;
                    _dataContext.CSErrorRowHeight = GridLength.Auto;
                    StartTimerForError();
                }
            }
            catch (ChangePasswordException chaPEx)
            {
                _dataContext.CSErrorMessage   = chaPEx.Message;
                _dataContext.CSErrorRowHeight = GridLength.Auto;
                StartTimerForError();
                _logger.Error(chaPEx.Message);
            }
        }
Пример #8
0
        public IActionResult ChangePassword([FromBody] RequestChangePassword request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            User user = Component.Get(request.IdUser);

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

            bool response = Component.ChangePassword(user, request);

            if (response)
            {
                return(Ok());
            }

            return(BadRequest());
        }
Пример #9
0
        private async void ChangePassword()
        {
            if (ValidateData())
            {
                if (await dialogService.ShowConfirm("Estás a punto de cambiar tu contraseña", "¿Estás seguro que la deseas cambiar?"))
                {
                    dialogService.ShowProgress();
                    RequestChangePassword request = new RequestChangePassword
                    {
                        NewPassword = NewPassword,
                        OldPassword = OldPassword,
                        UserName    = ServiceLocator.Current.GetInstance <ILoginViewModel>().User.UserName
                    };
                    ResponseChangePassword response = await apiService.ChangePassword(request);

                    dialogService.HideProgress();
                    ValidateDataResponseChangePassword(response);
                }
                return;
            }

            await dialogService.ShowMessage(AppResources.TittleInvalidData, "Hay registros con errores.");
        }
Пример #10
0
 public bool ChangePassword(RequestChangePassword request)
 {
     try
     {
         bool result = false;
         using (WantgoProdEntities ctx = new WantgoProdEntities())
         {
             var query = (from u in ctx.usuario
                          where request.UserId == u.id_usuario && request.OldPassword == u.password
                          select u).FirstOrDefault();
             if (query != null)
             {
                 query.password = request.NewPassword;
                 ctx.SaveChanges();
                 result = true;
             }
         }
         return(result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }