예제 #1
0
        public async Task <ActionResult> Contact(EmailModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var body = "<p>Email From: <bold>{0}</bold>({1})</p><p>Message:</p><p>{2}</p> ";
                    var from = WebConfigurationManager.AppSettings["emailto"];

                    var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"])
                    {
                        Subject = model.Subject,
                        Body    = string.Format(body, model.FromName, model.FromEmail,
                                                model.Body),
                        IsBodyHtml = true
                    };

                    var svc = new PersonalEmailService();
                    await svc.SendAsync(email);

                    ModelState.Clear();
                    return(View(new EmailModel()));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    await Task.FromResult(0);
                }
            }
            return(View(model));
        }
예제 #2
0
        public async Task <ActionResult> Contact(EmailModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var body = "<p>Email From: <bold>{0}</bold> ({1})</p><p>Message:</p><p>{2}</p>";
                    var from = $"Bug-A-Boo<{model.FromEmail}>";
                    //model.Body = "This is a message from your blog site.  The name and the email of the contacting person is above.";
                    var email = new MailMessage(from, ConfigurationManager.AppSettings["emailto"])
                    {
                        Subject    = model.Subject,
                        Body       = string.Format(body, model.FromName, model.FromEmail, model.Body),
                        IsBodyHtml = true
                    };
                    var svc = new PersonalEmailService();
                    await svc.SendAsync(email);

                    return(RedirectToAction("Index", "Home"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    await Task.FromResult(0);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #3
0
        public Task SendAsync(IdentityMessage message)
        {
            var personalEmailService = new PersonalEmailService();
            var mailMessage          = new MailMessage(
                WebConfigurationManager.AppSettings["emailto"],
                message.Destination
                );

            mailMessage.IsBodyHtml = true;
            return(personalEmailService.SendAsync(mailMessage));
        }
예제 #4
0
        public Task SendAsync(IdentityMessage message)
        {
            var personalEmailService = new PersonalEmailService();
            var mailMessage          = new MailMessage(
                WebConfigurationManager.AppSettings["username"],
                message.Destination
                );

            mailMessage.Body    = message.Body;
            mailMessage.Subject = message.Subject;
            return(personalEmailService.SendAsync(mailMessage));
        }
예제 #5
0
 public Task SendAsync(IdentityMessage message)
 {
     // Plug in your email service here to send an email.
     var personalEmailService = new PersonalEmailService();
     var mailMessage = new MailMessage(
        WebConfigurationManager.AppSettings["emailto"],
        message.Destination
        );
     mailMessage.Body = message.Body;
     mailMessage.Subject = message.Subject;
     mailMessage.IsBodyHtml = true;
     return personalEmailService.SendAsync(mailMessage);
 }
        public async Task <ActionResult> Register(ExtendedRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    UserName  = model.Email,
                    Email     = model.Email,
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    var from = $"Bug-A-Boo<{ConfigurationManager.AppSettings["emailfrom"]}>";
                    try
                    {
                        var email = new MailMessage(from, model.Email)
                        {
                            Subject    = "Confirmation",
                            Body       = "Confirm your account<a class='btn btn-primary' href=\"" + callbackUrl + "\"> Confirm </a>",
                            IsBodyHtml = true
                        };
                        var svc = new PersonalEmailService();
                        await svc.SendAsync(email);

                        ViewBag.Message = "You Must Confirm Your Email To Login";
                        //return RedirectToAction("StartLogin", "Account");
                        return(View("Info"));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        await Task.FromResult(0);
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("StartLogin", "Home"));;
        }
예제 #7
0
        public Task SendAsync(IdentityMessage message)
        {
            var personalEmailService = new PersonalEmailService();
            var mailMessage          = new MailMessage(
                "*****@*****.**",
                message.Destination
                );

            mailMessage.Body       = message.Body;
            mailMessage.Subject    = message.Subject;
            mailMessage.IsBodyHtml = true;


            return(personalEmailService.SendAsync(mailMessage));
        }
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                var from = $"BlogSite<{ConfigurationManager.AppSettings["emailfrom"]}>";
                try
                {
                    var email = new MailMessage(from, model.Email)
                    {
                        Subject    = "Password",
                        Body       = "Reset password<a class='btn btn-primary' href=\"" + callbackUrl + "\"> Reset password </a>",
                        IsBodyHtml = true
                    };
                    var svc = new PersonalEmailService();
                    await svc.SendAsync(email);

                    return(RedirectToAction("ForgotPasswordConfirmation"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    await Task.FromResult(0);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.Id))
                {
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    var from = $"Bug-A-Boo<{ConfigurationManager.AppSettings["emailfrom"]}>";
                    try
                    {
                        var email = new MailMessage(from, model.Email)
                        {
                            Subject    = "Confirmation",
                            Body       = "Confirm your account<a class='btn btn-primary' href=\"" + callbackUrl + "\"> Confirm </a>",
                            IsBodyHtml = true
                        };
                        var svc = new PersonalEmailService();
                        await svc.SendAsync(email);

                        ViewBag.Message = "You Must Confirm Your Email To Login";
                        //return RedirectToAction("StartLogin", "Account");
                        return(View("Info"));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        await Task.FromResult(0);
                    }
                    ViewBag.errorMessage = "Account Is Not Confirmed. Please Confirm Account to Login.";

                    return(View("error"));
                }
            }
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(RedirectToAction("StartLogin", "Home"));
            }
        }