Ejemplo n.º 1
0
        public ActionResult AthleteSignup(string token)
        {
            AthleteSignupKey key = _db.AthleteSignupKeys.Include("Athlete").Single(t => t.Token.Equals(token));

            ViewBag.Email = key.Athlete.EmailAddress;
            ViewBag.Token = token;
            return(View());
        }
Ejemplo n.º 2
0
        public async Task BeginAthleteSetup(Athlete athlete)
        {
            Guid   token     = Guid.NewGuid();
            string emailBody = Utilities.Constants.GetEmailBody(athlete.FirstName, "CrossFit Example", token);
            await _emailSender.SendEmailAsync(athlete.EmailAddress, "Welcome to CrossFit Example!", emailBody);

            var keys = new AthleteSignupKey
            {
                Token   = token.ToString(),
                Athlete = athlete
            };

            _db.AthleteSignupKeys.Add(keys);
            await _db.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                AthleteSignupKey key = _db.AthleteSignupKeys.Include("Athlete").Single(x => x.Token.Equals(model.SignupToken));
                var user             = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, AthleteInfoId = key.Athlete.Id
                };

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

                if (result.Succeeded)
                {
                    Athlete athlete = _db.Athletes.Include("Subscription").Single(a => a.Id.Equals(key.Athlete.Id));
                    athlete.ApplicationUserId = user.Id;
                    athlete.VerifiedUser      = true;
                    try
                    {
                        await _db.SaveChangesAsync();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}",
                                                       validationError.PropertyName,
                                                       validationError.ErrorMessage);
                            }
                        }
                    }

                    if (model.AccountType == "Admin")
                    {
                        await UserManager.AddToRoleAsync(user.Id, "Admin");
                    }
                    else
                    {
                        await UserManager.AddToRoleAsync(user.Id, "Athlete");
                    }

                    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
                    // 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
            if (model.AccountType != null)
            {
                return(View(model));
            }
            else
            {
                return(RedirectToAction("AthleteSignup", new { token = model.SignupToken }));
            }
        }