Ejemplo n.º 1
0
        public virtual async Task <ActionResult> SendEmail(SendEmailProfileViewModel sendEmail)
        {
            try
            {
                string Messagedate = ConvertDate.PerssionDate(DateTime.Now);
                string Explainbody;
                using (var reader = new StreamReader(Server.MapPath("~/EmailConfiguration/TemplateEmail/_AlertModerators.txt")))
                {
                    Explainbody = reader.ReadToEnd();
                }
                string resultBody = string.Format(Explainbody, string.Concat(sendEmail.Name + " " + sendEmail.Family),
                                                  sendEmail.Subject, sendEmail.Explain.Replace("\r\n", "<br />"), Messagedate);
                await _userManager.SendEmailAsync(sendEmail.Id, sendEmail.Subject, resultBody);

                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.SuccessSendEmail),
                    Status = AlertMode.success
                }));
            }
            catch
            {
                return(PartialView(MVC.admin.Shared.Views._alert, new AlertViewModel
                {
                    Alert = AlertOperation.SurveyOperation(StatusOperation.FailSendEmail),
                    Status = AlertMode.warning
                }));
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> ForgotPassword(ForgetPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.Email);

                var result = await _userManager.IsEmailConfirmedAsync(user.Id);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user.Id)))
                {
                    return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.NoExistEmail), Status = AlertMode.info
                    }));
                }

                try
                {
                    var code = await _userManager.GeneratePasswordResetTokenAsync(user.Id);

                    var callbackUrl = Url.Action(MVC.Account.ActionNames.ResetPassword, MVC.Account.Name,
                                                 new { userId = user.Id, code }, protocol: Request.Url.Scheme);


                    string Messagedate = ConvertDate.PerssionDate(DateTime.Now);
                    string Explainbody;
                    using (var reader = new StreamReader(Server.MapPath("~/EmailConfiguration/TemplateEmail/_ForgotPassword.txt")))
                    {
                        Explainbody = reader.ReadToEnd();
                    }
                    string UserName   = ((user.Name != null) && (user.Family != null)) ? string.Concat(user.Name + " " + user.Family) : user.Email;
                    string resultBody = string.Format(Explainbody, UserName, "ویرایش رمز عبور", callbackUrl, Messagedate);
                    await _userManager.SendEmailAsync(user.Id, "ویرایش رمز عبور در فناوران اطلاعات ارم وب", resultBody);

                    return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.ResetPassword), Status = AlertMode.success
                    }));
                }
                catch
                {
                    return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                        Alert = AlertOperation.SurveyOperation(StatusOperation.FailSendEmail), Status = AlertMode.warning
                    }));
                }
            }
            return(PartialView(viewName: MVC.admin.Shared.Views._alert, model: new AlertViewModel {
                Alert = AlertOperation.SurveyOperation(StatusOperation.Invalid), Status = AlertMode.warning
            }));
        }