Beispiel #1
0
        public string AuthorizeUser(string login, string password, out LoginFailType failType)
        {
            if (login == null || password == null)
            {
                throw new ArgumentNullException("Login and Password cant be null! Recheck!!!");
            }
            if (login == "" || password == "")
            {
                failType = LoginFailType.Error;
                return(null);
            }

            _userCredentials.TryGetValue(login, out IAuthData data);
            if (data == null)
            {
                failType = LoginFailType.WrongLogin;
                return(null);
            }

            if (!data.Password.Equals(password))
            {
                failType = LoginFailType.WrongPassword;
                return(null);
            }
            failType = LoginFailType.None;
            string sid = GenerateSession(DateTime.Now.Ticks);

            _userSessions.Add(sid, data);
            return(sid);
        }
Beispiel #2
0
 public string GetErrorText(LoginFailType type)
 {
     _LoginErrors.TryGetValue(type, out string errorText);
     if (errorText == null)
     {
         _LoginErrors.TryGetValue(LoginFailType.Error, out errorText);
     }
     return(errorText);
 }
        [TestCase("thisIsReallyLongPasswordForTestingIfInteractorValidatesPasswordMaximumLengthAccordingToProvidedBusinessRequirementsAndReturnsCorrectErrorInResponse", LoginFailType.PasswordWrongFormat)] //longer than max length
        public void ValidateNotCorrectPasswordTest(string password, LoginFailType code)
        {
            string testLogin    = "******";
            string testPassword = password;
            var    service      = new Mock <IUserDataService>(MockBehavior.Strict);
            var    presenter    = new Mock <IAuthPresenter>(MockBehavior.Strict);

            presenter.Setup(t => t.LoginFail(code));

            IAuthInteractor interactor = new AuthInteractor(service.Object, presenter.Object);

            presenter.Raise(t => t.OnLogInAttempt += null, testLogin, testPassword);
            presenter.Verify(t => t.LoginFail(code), Times.Once);
        }
        public void AuthInteractorOnLoginEventHandlingWrongLoginTest()
        {
            string        testLogin    = "******";
            string        testPassword = "******";
            var           service      = new Mock <IUserDataService>(MockBehavior.Strict);
            var           presenter    = new Mock <IAuthPresenter>(MockBehavior.Strict);
            LoginFailType code         = LoginFailType.WrongLogin;

            service.Setup(t => t.AuthorizeUser(testLogin, testPassword, out code)).Returns((string)null);;
            presenter.Setup(t => t.LoginFail(LoginFailType.WrongLogin));

            IAuthInteractor interactor = new AuthInteractor(service.Object, presenter.Object);

            presenter.Raise(t => t.OnLogInAttempt += null, testLogin, testPassword);
            service.Verify(t => t.AuthorizeUser(testLogin, testPassword, out code), Times.Once);
            presenter.Verify(t => t.LoginFail(LoginFailType.WrongLogin), Times.Once);
        }
        public void AuthInteractorOnLoginEventHandlingUnknownErrorTest()
        {
            string        testLogin    = "******";
            string        testPassword = "******";
            var           service      = new Mock <IUserDataService>(MockBehavior.Strict);
            var           presenter    = new Mock <IAuthPresenter>(MockBehavior.Strict);
            LoginFailType code         = LoginFailType.Error;

            service.Setup(t => t.AuthorizeUser(testLogin, testPassword, out code)).Throws <Exception>();
            presenter.Setup(t => t.LoginFail(LoginFailType.Error));

            IAuthInteractor interactor = new AuthInteractor(service.Object, presenter.Object);

            presenter.Raise(t => t.OnLogInAttempt += null, testLogin, testPassword);
            service.Verify(t => t.AuthorizeUser(testLogin, testPassword, out code), Times.Once);
            presenter.Verify(t => t.LoginFail(LoginFailType.Error), Times.Once);
        }
        public void AuthInteractorOnLoginEventHandlingTest()
        {
            string testSessionId = "10293847561213";
            string testLogin     = "******";
            string testPassword  = "******";
            string testUserId    = "4825557";
            var    service       = new Mock <IUserDataService>(MockBehavior.Strict);
            var    presenter     = new Mock <IAuthPresenter>(MockBehavior.Strict);

            LoginFailType code = LoginFailType.None;

            service.Setup(t => t.AuthorizeUser(testLogin, testPassword, out code)).Returns(testSessionId);
            service.Setup(t => t.GetUserIdBySessionId(testSessionId)).Returns(testUserId);
            presenter.Setup(t => t.LoginSuccess(testSessionId, testUserId));
            IAuthInteractor interactor = new AuthInteractor(service.Object, presenter.Object);

            presenter.Raise(t => t.OnLogInAttempt += null, testLogin, testPassword);
            service.Verify(t => t.AuthorizeUser(testLogin, testPassword, out code), Times.Once);
            service.Verify(t => t.GetUserIdBySessionId(testSessionId), Times.Once);
            presenter.Verify(t => t.LoginSuccess(testSessionId, testUserId), Times.Once);
        }
Beispiel #7
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (IsSuccess != false)
            {
                hash ^= IsSuccess.GetHashCode();
            }
            if (LoginFailType != global::GamePacket.Proto.AccountFailType.AlDefault)
            {
                hash ^= LoginFailType.GetHashCode();
            }
            if (UniqueId.Length != 0)
            {
                hash ^= UniqueId.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Beispiel #8
0
 internal void OnLoginFailed(LoginFailType failType)
 {
     _api.Logger.Debug($"Login failed with type {failType}");
     LoginFailed?.Invoke(failType);
     Disconnnect();
 }
 /// <summary>
 /// LoginEventArgs
 /// </summary>
 /// <param name="principal"></param>
 /// <param name="type"></param>
 /// <param name="message"></param>
 public LoginEventArgs(System.Security.Principal.IPrincipal principal, LoginFailType type, string message)
 {
     m_principal = principal;
     m_loginFailType = type;
     m_message = message;
 }
Beispiel #10
0
 /// <summary>
 /// LoginEventArgs
 /// </summary>
 /// <param name="principal"></param>
 /// <param name="type"></param>
 /// <param name="message"></param>
 public LoginEventArgs(System.Security.Principal.IPrincipal principal, LoginFailType type, string message)
 {
     m_principal     = principal;
     m_loginFailType = type;
     m_message       = message;
 }
Beispiel #11
0
 public string GetErrorText(LoginFailType err)
 {
     return(_localeData.GetErrorText(err));
 }
Beispiel #12
0
 public void LoginFail(LoginFailType failReason)
 {
     _view.ShowErrorMessage(_localeWorker.GetErrorText(failReason));
     //добавить стилизацию вью
 }