상속: HaloOnline.Server.Model.User.User, IHaloUser
        public async Task<IHttpActionResult> CreateAccount(CreateAccountRequest request)
        {
            var user = new HaloUser
            {
                UserName = request.Username
            };
            var creationResult = await _userManager.CreateAsync(user, request.Password);
            if (creationResult.Succeeded == false)
            {
                return BadRequest(string.Join(", ", creationResult.Errors));
            }
            

            var userBaseData = new UserBaseData
            {
                User = new UserId
                {
                    Id = user.UserId
                },
                Nickname = request.Nickname,
                BattleTag = "",
                Level = 0,
                Clan = new ClanId
                {
                    Id = 0
                },
                ClanTag = ""
            };
            await _userBaseDataRepository.SetUserBaseDataAsync(userBaseData);

            var token = AuthenticateUser(user);
            return Ok(token);
        }
예제 #2
0
 public Task DeleteAsync(HaloUser user)
 {
     return Task.Run(() =>
     {
         HaloUser haloUser;
         _users.TryRemove(user.Id, out haloUser);
     });
 }
예제 #3
0
 public Task CreateAsync(HaloUser user)
 {
     return Task.Run(() =>
     {
         user.UserId = _nextId++;
         ;
         _users.TryAdd(user.Id, user);
     });
 }
예제 #4
0
 public Task UpdateAsync(HaloUser user)
 {
     return Task.Run(() =>
     {
         HaloUser currentUser;
         while (_users.TryGetValue(user.Id, out currentUser))
         {
             if (_users.TryUpdate(user.Id, user, currentUser))
             {
                 return true;
             }
         }
         return false;
     });
 }
예제 #5
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            IHaloUserManager haloUserManager =
                (IHaloUserManager)context.OwinContext.GetAutofacLifetimeScope().Resolve(typeof(IHaloUserManager));


            // BUG: Find out how this is done via AutoFac
            HaloUser user = await haloUserManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_login", "The user name or password is incorrect.");
            }
            else
            {
                var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                identity.AddClaim(new Claim("id", user.Id));
                identity.AddClaim(new Claim("username", user.UserName));
                context.Validated(identity);
            }
        }
예제 #6
0
 public Task SetPasswordHashAsync(HaloUser user, string passwordHash)
 {
     return Task.Run(() => user.UserPasswordHash = passwordHash);
 }
예제 #7
0
 public Task DeleteAsync(HaloUser user)
 {
     return _userRepository.UpdateAsync(user);
 }
예제 #8
0
 public Task CreateAsync(HaloUser user)
 {
     return _userRepository.CreateAsync(user);
 }
예제 #9
0
        public static void Register(HttpConfiguration config)
        {
            using (var scope = config.DependencyResolver.BeginScope())
            {
                var userManager = (IHaloUserManager) scope.GetService(typeof (IHaloUserManager));
                var userBaseDataRepository =
                    (IUserBaseDataRepository) scope.GetService(typeof (IUserBaseDataRepository));

                HaloUser testUser1 = new HaloUser
                {
                    UserName = "******"
                };
                HaloUser testUser2 = new HaloUser
                {
                    UserName = "******"
                };
                HaloUser testUser3 = new HaloUser
                {
                    UserName = "******"
                };
                userManager.CreateAsync(testUser1, "123").Wait();
                userManager.CreateAsync(testUser2, "456").Wait();
                userManager.CreateAsync(testUser3, "no1dead").Wait();

                UserBaseData testUser1Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser1.UserId
                    },
                    Nickname = "no1dead",
                    Clan = new ClanId
                    {
                        Id = 1
                    },
                    ClanTag = "ClanTag",
                    Level = 2,
                    BattleTag = "BattleTag"
                };

                UserBaseData testUser2Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser2.UserId
                    },
                    Nickname = "Nickname",
                    Clan = new ClanId
                    {
                        Id = 1
                    },
                    ClanTag = "ClanTag",
                    Level = 10,
                    BattleTag = "BattleTag"
                };

                                UserBaseData testUser3Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser3.UserId
                    },
                    Nickname = "Nickname",
                    Clan = new ClanId
                    {
                        Id = 1
                    },
                    ClanTag = "ClanTag",
                    Level = 10,
                    BattleTag = "BattleTag"
                };

                userBaseDataRepository.CreateUserBaseDataAsync(testUser1Data);
                userBaseDataRepository.CreateUserBaseDataAsync(testUser2Data);
                userBaseDataRepository.CreateUserBaseDataAsync(testUser3Data);
            }
        }
 private string AuthenticateUser(HaloUser haloUser)
 {
     var authenticationManager = Request.GetOwinContext().Authentication;
     authenticationManager.SignOut();
     var identity = _userManager.CreateIdentityAsync(haloUser, HaloAuthEnvironment.UserContext).Result;
     var authenticationProperties = new AuthenticationProperties
     {
         IssuedUtc = DateTime.UtcNow,
         ExpiresUtc = DateTime.UtcNow.Add(TimeSpan.FromDays(1))
     };
     var ticket = new AuthenticationTicket(identity, authenticationProperties);
     authenticationManager.SignIn(authenticationProperties, identity);
     return _secureDataFormat.Protect(ticket); // TODO: Max size 451 bytes. Doesn't work again.
 }
 public Task <string> GetPasswordHashAsync(HaloUser user)
 {
     return(Task.FromResult(user.UserPasswordHash));
 }
 public Task SetPasswordHashAsync(HaloUser user, string passwordHash)
 {
     return(Task.Run(() => user.UserPasswordHash = passwordHash));
 }
 public Task DeleteAsync(HaloUser user)
 {
     return(_userRepository.UpdateAsync(user));
 }
 public Task CreateAsync(HaloUser user)
 {
     return(_userRepository.CreateAsync(user));
 }
예제 #15
0
        private static void SeedServer(IDependencyScope scope)
        {
            var userManager = (IHaloUserManager) scope.GetService(typeof (IHaloUserManager));
            var userBaseDataRepository = (IUserBaseDataRepository) scope.GetService(typeof (IUserBaseDataRepository));
            var userSubscriptionRepository = (IUserSubscriptionRepository)scope.GetService(typeof(IUserSubscriptionRepository));
            var clanRepository = (IClanRepository)scope.GetService(typeof(IClanRepository));
            var clanMembershipRepository = (IClanMembershipRepository) scope.GetService(typeof (IClanMembershipRepository));

            try
            {
                var clan = clanRepository.FindByNamePrefixAsync("Clan1").Result.FirstOrDefault();
                if (clan == null)
                {
                    clan = new Clan
                    {
                        Name = "Clan1",
                        Description = "First clan",
                        Tag = "TAG"
                    };
                    clanRepository.CreateAsync(clan).Wait();
                }

                HaloUser testUser1 = new HaloUser
                {
                    UserName = "******"
                };
                HaloUser testUser2 = new HaloUser
                {
                    UserName = "******"
                };

                userManager.CreateAsync(testUser1, "123").Wait();
                userManager.CreateAsync(testUser2, "test").Wait();

                UserBaseData testUser1Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser1.UserId
                    },
                    Nickname = "User1",
                    Clan = new ClanId
                    {
                        Id = 0
                    },
                    ClanTag = "",
                    Level = 2,
                    BattleTag = "BattleTag1"
                };

                UserBaseData testUser2Data = new UserBaseData
                {
                    User = new UserId
                    {
                        Id = testUser2.UserId
                    },
                    Nickname = "User2",
                    Clan = new ClanId
                    {
                        Id = 0
                    },
                    ClanTag = "",
                    Level = 10,
                    BattleTag = "BattleTag2"
                };

                userBaseDataRepository.SetUserBaseDataAsync(testUser1Data);
                userBaseDataRepository.SetUserBaseDataAsync(testUser2Data);

                var testUser1ClanMembership = new ClanMembership
                {
                    UserId = testUser1.UserId,
                    ClanId = clan.ClanId,
                    Role = 1
                };

                clanMembershipRepository.CreateAsync(testUser1ClanMembership).Wait();

                var testUser1Subscription = new UserSubscription
                {
                    UserId = testUser1.UserId,
                    FriendUserId = testUser2.UserId
                };
                userSubscriptionRepository.CreateAsync(testUser1Subscription).Wait();

            }
            catch (Exception)
            {
                Debug.WriteLine("Server initialization failed.");
            }
        }
예제 #16
0
 public Task<string> GetPasswordHashAsync(HaloUser user)
 {
     return Task.FromResult(user.UserPasswordHash);
 }
예제 #17
0
 public Task<bool> HasPasswordAsync(HaloUser user)
 {
     return Task.FromResult(user.UserPasswordHash != null);
 }
 public Task <bool> HasPasswordAsync(HaloUser user)
 {
     return(Task.FromResult(user.UserPasswordHash != null));
 }