Beispiel #1
0
 public AccountController(
     IIdentityServerInteractionService interaction,
     IClientStore clientStore,
     IHttpContextAccessor httpContextAccessor,
     IEventService events,
     IAppConfiguration appConfiguration,
     IUserStore userStore,
     ILogger logger,
     IPrincipalSearchService principalSearchService,
     IFabricClaimsService claimsService,
     AccountService accountService,
     GroupFilterService groupFilterService,
     TestUserStore users = null)
 {
     // if the TestUserStore is not in DI, then we'll just use the global users collection
     _users                  = users ?? MakeTestUserStore(appConfiguration);
     _interaction            = interaction;
     _events                 = events;
     _appConfiguration       = appConfiguration;
     _logger                 = logger;
     _principalSearchService = principalSearchService;
     _accountService         = accountService;
     _claimsService          = claimsService;
     _groupFilterService     = groupFilterService;
     _userLoginManager       = new UserLoginManager(userStore, _logger);
 }
Beispiel #2
0
        public async void TestUserLogin_UpdatesLastLoginByClient()
        {
            var userLoginManager = new UserLoginManager(UserStore, new Mock <ILogger>().Object);

            var userId     = $"HealthCatalyst\\{GetRandomString()}";
            var provider   = FabricIdentityConstants.FabricExternalIdentityProviderTypes.Windows;
            var clientId   = "sampleApp";
            var userName   = "******";
            var firstName  = "foo";
            var lastName   = "baz";
            var middleName = "dot";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(JwtClaimTypes.GivenName, firstName),
                new Claim(JwtClaimTypes.FamilyName, lastName),
                new Claim(JwtClaimTypes.MiddleName, middleName),
                new Claim(JwtClaimTypes.Role, @"FABRIC\Health Catalyst Viewer")
            };

            var user = await userLoginManager.UserLogin(provider, userId, claims, clientId);

            var firstLoginDate = user.LastLoginDatesByClient.First().LoginDate;

            //Sleep to ensure some time passes between logins
            Thread.Sleep(10);

            user = await userLoginManager.UserLogin(provider, userId, claims, clientId);

            var secondLoginDate = user.LastLoginDatesByClient.First().LoginDate;

            Assert.True(secondLoginDate >= firstLoginDate, "second login date is not greater than first");
        }
        public async Task UserLoginManager_UserLogin_NewUserWithTwoNameClaims()
        {
            var userLoginManager = new UserLoginManager(
                new InMemoryUserStore(new InMemoryDocumentService()),
                new Mock <ILogger>().Object);

            var subjectId         = Guid.NewGuid().ToString();
            var clientId          = "test";
            var userPrincipalName = "*****@*****.**";
            var userDisplayName   = "Bob Gomez";

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userPrincipalName),
                new Claim(JwtClaimTypes.Name, userDisplayName),
                new Claim(FabricIdentityConstants.PublicClaimTypes.UserPrincipalName, userPrincipalName)
            };

            var newUser = await userLoginManager.UserLogin(FabricIdentityConstants.AuthenticationSchemes.Azure,
                                                           subjectId, claims, clientId);

            var nameClaims = newUser.Claims.Where(c => c.Type == JwtClaimTypes.Name).ToList();

            Assert.Equal(subjectId, newUser.SubjectId);
            Assert.Equal(userPrincipalName, newUser.Username);
            Assert.Equal(1, nameClaims.Count);
            Assert.Equal(userDisplayName, nameClaims.Single().Value);
        }
 private void Awake()
 {
     CreateInputUI();
     userLoginManager        = new UserLoginManager(ShowErrorMessage);
     userRegistrationManager = new UserRegistrationManager(ShowErrorMessage);
     autoLoginManager        = new AutoLoginManager(ShowErrorMessage);
 }
Beispiel #5
0
        public ActionResult DoLogin(LoginViewModel loginData)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Login", loginData));
            }
            //var user = Mapper.Map<User>(loginData);

            var userLogin = new UserLoginManager();
            var employee  = userLogin.Login(loginData);

            if (employee == null)
            {
                return(View("Login"));
            }

            Session["Authorised"] = true;
            Session["UserId"]     = employee.Id;
            if (employee.Role.Name == VariablesConfig.AdminRoleName)
            {
                Session["IsAdmin"] = true;
            }

            FormsAuthentication.SetAuthCookie(employee.Email, true);

            return(RedirectToAction("Index", "Work"));
        }
Beispiel #6
0
        public async void TestUserLogin_UpdateClaims_RemovesClaim()
        {
            var userLoginManager = new UserLoginManager(UserStore, new Mock <ILogger>().Object);
            var userId           = $"HealthCatalyst\\{GetRandomString()}";
            var provider         = FabricIdentityConstants.FabricExternalIdentityProviderTypes.Windows;
            var clientId         = "sampleApp";
            var claims           = GetBaseClaims();

            claims.Add(new Claim(JwtClaimTypes.Role, @"FABRIC\Health Catalyst Editor"));

            await userLoginManager.UserLogin(provider, userId, claims, clientId);

            var storedUser = UserStore.FindBySubjectIdAsync(userId).Result;

            Assert.Equal(claims.Count, storedUser.Claims.Count);

            var claim = claims.FirstOrDefault(c => c.Type == JwtClaimTypes.Role);

            claims.Remove(claim);
            await userLoginManager.UserLogin(provider, userId, claims, clientId);

            storedUser = UserStore.FindBySubjectIdAsync(userId).Result;
            Assert.Equal(claims.Count, storedUser.Claims.Count);
            Assert.Equal(claims.First(c => c.Type == ClaimTypes.Name).Value, storedUser.Claims.First(c => c.Type == JwtClaimTypes.Name).Value);
            Assert.Equal(claims.First(c => c.Type == JwtClaimTypes.GivenName).Value, storedUser.Claims.First(c => c.Type == JwtClaimTypes.GivenName).Value);
            Assert.Equal(claims.First(c => c.Type == JwtClaimTypes.FamilyName).Value, storedUser.Claims.First(c => c.Type == JwtClaimTypes.FamilyName).Value);
            Assert.Equal(claims.First(c => c.Type == JwtClaimTypes.MiddleName).Value, storedUser.Claims.First(c => c.Type == JwtClaimTypes.MiddleName).Value);
            Assert.Equal(claims.Count(c => c.Type == JwtClaimTypes.Role), storedUser.Claims.Count(c => c.Type == JwtClaimTypes.Role));
            Assert.Equal(1, storedUser.Claims.Count(c => c.Type == JwtClaimTypes.Role));
        }
Beispiel #7
0
        protected void btn1_click(object sender, EventArgs e)
        {
            UserLoginManager  userLoginManager = new UserLoginManager();
            UserLoginEntities user             = userLoginManager.loginuser(txtuname.Text, txtpassword.Text);

            if (user != null)
            {
                hfUserID.Value    = user.id.ToString();
                namehide.Value    = user.Name.ToString();
                familyhide.Value  = user.Family.ToString();
                phonehide.Value   = user.Phone.ToString();
                emailhise.Value   = user.Email.ToString();
                addresshide.Value = user.Address.ToString();
                genderhide.Value  = user.Gender.ToString();
                Response.Cookies["Cookies3"]["id"]       = hfUserID.Value;
                Response.Cookies["Cookies3"]["name"]     = namehide.Value;
                Response.Cookies["Cookies3"]["family"]   = familyhide.Value;
                Response.Cookies["Cookies3"]["phone"]    = phonehide.Value;
                Response.Cookies["Cookies3"]["email"]    = emailhise.Value;
                Response.Cookies["Cookies3"]["address"]  = addresshide.Value;
                Response.Cookies["Cookies3"]["gender"]   = genderhide.Value;
                Response.Cookies["Cookies3"]["username"] = txtuname.Text;
                Response.Cookies["Cookies3"]["password"] = txtpassword.Text;

                Response.Cookies["StudentCookies"].Expires = DateTime.Now.AddDays(1);

                Response.Redirect("Profile.aspx");
            }
            UserLoginManager  userLoginManager1 = new UserLoginManager();
            UserLoginEntities user1             = userLoginManager1.loginuser1(txtuname.Text, txtpassword.Text);

            if (user1 != null)
            {
                Response.Cookies["Cookies4"]["id"]       = user1.id.ToString();
                Response.Cookies["Cookies4"]["Email"]    = user1.Email.ToString();
                Response.Cookies["Cookies4"]["password"] = user1.Password.ToString();

                Response.Cookies["DCookies"].Expires = DateTime.Now.AddDays(1);

                Response.Redirect("AccessPart.aspx");
            }
            UserLoginManager  userLoginManager2 = new UserLoginManager();
            UserLoginEntities user2             = userLoginManager2.loginuser2(txtuname.Text, txtpassword.Text);

            if (user2 != null)
            {
                Response.Cookies["Cookies5"]["id"]       = user2.id.ToString();
                Response.Cookies["Cookies5"]["Email"]    = user2.Email.ToString();
                Response.Cookies["Cookies5"]["password"] = user2.Password.ToString();

                Response.Cookies["ACookies"].Expires = DateTime.Now.AddDays(1);

                Response.Redirect("LabManage.aspx");
            }
            else
            {
                Response.Write("<script>alert('اطلاعات شما صحیح نیست');</script>");
            }
        }
 public CustomProfileService(UserManager <AppUser> userManager,
                             IUserClaimsPrincipalFactory <AppUser> claimsFactory,
                             UserLoginManager loginManager,
                             ProfilePhotoUrlConstructor profilePhotoUrl) : base(userManager, claimsFactory)
 {
     _loginManager    = loginManager;
     _userManager     = userManager;
     _profilePhotoUrl = profilePhotoUrl;
 }
Beispiel #9
0
        public ActionResult Edit()
        {
            if (!UserLoginManager.IsLogged(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewData["roles"] = _employeeService.GetRoles();
            return(View());
        }
Beispiel #10
0
        public ActionResult Tabel()
        {
            if (!UserLoginManager.IsLogged(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }


            return(View());
        }
Beispiel #11
0
        [Fact]// tells xUnit its a test
        public void OnlySymbolsPassword()
        {
            //Arrange - preper whats needed to do the test
            UserLoginManager manager     = new UserLoginManager();
            string           onlySymbols = "!@#$";

            bool result = manager.ValidatePassword(onlySymbols);

            //Assert - did it do what its supposed to do
            Assert.False(result);
        }
Beispiel #12
0
        // GET: Timesheet
        public ActionResult Edit()
        {
            if (!UserLoginManager.IsLogged(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            ViewData["employees"] = _timesheetService.GetEmployeeNames();
            ViewData["projects"]  = _timesheetService.GetProjectCodes();
            return(View());
        }
Beispiel #13
0
        public IHttpActionResult Login(LoginRequest loginRequest)
        {
            UserLoginManager     userLoginManager     = new UserLoginManager();
            AuthenticatedUserDto authenticatedUserDto = userLoginManager.TryLogin(loginRequest);

            if (authenticatedUserDto == null)
            {
                return(Unauthorized());
            }

            return(Ok(authenticatedUserDto));
        }
Beispiel #14
0
        [Fact]// tells xUnit its a test
        public void EmptyUserList()
        {
            //Arrange - preper whats needed to do the test
            UserLoginManager manager = new UserLoginManager(new Dictionary <string, string>());
            int expected             = 0;

            //Act - run method that we are testing
            int actual = manager.UserCount();

            //Assert - did it do what its supposed to do
            Assert.Equal(expected, actual);
        }
Beispiel #15
0
        [Fact]// tells xUnit its a test
        public void ValidPassword()
        {
            //Arrange - preper whats needed to do the test
            UserLoginManager manager      = new UserLoginManager();
            string           goodPassword = "******";

            //Act - run method that we are testing
            bool result = manager.ValidatePassword(goodPassword);

            //Assert - did it do what its supposed to do
            Assert.True(result);
        }
Beispiel #16
0
        [Fact]// tells xUnit its a test
        public void DefualtAmountOfUsers()
        {
            //Arrange - preper whats needed to do the test
            UserLoginManager manager = new UserLoginManager();
            int expected             = 2;

            //Act - run method that we are testing
            int actual = manager.UserCount();

            //Assert - did it do what its supposed to do
            Assert.Equal(expected, actual);
        }
        public async Task UserLoginManager_UserLogin_ExistingUser_HasPropertiesAndRoleClaimsUpdated()
        {
            var documentDbUserStore = new InMemoryUserStore(new InMemoryDocumentService());

            var userLoginManager = new UserLoginManager(documentDbUserStore, new Mock <ILogger>().Object);

            var userId     = "HealthCatalyst\\foo.bar";
            var provider   = FabricIdentityConstants.FabricExternalIdentityProviderTypes.Windows;
            var clientId   = "sampleApp";
            var userName   = "******";
            var firstName  = "foo";
            var lastName   = "bar";
            var middleName = "dot";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(JwtClaimTypes.GivenName, firstName),
                new Claim(JwtClaimTypes.FamilyName, lastName),
                new Claim(JwtClaimTypes.MiddleName, middleName),
                new Claim(JwtClaimTypes.Role, @"FABRIC\Health Catalyst Viewer")
            };

            var existingUser = await userLoginManager.UserLogin(provider, userId, claims, clientId);

            var existingRoleClaim = existingUser.Claims.Single(c => c.Type == JwtClaimTypes.Role);
            var firstLoginDate    = existingUser.LastLoginDatesByClient.First().LoginDate;

            userId     = "HealthCatalyst\\foo.bar";
            provider   = FabricIdentityConstants.FabricExternalIdentityProviderTypes.Windows;
            clientId   = "sampleApp";
            userName   = "******";
            firstName  = "abc";
            lastName   = "def";
            middleName = "zzz";
            claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(JwtClaimTypes.GivenName, firstName),
                new Claim(JwtClaimTypes.FamilyName, lastName),
                new Claim(JwtClaimTypes.MiddleName, middleName),
                new Claim(JwtClaimTypes.Role, @"FABRIC\Health Catalyst Editor")
            };

            var updatedUser = await userLoginManager.UserLogin(provider, userId, claims, clientId);

            Assert.Equal(userName, updatedUser.Username);
            Assert.Equal(firstName, updatedUser.FirstName);
            Assert.Equal(lastName, updatedUser.LastName);
            Assert.Equal(middleName, updatedUser.MiddleName);
            Assert.Equal(5, updatedUser.Claims.Count);
            Assert.NotEqual(existingRoleClaim.Value, updatedUser.Claims.First().Value);
            Assert.True(firstLoginDate.Ticks < updatedUser.LastLoginDatesByClient.First().LoginDate.Ticks);
        }
        private void loginbutton_Click(object sender, EventArgs e)
        {
            UserLoginManager userLoginManager = new UserLoginManager();
            string           result           = userLoginManager.CheckLogin(useIDtextBox.Text, passwordtextBox.Text);

            MessageBox.Show(result);
            if (result == "Login Successful")
            {
                StockManagementUI stockManagementUi = new StockManagementUI();
                stockManagementUi.Show();
            }
        }
Beispiel #19
0
        [Fact]// tells xUnit its a test
        public void OnlyDigietsPassword()
        {
            //Arrange - preper whats needed to do the test
            UserLoginManager manager    = new UserLoginManager();
            string           onlyDigits = "123";

            //Act - run method that we are testing
            bool result = manager.ValidatePassword(onlyDigits);

            //Assert - did it do what its supposed to do
            Assert.False(result);
        }
Beispiel #20
0
 public ResourceOwnerValidator(UserManager <AppUser> userManager,
                               SignInManager <AppUser> signInManager,
                               IEventService events,
                               ILogger <ResourceOwnerValidator> logger,
                               UserLoginManager loginManager)
 {
     _userManager          = userManager;
     _signInManager        = signInManager;
     _events               = events;
     _logger               = logger;
     _informationValidator = new LoginInformationValidator();
     _loginManager         = loginManager;
 }
        public async Task UserLoginManager_UserLogin_NoNameOrUpnClaim()
        {
            var userLoginManager = new UserLoginManager(
                new InMemoryUserStore(new InMemoryDocumentService()),
                new Mock <ILogger>().Object);

            var subjectId = Guid.NewGuid().ToString();
            var clientId  = "test";

            var claims  = new List <Claim>();
            var newUser = await userLoginManager.UserLogin(FabricIdentityConstants.AuthenticationSchemes.Azure,
                                                           subjectId, claims, clientId);

            Assert.Equal(subjectId, newUser.SubjectId);
            Assert.Equal(subjectId, newUser.Username);
        }
Beispiel #22
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            userNameTextBox.Text = "Zahid";
            passwordTextBox.Text = "zahid";
            UserLoginManager aUserLoginManager = new UserLoginManager();

            if (aUserLoginManager.IsExist(userNameTextBox.Text, passwordTextBox.Text))
            {
                MainForm2 mainFormUi = new MainForm2();
                mainFormUi.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("User Name OR Password Wrong");
            }
        }
        public async Task Should_Call_ExistAsyncMethod()
        {
            //Arrange

            const string email    = "*****@*****.**";
            const string password = "******";

            _manager = new UserLoginManager(_mapperMock.Object, _repositoryMock.Object);

            //Act

            var result = await _manager.ExistsAsync(email, password);

            //Assert

            _repositoryMock.Verify(x => x.ExistsAsync(email, password), Times.Once);
        }
Beispiel #24
0
        // GET: Work
        public ActionResult Index()
        {
            if (!UserLoginManager.IsLogged(Session))
            {
                return(RedirectToAction("Index", "Home"));
            }

            var currentUser = UserLoginManager.GetCurrentUser(Session);

            var userVm = new WorkIndexViewModel
            {
                Mail     = currentUser.Email,
                Name     = currentUser.Name,
                RoleName = currentUser.Role.Name
            };


            return(View(userVm));
        }
        public async Task Should_GetUserAsync_ResturnsALoginUserModelById()
        {
            //Arrange

            const int    userId   = 1;
            const string password = "******";
            const string email    = "*****@*****.**";

            var userEntity = new UserEf
            {
                Id       = userId,
                Email    = email,
                Password = password
            };

            var userModel = new UserLogin
            {
                Id    = userId,
                Email = email
            };

            _repositoryMock.Setup(x => x.GetUserAsync(userId))
            .ReturnsAsync(userEntity);

            _mapperMock.Setup(x => x.Map <UserLogin>(userEntity))
            .Returns(userModel);

            _manager = new UserLoginManager(_mapperMock.Object, _repositoryMock.Object);

            //Act

            var model = await _manager.GetUserAsync(userId);

            //Assert

            _repositoryMock.Verify(x => x.GetUserAsync(userId), Times.Once);
            _mapperMock.Verify(x => x.Map <UserLogin>(userEntity), Times.Once);

            Assert.NotNull(model.Email);
            Assert.Equal(userId, model.Id);
            Assert.Equal(email, model.Email);
        }
        public async Task UserLoginManager_UserLogin_NewUser_HasCorrectPropertiesSet()
        {
            //create a new user, ensure claims,  login date, provider, and name properties are set correctly
            var userLoginManager = new UserLoginManager(
                new InMemoryUserStore(new InMemoryDocumentService()),
                new Mock <ILogger>().Object);

            var userId     = "HealthCatalyst\\foo.baz";
            var provider   = FabricIdentityConstants.FabricExternalIdentityProviderTypes.Windows;
            var clientId   = "sampleApp";
            var userName   = "******";
            var firstName  = "foo";
            var lastName   = "baz";
            var middleName = "dot";
            var claims     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(JwtClaimTypes.GivenName, firstName),
                new Claim(JwtClaimTypes.FamilyName, lastName),
                new Claim(JwtClaimTypes.MiddleName, middleName),
                new Claim(JwtClaimTypes.Role, @"FABRIC\Health Catalyst Viewer")
            };

            var newUser = await userLoginManager.UserLogin(provider, userId, claims, clientId);

            Assert.Equal(userId, newUser.SubjectId);
            Assert.Equal(provider, newUser.ProviderName);
            Assert.Equal(userName, newUser.Username);
            Assert.Equal(firstName, newUser.FirstName);
            Assert.Equal(lastName, newUser.LastName);
            Assert.Equal(middleName, newUser.MiddleName);
            Assert.Equal(5, newUser.Claims.Count);
            Assert.Equal(1, newUser.Claims.Count(c => c.Type == JwtClaimTypes.Name));
            Assert.Equal(1, newUser.Claims.Count(c => c.Type == JwtClaimTypes.Role));
            Assert.Equal(1, newUser.LastLoginDatesByClient.Count);
            Assert.Equal(clientId, newUser.LastLoginDatesByClient.First().ClientId);
        }
Beispiel #27
0
 public ActionResult Index()
 {
     return(UserLoginManager.IsLogged(Session)
         ? RedirectToAction("Index", "Work")
         : RedirectToAction("Login", "Home"));
 }