Exemplo n.º 1
0
        public async Task<User> Account(string username, string password)
        {
            var remoteUser = await this.remoteData.Login(username, password);
            if (remoteUser == null)
            {
                return null;
            }

            var localUser = await this.GetLocalAccount(username);
            if (localUser == null)
            {
                localUser = new User
                {
                    UserName = remoteUser.UserName,
                    AvatarUrl = remoteUser.AvatarUrl,
                    IsAdmin = remoteUser.IsAdmin
                };

                this.users.Add(localUser);
                this.users.SaveChanges();
            }
            else if (localUser.AvatarUrl != remoteUser.AvatarUrl || localUser.IsAdmin != remoteUser.IsAdmin)
            {
                localUser.IsAdmin = remoteUser.IsAdmin;
                localUser.AvatarUrl = remoteUser.AvatarUrl;
                this.users.SaveChanges();
            }

            return localUser;
        }
Exemplo n.º 2
0
        public static ClaimsIdentity Create(User user, string authenticationType)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var id = new ClaimsIdentity(authenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
            id.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(), ClaimValueTypes.String));
            id.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, user.UserName, ClaimValueTypes.String));

            return id;
        }
Exemplo n.º 3
0
 public void LoginShouldReturnCorrectResults(string username, string password, User expected)
 {
     var service = new RemoteDataService();
     var result = service.Login(username, password).Result;
     Assert.AreEqual(expected, result);
 }