コード例 #1
0
        public void GetByToken_CorrectParameters()
        {
            string userLogin = "******";
            string userToken = _sessionTokenMock.GenerateSessionToken(userLogin);

            var result = _userSystemService.GetByToken(userToken);

            Assert.IsTrue(result.actionResult.ResultConnection == ServiceResult.ResultConnectionEnum.Correct);
        }
コード例 #2
0
        public void Authorization_AuthorizationAdmin()
        {
            var request = new AuthorizationRequest()
            {
                Login    = "******",
                Password = "******",
            };

            var result = _authorizationService.AuthorizationUser(request);

            Assert.IsTrue(result.userRole.Role == UserRole.RoleEnum.Admin &&
                          result.sessionToken == _sessionTokenMock.GenerateSessionToken(request.Login));
        }
コード例 #3
0
        public (UserRole userRole, string sessionToken, DateTime authorizationFinish) AuthorizationUser(AuthorizationRequest authorizationData)
        {
            string hash       = _passwordHash.GeneratePasswordHash(authorizationData.Login, authorizationData.Password);
            var    userSystem = _dbContext.UsersSystem.GetUserByLoginPasswordhash(authorizationData.Login, hash);

            var sessionToken = _sessionTokenGenerator.GenerateSessionToken(authorizationData.Login);

            UserAuthorizationToken userToken = new UserAuthorizationToken(DateTime.Now, DateTime.Now.Add(_timeKeyWork),
                                                                          sessionToken, new AuthorizationStatus(AuthorizationStatus.AuthorizationStatusEnum.Active),
                                                                          // ReSharper disable once PossibleInvalidOperationException
                                                                          userSystem.IdEntity.Value);

            var cancelResult = CancelOldSessionToken(userSystem.IdEntity.Value);

            if (!cancelResult)
            {
                return(null, null, DateTime.Now);
            }

            var tokenInserResult = _dbContext.UserAuthorizationsToken.Insert(userToken);

            if (!tokenInserResult.HasValue)
            {
                return(null, null, DateTime.Now);
            }

            return(userSystem.UserAdmittance.UserRole, sessionToken, DateTime.Now + _timeKeyWork);
        }