Ejemplo n.º 1
0
        public async Task RemovePledgeAsync(EventRegistration registration, GGCharityUser Donor)
        {
            var pledge = await (from p in _context.Pledges 
                                where p.Receiver.UserId.Equals(registration.UserId) && p.Receiver.EventId.Equals(registration.EventId) && p.DonorId.Equals(Donor.Id) 
                                select p).SingleOrDefaultAsync();

            _context.Pledges.Remove(pledge);
        }
Ejemplo n.º 2
0
 public Pledge AddPledge(EventRegistration PlayerRegistration, GGCharityUser donor, Decimal Amount)
 {
     var pledge = new Pledge(PlayerRegistration, donor, Amount);
     _context.Pledges.Add(pledge);
     return pledge;
 }
Ejemplo n.º 3
0
 private async Task SignInAsync(GGCharityUser user, bool isPersistent)
 {
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
     AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
     GGCharitySession.Get().Initialize(user);
 }
Ejemplo n.º 4
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            Trace.TraceInformation("Handling register request for user {0}, timezone {1}, returnUrl = {2}", model.Username, model.TimeZoneId, model.ReturnUrl);
            if (ModelState.IsValid)
            {
                var user = new GGCharityUser() { UserName = model.Username, Email = model.Email, TimeZoneId = model.TimeZoneId };
                IdentityResult result = null;
                await Data.PerformAsync(async () =>
                {
                    result = await UserManager.CreateAsync(user, model.Password);
                });

                if (result.Succeeded)
                {
                    return await PostRegistrationSignIn(model.ReturnUrl, user);
                }
                else
                {
                    AddErrors(result);
                }
            }

            Trace.TraceEvent(TraceEventType.Error, 0, "Model state invalid for registration attempt for user {0}.  Error = {1}", model.Username, String.Join(", ", ModelState));

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 5
0
 private async Task AddClaimsForNewUser(ExternalLoginInfo info, GGCharityUser user)
 {
     foreach (var claim in info.ExternalIdentity.Claims)
     {
         if (!claim.Type.Equals(ClaimTypes.NameIdentifier))
         {
             await Data.PerformAsync(async () =>
             {
                 await UserManager.AddClaimAsync(user.Id, claim);
             });
         }
     }
 }
Ejemplo n.º 6
0
        private async Task<ActionResult> PostRegistrationSignIn(string ReturnUrl, GGCharityUser user)
        {
            await SignInAsync(user, isPersistent: 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 = UriExtensions.GetEmulationAwareUrl(Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme));

            // If auto-confirm is turned on, just send them straight to the confirmation URL
            if (Config.Get().AutoConfirmAccounts)
            {
                await Data.PerformAsync(async () =>
                {
                    await UserManager.ConfirmEmailAsync(user.Id, code);
                });
            }
            else
            {
                await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Hi " + user.UserName + "!<br /><br />Thanks for signing up for GGCharity.  Before you can join an event or make a pledge, you'll have to confirm your email address.  Please <a href=\"" + callbackUrl + "\">click here</a> to proceed!<br /><br />-The GGCharity Team");
            }

            if (ReturnUrl == null)
            {
                ReturnUrl = Url.Action("Index", "Home");
            }
            return RedirectToLocal(ReturnUrl);
        }
Ejemplo n.º 7
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string ReturnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("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 GGCharityUser() { UserName = model.UserName, Email = model.Email };
                user.TimeZoneId = model.TimeZoneId;

                IdentityResult result = null;

                await Data.PerformAsync(async () =>
                {
                    result = await UserManager.CreateAsync(user);
                });

                if (result.Succeeded)
                {
                    await Data.PerformAsync(async () =>
                    {
                        result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    });
                }

                if (result.Succeeded)
                {
                    await Data.PerformAsync(async () =>
                    {
                        await AddClaimsForNewUser(info, user);
                    });

                    await LoadNewUserDataAsync(user, info);
                }

                if (result.Succeeded)
                {
                    return await PostRegistrationSignIn(ReturnUrl, user);
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = ReturnUrl;
            return View(model);
        }
Ejemplo n.º 8
0
        private async Task RefreshGamesForLoginAsync(GGCharityUser user, IdentityUserLogin login)
        {
            if (login.LoginProvider == "BattleNet")
            {
                IdentityUserClaim battleNetAccessTokenClaim = user.Claims.Where(c => c.ClaimType == @"urn:battlenet:accesstoken").SingleOrDefault();
                if (battleNetAccessTokenClaim == null)
                {
                    Trace.TraceEvent(TraceEventType.Critical, 0, "User {0} has a BattleNet login but no access token claim", user.Id);
                    return;
                }

                string battleNetAccessToken = battleNetAccessTokenClaim.ClaimValue;

                await LoadBattleNetUserDataAsync(user, battleNetAccessToken);
            }
        }
Ejemplo n.º 9
0
        private async Task LoadBattleNetUserDataAsync(GGCharityUser user, string accessToken)
        {
            Trace.TraceInformation("Calling GetProfileAsync for battle.net user {0}", user.UserName);
            var profile = await BattleNetApi.StarCraft.Api.GetProfileAsync(BattleNetApi.Region.US, accessToken);

            if (profile.Characters.Count > 1)
            {
                Trace.TraceEvent(TraceEventType.Critical, 0, "User {0} has {1} StarCraft characters!", user.Email, profile.Characters.Count);
                throw new NotSupportedException();
            }

            if (profile.Characters.Count == 0)
            {
                Trace.TraceInformation("User {0} has no StarCraft characters", user.Email);
                return;
            }

            await Data.PerformAsync(async () =>
            {
                GameProfile oldStarcraftProfile = user.GameProfiles.Where(p => p.GameId == GameID.StarCraft).SingleOrDefault();
                if (oldStarcraftProfile == null)
                {
                    Trace.TraceInformation("User {0} does not have a StarCraft game profile, creating one", user.UserName);

                    var gameProfile = new GameProfile
                    {
                        GameId = GameID.StarCraft,
                        ProfileData = profile.JsonString,
                        ProfileDataVersion = profile.Version,
                        UserId = user.Id,
                        AdditionalData = profile.Region.ToString()
                    };

                    user.GameProfiles.Add(gameProfile);
                    Data.GameProfiles.Add(gameProfile);
                }
                else
                {
                    Trace.TraceInformation("User {0} already has a StarCraft game profile, refreshing it", user.UserName);
                    oldStarcraftProfile.ResetData(profile.JsonString, profile.Version, profile.Region.ToString());
                }

                await Data.SaveChangesAsync();
                Trace.TraceInformation("User {0}'s StarCraft game profile was saved successfully", user.UserName);
            });
        }
Ejemplo n.º 10
0
 private Task LoadNewUserDataAsync(GGCharityUser user, ExternalLoginInfo loginInfo)
 {
     if (loginInfo.Login.LoginProvider == BattleNetProviderId)
     {
         Trace.TraceInformation("Beginning to load BattleNet info for user {0}", user.UserName);
         var accessTokenClaim = loginInfo.ExternalIdentity.Claims.Where(c => c.Type == @"urn:battlenet:accesstoken").Single();
         return LoadBattleNetUserDataAsync(user, accessTokenClaim.Value);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Ejemplo n.º 11
0
 public static string PlayerProfilePublicLink(this UrlHelper Url, GGCharityUser user)
 {
     return Url.Action("Public", "User", new { Id = user.UserName });
 }