예제 #1
0
        public static IdentityUser UserWithTestRole()
        {
            var user =  new IdentityUser();
            user.AddRole("test");

            return user;
        }
예제 #2
0
        public static IdentityUser UserWithTestRole()
        {
            var user = new IdentityUser();

            user.AddRole("test");

            return(user);
        }
예제 #3
0
        public static IdentityUser UserWithClaimAndRole(Claim claim, string role = "test")
        {
            var user = new IdentityUser();
            user.AddRole(role);
            user.AddClaim(claim);

            return user;
        }
예제 #4
0
        public static IdentityUser UserWithClaimAndRole(Claim claim, string role = "test")
        {
            var user = new IdentityUser();

            user.AddRole(role);
            user.AddClaim(claim);

            return(user);
        }
예제 #5
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = model.Email, Email = model.Email
                };

                if (user.Email == "*****@*****.**")
                {
                    user.AddRole("admin");
                    user.AddRole("bond");
                }

                if (user.Email == "*****@*****.**")
                {
                    user.AddRole("admin");
                }

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #6
0
    private async Task AddUsers()
    {
        var adminUser = new IdentityUser(_guidGenerator.Create(), "administrator", "*****@*****.**");

        adminUser.AddRole(_adminRole.Id);
        adminUser.AddClaim(_guidGenerator, new Claim("TestClaimType", "42"));
        await _userRepository.InsertAsync(adminUser);

        var john = new IdentityUser(_testData.UserJohnId, "john.nash", "*****@*****.**");

        john.AddRole(_moderatorRole.Id);
        john.AddRole(_supporterRole.Id);
        john.AddOrganizationUnit(_ou111.Id);
        john.AddOrganizationUnit(_ou112.Id);
        john.AddLogin(new UserLoginInfo("github", "john", "John Nash"));
        john.AddLogin(new UserLoginInfo("twitter", "johnx", "John Nash"));
        john.AddClaim(_guidGenerator, new Claim("TestClaimType", "42"));
        john.SetToken("test-provider", "test-name", "test-value");
        await _userRepository.InsertAsync(john);

        var david = new IdentityUser(_testData.UserDavidId, "david", "*****@*****.**");

        david.AddOrganizationUnit(_ou112.Id);
        await _userRepository.InsertAsync(david);

        var neo = new IdentityUser(_testData.UserNeoId, "neo", "*****@*****.**");

        neo.AddRole(_supporterRole.Id);
        neo.AddClaim(_guidGenerator, new Claim("TestClaimType", "43"));
        neo.AddOrganizationUnit(_ou111.Id);
        await _userRepository.InsertAsync(neo);

        var bob = new IdentityUser(_testData.UserBobId, "bob", "*****@*****.**");

        bob.SetIsActive(false);
        await _userManager.CreateAsync(bob, "1q2w3E*");
    }