public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    string body        = MailTemplateBody.GetBody(user.FullName, String.Format("Thank you for your registration by <b>{0}</b>.<br /> Please confirm your account by clicking this <a style=\"color: #18bc9c; text-decoration: none\" href=\"{1}\">link</a>.", Settings.Default.ApplicationName, callbackUrl));

                    await UserManager.SendEmailAsync(user.Id, "Confirm your account", body);

                    //ViewBag.Link = callbackUrl;
                    return(View("DisplayEmail"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser()
                {
                    UserName  = model.Email,
                    Email     = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        var    callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        string body        = MailTemplateBody.GetBody(user.FullName, String.Format("Thank you for your registration by <b>{0}</b>.<br /> Please confirm your account by clicking this <a href=\"{1}\">link</a>.", Settings.Default.ApplicationName, callbackUrl));
                        await UserManager.SendEmailAsync(user.Id, "Confirm your account", body);

                        //ViewBag.Link = callbackUrl;
                        return(View("DisplayEmail"));

                        //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        //return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Пример #3
0
        public async Task <ActionResult> Create(TournamentViewModel _tournamentViewModel)
        {
            if (ModelState.IsValid)
            {
                Tournament      tournament  = tournamentService.Create(_tournamentViewModel.Tournament);
                var             userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                ApplicationUser user        = await userManager.FindByNameAsync(tournament.Organizer);

                string subject = string.Format("Tournament \"{0}\" was successfully created.", tournament.Name);
                string body    = MailTemplateBody.GetBody(user.FullName, String.Format("Congradulation! Your tournament \"{0}\" was successfully created.", tournament.Name));

                await userManager.SendEmailAsync(user.Id, subject, body);

                return(RedirectToAction("Details", "Tournaments", new { id = tournament.Id }));
            }
            _tournamentViewModel.CountryList    = GetCountryList();
            _tournamentViewModel.SportGroupList = GetSportGroupList();

            return(View(_tournamentViewModel));
        }
Пример #4
0
        public async Task <ActionResult> Confirm(int id, string active, int?page = 1)
        {
            if (Request.IsAjaxRequest())
            {
                var team = teamService.GetById(id);
                team.ParticipationConfirmed = true;
                teamService.Update(team);

                var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

                ApplicationUser user = await userManager.FindByNameAsync(team.Coach);

                string subject = string.Format("Your participation in the tournament \"{0}\"  is confirmed.", team.Tournament.Name);
                string body    = MailTemplateBody.GetBody(user.FullName, string.Format("Your participation in the tournament \"{0}\"  is confirmed.", team.Tournament.Name));

                await userManager.SendEmailAsync(user.Id, subject, body);

                return(RedirectToAction("Details", "Tournaments", new { id = team.TournamentId, active = active, page = page }));
            }
            return(null);
        }
Пример #5
0
        public async Task <ActionResult> Create([Bind(Include = "Team")] TeamViewModel _teamViewModel)
        {
            Tournament tournament = tournamentService.GetById(_teamViewModel.Team.TournamentId);

            if (ModelState.IsValid)
            {
                Team team        = teamService.Create(_teamViewModel.Team);
                var  userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();

                ApplicationUser user = await userManager.FindByNameAsync(tournament.Organizer);

                string subject = string.Format("Team \"{0}\" wants to participate in your tournament \"{1}\".", team.Name, team.Tournament.Name);
                string body    = MailTemplateBody.GetBody(user.FullName, String.Format("Team \"{0}\" with the coach {2} want to participate in your tournament \"{1}\". <br/> <br/>Please confirm participation.", team.Name, team.Tournament.Name, team.Coach.GetFullName()));

                await userManager.SendEmailAsync(user.Id, subject, body);

                return(RedirectToAction("Details", "Teams", new { id = team.Id }));
            }
            _teamViewModel.CountryList = GetCountryList();
            _teamViewModel.RankingList = GetRankingList(tournament);
            return(View(_teamViewModel));
        }