Example #1
0
        public async Task <IActionResult> ResetPasswordEmail(ResetPasswordEmail emailModel)
        {
            if (ModelState.IsValid)
            {
                var user = _uow.UsersRepository.Get(ent => ent.Email == emailModel.Email);
                if (user != null)
                {
                    var log = new ForgetPasswordURL();
                    log.ToId       = user.Id;
                    log.ToType     = (int)EN_TypeUser.User;
                    log.Token      = Guid.NewGuid();
                    log.Expiration = DateTime.Now.AddMinutes(30);


                    _uow.ForgetPasswordURLRepository.Add(log);
                    _uow.Save();

                    var    subject = "Reset Password Confirmation Email";
                    string url1    = $"{AppSession.AppURL}Account/ResetPassword?token={ log.Token }";
                    var    model   = new EmailModelsResetPass();
                    model.Url = url1;
                    string htmlbody = await _razorViewToStringRenderer.RenderViewToStringAsync("/Views/Emails/_ResetPasswordEmail.cshtml", model);

                    var emailsendstatus = EmailsSettings.EmailSend(user.EnglishName, user.Email, subject, htmlbody);
                    if (!emailsendstatus)
                    {
                        ModelState.AddModelError("Email", "Error Occured While Send Email!!");
                    }
                    else
                    {
                        return(RedirectToAction("ResetPasswordDone", "Account"));
                    }
                }
                else
                {
                    ModelState.AddModelError("Email", "No Email Found Match Entered Email");
                }
            }
            return(View(emailModel));
        }
        public async Task <IActionResult> CustomerResetPasswordEmail(ResetPasswordEmail emailModel)
        {
            if (ModelState.IsValid)
            {
                var customer = _uow.CustomerRepository.Get(ent => ent.Email == emailModel.Email);
                if (customer != null)
                {
                    var log = new ForgetPasswordURL();
                    log.ToId       = customer.Id;
                    log.ToType     = (int)EN_TypeUser.Customer;
                    log.Token      = Guid.NewGuid();
                    log.Expiration = DateTime.Now.AddMinutes(30);


                    _uow.ForgetPasswordURLRepository.Add(log);
                    _uow.Save();

                    var    subject = "Reset Password Confirmation Email";
                    string url1    = $"{AppSession.AppURL}Account/ResetPassword?token={ log.Token }";
                    var    model   = new EmailModelsResetPass();
                    model.Url = url1;
                    string htmlbody = await _razorViewToStringRenderer.RenderViewToStringAsync("/Views/Emails/_ResetPasswordEmail.cshtml", model);

                    var emailsendstatus = EmailsSettings.EmailSend(customer.EnglishName, customer.Email, subject, htmlbody);
                    if (!emailsendstatus)
                    {
                        ModelState.AddModelError("Email", "Error Occured While Send Email!!");
                    }
                    else
                    {
                        return(Ok(new ApiResponseModel
                        {
                            Status = EN_ResponseStatus.Success,
                            Message = "Reset Password Email Sent Check Your Email",
                            Data = null,
                            Errors = null
                        }));
                    }
                }
                else
                {
                    ModelState.AddModelError("Email", "No Email Found Match Entered Email");
                }
            }
            var errors      = ModelState.Select(ent => new { key = ent.Key, value = ent.Value.Errors.Select(err => (err.ErrorMessage == null || err.ErrorMessage == "") ? err.Exception.Message : err.ErrorMessage) });
            var errors_list = new List <string>();

            foreach (var sublist in errors)
            {
                foreach (var item in sublist.value)
                {
                    errors_list.Add(sublist.key + ": " + item);
                }
            }
            return(Ok(new ApiResponseModel
            {
                Status = EN_ResponseStatus.Faild,
                Message = "Error Occured",
                Data = null,
                Errors = errors_list.ToArray()
            }));
        }