public ActionResult EmailGroceryList()
        {
            HttpClient client       = new HttpClient();
            var        response     = client.GetAsync(Request.Url.GetLeftPart(UriPartial.Authority) + Url.Action("GroceryListPartial", new { id = User.Identity.GetUserId() })).Result;
            var        responseBody = response.Content.ReadAsStringAsync().Result;
            var        message      = @"<!DOCTYPE html>
<html><head><link rel=""stylesheet"" type=""text/css"" href=""https://localhost:44370/Content/Site.css""></head><body>" + responseBody + "</body></html>";

            EmailUtility.SendConfirmation(User.Identity.GetUserName(), message, $"eat smrt: Shopping List For {DateTime.Now.ToString("dddd, dd MMMM yyyy")}", true);
            return(new HttpStatusCodeResult(HttpStatusCode.NoContent));
        }
Example #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var userProfile = new UserProfile
                    {
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        EmailAddress = model.EmailAddress,
                        UserId       = user.Id
                    };
                    using (var db = new EatInDBEntities())
                    {
                        db.UserProfiles.Add(userProfile);
                        db.SaveChanges();
                    }
                    EmailUtility.SendConfirmation(model.EmailAddress, "Welcome to eat smrt! You are now a registered user.");
                    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>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }