コード例 #1
0
ファイル: UserManager.cs プロジェクト: bigkeikei/PiggyBank
 public async Task<User> CreateUser(User user)
 {
     if (user == null) throw new SimpleIdentityDataException("User object is missing");
     if (user.Name == null || user.Name.Length == 0) throw new SimpleIdentityDataException("User.Name is missing");
     if (user.Email == null || user.Email.Length == 0) throw new SimpleIdentityDataException("User.Email is missing");
     user.Authentication = new UserAuthentication { User = user, Secret = Membership.GeneratePassword(8, 0) };
     AuthorizationManager auth = new AuthorizationManager(_dbContext);
     _dbContext.Users.Add(user);
     await _dbContext.SaveChangesAsync();
     await auth.GrantAuthorizationToUser(Authorization.AuthResourceType.User, user.Id, Authorization.AuthScopes.Full, user);
     await _dbContext.SaveChangesAsync();
     return user;
 }
コード例 #2
0
        public async void ReturnUser_WhenSucessful()
        {
            var mockDbContext = new MockSimpleIdentityDbContext();
            UserManager userManager = new UserManager(mockDbContext);
            AuthorizationManager authManager = new AuthorizationManager(mockDbContext);

            User user = new User();
            user.Name = "foo";
            user.Email = "*****@*****.**";
            user.IsActive = true;
            user.Id = 1;

            var createdUser = await userManager.CreateUser(user);

            Assert.True(createdUser.Name == user.Name);
            Assert.True(createdUser.Email == user.Email);
            Assert.True(createdUser.Authentication.Secret.Length > 0);
            Assert.True(await authManager.IsUserAuthorized(1, Authorization.AuthResourceType.User, 1, Authorization.AuthScopes.Full));

        }
コード例 #3
0
 public SimpleIdentityRepository(ISimpleIdentityDbContext dbContext)
 {
     UserManager = new UserManager(dbContext);
     AuthorizationManager = new AuthorizationManager(dbContext);
     TokenManager = new TokenManager(dbContext);
 }