Example #1
0
        private bool LogIn()
        {
            IoService.Out.Write(Resources.InfoLogin);
            string login = IoService.In.ReadLine()?.Trim(' ');

            IoService.Out.Write(Resources.InfoPassword);
            string password = IoService.ReadPassword();

            bool valid = UserValidator.ValidPassword(password);

            if (!valid)
            {
                IoService.Out.WriteLine(
                    Resources.ErrorNotValidPassword,
                    PasswordValidation.MinPasswordLength);
                return(false);
            }

            if (Session.IsLogged)
            {
                IoService.Out.WriteLine(Resources.ErrorDoubleLogIn);
                Logger.Error(Resources.ErrorDoubleLogIn);

                throw new Exception(Resources.ErrorDoubleLogIn);
            }

            try
            {
                LoginDTO loginModel = new LoginDTO()
                {
                    UserName = login,
                    Password = password
                };

                Response <SessionInfo> response = authenticator.LogIn(loginModel);

                if (response.IsSuccessful)
                {
                    Session = response.ResultTask.Result;
                }

                Logger.Info(Resources.InfoEndedSignUp);

                LoggedIn?.Invoke(this, new EventArgs());
            }
            catch (Exception ex)
            {
                IoService.Out.WriteLine(ex.Message);
                Logger.Error(ex.Message);
                return(false);
            }

            return(true);
        }
        private string ReadAndValidatePassword()
        {
            bool   valid;
            string password;

            do
            {
                IoService.Out.Write(Resources.InfoPassword);
                password = IoService.ReadPassword();

                valid = UserValidator.ValidPassword(password);
                if (!valid)
                {
                    IoService.Out.WriteLine(
                        Resources.ErrorNotValidPassword,
                        PasswordValidation.MinPasswordLength);
                }
            }while (!valid);

            return(password);
        }