Exemplo n.º 1
0
        public void Authorization(string login, string password)
        {
            if (login == null)
            {
                throw new ArgumentNullException("Provided login is null! Recheck!");
            }

            if (!_validator.ValidateLogin(login))
            {
                _presenter.LoginFail(LoginFailType.LoginWrongFormat);
                return;
            }

            if (password == null)
            {
                throw new ArgumentNullException("Provided password is null! Recheck!");
            }

            if (!_validator.ValidatePassword(password))
            {
                _presenter.LoginFail(LoginFailType.PasswordWrongFormat);
                return;
            }

            try
            {
                string sid = _service.AuthorizeUser(login, password, out LoginFailType error);
                //            Console.WriteLine(error);
                if (error != LoginFailType.None)
                {
                    _presenter.LoginFail(error);
                    return;
                }
                string uid = _service.GetUserIdBySessionId(sid);

                if (uid == null)
                {
                    _presenter.LoginFail(LoginFailType.Error);
                    return;
                }
                _presenter.LoginSuccess(sid, uid);
            }
            catch (Exception ex)
            {
                Console.Write(ex);

                _presenter.LoginFail(LoginFailType.Error);
                return;
            }
        }