Exemplo n.º 1
0
        public void TestMissingUserName()
        {
            //todo pass in a stub/mock ldap service so we can test
            ActiveDirectoryAuthentication authentication = new ActiveDirectoryAuthentication("janedoe", null);
            LoginRequest credentials = new LoginRequest();
            bool         isValid     = authentication.Authenticate(credentials);

            Assert.IsFalse(isValid);
        }
Exemplo n.º 2
0
        public void TestValidUserName()
        {
            //todo pass in a stub/mock ldap service so we can test
            ActiveDirectoryAuthentication authentication = new ActiveDirectoryAuthentication(userName, null);

            authentication.DomainName = domainName;
            LoginRequest credentials = new LoginRequest(userName);
            bool         isValid     = authentication.Authenticate(credentials);

            Assert.IsTrue(isValid);
        }
Exemplo n.º 3
0
        public override Task <SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
        {
            if (ActiveDirectoryAuthentication.IsADAuthenticationEnabled())
            {
                if (ActiveDirectoryAuthentication.Authenticate(userName, password))
                {
                    return(base.PasswordSignInAsync(userName, "bazooka", isPersistent, shouldLockout));
                }
            }

            return(base.PasswordSignInAsync(userName, password, isPersistent, shouldLockout));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email
                };

                if (db.Users.Count() == 0)
                {
                    user.Administrator = true;
                }

                IdentityResult result;

                if (ActiveDirectoryAuthentication.IsADAuthenticationEnabled())
                {
                    if (!ActiveDirectoryAuthentication.Authenticate(model.UserName, model.Password))
                    {
                        ModelState.AddModelError("", "username or password not valid");
                        return(View(model));
                    }
                    else
                    {
                        result = await UserManager.CreateAsync(user, "bazooka");
                    }
                }
                else
                {
                    result = await UserManager.CreateAsync(user, model.Password);
                }


                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : 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 = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }