Esempio n. 1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {

            // check if team is full:
            var team = Context.Teams.FirstOrDefault(t => t.TeamID.Equals(model.TeamID));
            if (team == null)
            {
                ModelState.AddModelError("Invalid Team", "Invalid Team");
            }
        
            if (!ModelState.IsValid) return View(model);

            var user = new ApplicationUser { UserName = model.Email, Email = model.Email, DisplayName = model.DisplayName, TeamID = model.TeamID };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                await SignInManager.SignInAsync(user, false, false);
                return RedirectToAction("Index", "Home");

                //var emailSendResult = await SendEmailConfirmation(user);
                //return RedirectToAction("confirmation", "account");
            }
            AddErrors(result);

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 2
0
        private async Task<dynamic> SendEmailConfirmation(ApplicationUser user)
        {
            //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

            // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
            // Send an email with this link
            var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { token = user.Id, code = code }, protocol: Request.Url.Scheme);
            const string apiKey = "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";
            dynamic sg = new SendGridAPIClient(apiKey);

            var from = new Email("*****@*****.**");
            var subject = "Confirm your YOURSITE account";
            var to = new Email(user.Email);
            var content = new Content("text/html", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
            var mail = new Mail(from, subject, to, content);

            dynamic response = await sg.client.mail.send.post(requestBody: mail.Get());
            //await sg.client.mail.send.post(requestBody: mail.Get());
            return response;
        }