Beispiel #1
0
        public async Task <Account> GetAsync()
        {
            try {
                Account account = await _accountsHttpClient.GetAccountAsync(_authenticator.GetAccess());

                return(account);
            }
            catch (UnauthorizedException) {
                bool refreshResult = await _authenticator.RefreshAccessToken();

                if (refreshResult == false)
                {
                    _loginRenavigator.Renavigate();
                    return(null);
                }
                Account account = await _accountsHttpClient.GetAccountAsync(_authenticator.GetAccess());

                if (account == null)
                {
                    _loginRenavigator.Renavigate();
                }
                return(account);
            }
            catch (Exception) {
                _loginRenavigator.Renavigate();
                return(null);
            }
        }
Beispiel #2
0
        public override async Task ExecuteAsync(object parameter)
        {
            _registerViewModel.ErrorMessage = string.Empty;

            try
            {
                await _authenticator.Register(
                    _registerViewModel.Username,
                    _registerViewModel.Email,
                    _registerViewModel.Password,
                    _registerViewModel.ConfirmPassword,
                    _registerViewModel.Name,
                    _registerViewModel.Surname);

                _renavigator.Renavigate();
            }
            catch (PasswordsMismatchException)
            {
                _registerViewModel.ErrorMessage = "Password does not match confirm password.";
            }
            catch (EmailAlreadyExistsException)
            {
                _registerViewModel.ErrorMessage = "An account for this email already exists.";
            }
            catch (UsernameAlreadyExistsException)
            {
                _registerViewModel.ErrorMessage = "An account for this username already exists.";
            }
            catch (Exception)
            {
                _registerViewModel.ErrorMessage = "Registration failed.";
            }
        }
        public override async Task ExecuteAsync(object parameter)
        {
            _loginViewModel.ErrorMessage = string.Empty;

            try
            {
                await _authenticator.Login(_loginViewModel.Username, _loginViewModel.Password);

                Account account = _authenticator.CurrentAccount;

                if (account.User.Type == 1)
                {
                    _renavigator.Renavigate();
                }
                else
                {
                    _renavigatorUser.Renavigate();
                }
            }
            catch (UserNotFoundException)
            {
                _loginViewModel.ErrorMessage = "Username does not exist.";
            }
            catch (InvalidPasswordException)
            {
                _loginViewModel.ErrorMessage = "Incorrect password.";
            }
            catch (Exception)
            {
                _loginViewModel.ErrorMessage = "Login failed.";
            }
        }
Beispiel #4
0
        public override async Task ExecuteAsync(object parameter)
        {
            _registerViewModel.ErrorMessage = string.Empty;

            RegistrationResult registrationResult = await _authenticator.Register(
                _registerViewModel.Email,
                _registerViewModel.Username,
                _registerViewModel.Password,
                _registerViewModel.ConfirmPassword);

            switch (registrationResult)
            {
            case RegistrationResult.Success:
                _renavigator.Renavigate();
                break;

            case RegistrationResult.PasswordsDoNotMatch:
                _registerViewModel.ErrorMessage = "Confirm password does not match origin password.";
                break;

            case RegistrationResult.EmailAlreadyExists:
                _registerViewModel.ErrorMessage = "An account with this email already exists.";
                break;

            case RegistrationResult.UsernameAlreadyExists:
                _registerViewModel.ErrorMessage = "An account with this username already exists.";
                break;

            default:
                _registerViewModel.ErrorMessage = "Registration failed.";
                break;
            }
        }
Beispiel #5
0
        private async void LoginCmd()
        {
            bool success = await _authenticator.Login(Username, Password);

            if (success)
            {
                _renavigator.Renavigate();
            }
        }
        public async void Execute(object parameter)
        {
            bool success = await _authenticator.Login(_loginViewModel.Username, parameter.ToString());

            if (success)
            {
                _renavigator.Renavigate();
            }
        }
Beispiel #7
0
        /// <summary>
        /// try to login and navigate to selected view
        /// </summary>
        /// <param name="parameter"> parameter value will be password</param>
        public async void Execute(object parameter)
        {
            //user name is bind to property in view but password can not bind to view since security issue
            //password will be passed through parameter
            bool success = await _authenticator.Login(_loginViewModel.Username, parameter.ToString());

            //if login is success, then navigate to current view
            //current view will be MeterToFeetView because renavigation is set to MeterToFeetViewModel
            if (success)
            {
                _navigator.Renavigate();
            }
        }
        public override async Task ExecuteAsync(object parameter)
        {
            _loginViewModel.ErrorMessage = string.Empty;

            try
            {
                await _authenticator.Login(_loginViewModel.Username, _loginViewModel.Password);

                _renavigator.Renavigate();
            }
            catch (InvalidLoginOrPasswordException)
            {
                _loginViewModel.ErrorMessage = "Username and/or password is incorrect.";
            }
        }
Beispiel #9
0
        public async void Execute(object parameter)
        {
            try
            {
                bool success = await userManager.LoginAsync(loginViewModel.UserName, loginViewModel.Password);

                if (success)
                {
                    watchListNavigator.Renavigate();
                }
            }
            catch (Exception ex)
            {
                loginViewModel.Error = ex.Message;
                Debug.WriteLine(ex);
            }
        }
Beispiel #10
0
        public async void Execute(object parameter)
        {
            _registerViewModel.ErrorMessage = string.Empty;
            ResourceDictionary oldDict = (from d in Application.Current.Resources.MergedDictionaries
                                          where d.Source != null && d.Source.OriginalString.StartsWith("Resources/Lang.")
                                          select d).First();

            try {
                string             password           = parameter.ToString();
                RegistrationResult registrationResult = await _authenticator.Register(
                    _registerViewModel.Email,
                    _registerViewModel.Username,
                    password,
                    password
                    );

                switch (registrationResult)
                {
                case RegistrationResult.Success:
                    _registerRenavigator.Renavigate();
                    break;

                case RegistrationResult.EmailAlreadyExists:
                    _registerViewModel.ErrorMessage = oldDict["Errors_EmailAccountAlreadyExists"].ToString();
                    break;

                case RegistrationResult.UsernameAlreadyExists:
                    _registerViewModel.ErrorMessage = oldDict["Errors_UsernameAccountAlreadyExists"].ToString();
                    break;

                case RegistrationResult.InvalidEmail:
                    _registerViewModel.ErrorMessage = oldDict["Errors_InvalidEmail"].ToString();
                    break;

                default:
                    _registerViewModel.ErrorMessage = oldDict["Errors_Failed"].ToString();
                    break;
                }
            }
            catch (Exception) {
                _registerViewModel.ErrorMessage = oldDict["Errors_Failed"].ToString();
            }
        }
Beispiel #11
0
        public override async Task ExecuteAsync(object parameter)
        {
            _registerViewModel.ErrorMessage = string.Empty;

            try
            {
                RegistrationResult registration = await _authenticator.Register(
                    _registerViewModel.Email,
                    _registerViewModel.Username,
                    _registerViewModel.Password,
                    _registerViewModel.ConfirmPassword);

                switch (registration)
                {
                case RegistrationResult.Success:
                    MessageBox.Show("Регистрация прошла успешно", "Инфо", MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                    _renavigator.Renavigate();
                    break;

                case RegistrationResult.PasswordDoNotMatch:
                    _registerViewModel.ErrorMessage = "Пароль не соответствуют введённому паролю.";
                    break;

                case RegistrationResult.EmailAlreadyExist:
                    _registerViewModel.ErrorMessage = "Такой email уже существует.";
                    break;

                case RegistrationResult.UsernameAlreadyExist:
                    _registerViewModel.ErrorMessage = "Пользователь с таким именем уже существует.";
                    break;

                default:
                    _registerViewModel.ErrorMessage = "Ошибка регистрации";
                    break;
                }
            }
            catch (Exception)
            {
                _registerViewModel.ErrorMessage = "Ошибка регистрации";
            }
        }
Beispiel #12
0
        public async void Execute(object parameter)
        {
            switch (_upsertAction)
            {
            case UpsertAction.Add:
                await _employeeRepo.AddAsync(_upsertEmployeeViewModel.Employee);

                break;

            case UpsertAction.Update:
                await _employeeRepo.Update(_upsertEmployeeViewModel.Employee);

                break;

            default:
                break;
            }

            _renavigator.Renavigate();
        }
        public async void Execute(object parameter)
        {
            try
            {
                var success = await userManager.RegisterAsync(
                    registerViewModel.Name,
                    registerViewModel.UserName,
                    registerViewModel.Password,
                    registerViewModel.ConfirmPassword);

                if (success)
                {
                    loginNavigator.Renavigate();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
        public async void Execute(object parameter)
        {
            switch (_upsertAction)
            {
            case UpsertAction.Add:
                await _compRepo.Add(_addCompanyViewModel.Company);

                break;

            case UpsertAction.Update:
                await _compRepo.Update(_addCompanyViewModel.Company);

                break;

            default:
                break;
            }

            _renavigator.Renavigate();
        }
Beispiel #15
0
        public override async Task ExecuteAsync(object?parameter)
        {
            try
            {
                await _authenticator.Login(_loginViewModel.Username, _loginViewModel.Password);

                _renavigator.Renavigate();
            }
            catch (UserNotFoundException)
            {
                _loginViewModel.ErrorMessage = "Пользовать не найден";
            }
            catch (InvalidPasswordException)
            {
                _loginViewModel.ErrorMessage = "Неправилный пароль";
            }
            catch (Exception)
            {
                _loginViewModel.ErrorMessage = "Ошибка входа";
            }
        }
Beispiel #16
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                await _authenticator.Login(_loginViewModel.Username, _loginViewModel.Password);

                _renavigator.Renavigate();
            }
            catch (UserNotFoundException)
            {
                _loginViewModel.ErrorMessage = "Username does not exist.";
            }
            catch (InvalidPasswordExeption)
            {
                _loginViewModel.ErrorMessage = "Incorrect password.";
            }
            catch (Exception)
            {
                _loginViewModel.ErrorMessage = "Login failed.";
            }
        }
Beispiel #17
0
        public async void Execute(object parameter)
        {
            ResourceDictionary oldDict = (from d in Application.Current.Resources.MergedDictionaries
                                          where d.Source != null && d.Source.OriginalString.StartsWith("Resources/Lang.")
                                          select d).First();

            try {
                await _authenticator.Login(_loginViewModel.Username, parameter.ToString());

                _renavigator.Renavigate();
            }
            catch (UserNotFoundException) {
                _loginViewModel.ErrorMessage = oldDict["Errors_UsernameDoesntExists"].ToString();
            }
            catch (InvalidPasswordException) {
                _loginViewModel.ErrorMessage = oldDict["Errors_IncorrectPassword"].ToString();
            }
            catch (Exception) {
                _loginViewModel.ErrorMessage = oldDict["Errors_Failed"].ToString();
            }
        }
        public override async Task ExecuteAsync(object parameter)
        {
            registerViewModel.ErrorMessage = string.Empty;

            //try
            //{
            RegistrationResult registrationResult = await authenticator.Register(
                registerViewModel.Email,
                registerViewModel.Username,
                registerViewModel.Password,
                registerViewModel.ConfirmPassword);

            switch (registrationResult)
            {
            case RegistrationResult.Success:
                registerRenavigator.Renavigate();
                break;

            case RegistrationResult.PasswordDoNotMatch:
                registerViewModel.ErrorMessage = "Password does not match the confirm password";
                break;

            case RegistrationResult.UsernameAlreadyExists:
                registerViewModel.ErrorMessage = $"Username {registerViewModel.Username} already exists";
                break;

            case RegistrationResult.EmailAlreadyExists:
                registerViewModel.ErrorMessage = $"Email {registerViewModel.Email} is already in use.";
                break;

            default:
                registerViewModel.ErrorMessage = "Registration failed.";
                break;
            }
            //}
            //catch (Exception e)
            //{
            //    registerViewModel.ErrorMessage = "Registration failed.";
            //}
        }
        public async Task <Issue> GetAsync(int id)
        {
            try {
                Issue result = await _issuesHttpClient.GetAsync(_authenticator.GetAccess(), id);

                return(result);
            }
            catch (UnauthorizedException) {
                bool refreshResult = await _authenticator.RefreshAccessToken();

                if (refreshResult == false)
                {
                    _loginRenavigator.Renavigate();
                    return(null);
                }
                Issue result = await _issuesHttpClient.GetAsync(_authenticator.GetAccess(), id);

                return(result);
            }
            catch (Exception) {
                _loginRenavigator.Renavigate();
                return(null);
            }
        }
Beispiel #20
0
        public async Task <Domain.Models.Task> CreateAsync(Domain.Models.Task entity)
        {
            try {
                Domain.Models.Task result = await _tasksHttpClient.CreateAsync(_authenticator.GetAccess(), entity);

                return(result);
            }
            catch (UnauthorizedException) {
                bool refreshResult = await _authenticator.RefreshAccessToken();

                if (refreshResult == false)
                {
                    _loginRenavigator.Renavigate();
                    return(null);
                }
                Domain.Models.Task result = await _tasksHttpClient.CreateAsync(_authenticator.GetAccess(), entity);

                return(result);
            }
            catch (Exception) {
                _loginRenavigator.Renavigate();
                return(null);
            }
        }
Beispiel #21
0
 public void Execute(object parameter)
 {
     _authenticator.Logout();
     _renavigator.Renavigate();
 }
 private void LogoutUser()
 {
     _authenticator.Logout();
     _renavigate.Renavigate();
 }
Beispiel #23
0
 public void Execute(object parameter)
 {
     _renavigator.Renavigate();
 }
Beispiel #24
0
 public void Execute(object parameter)
 {
     userManager.Logout();
     loginNavigator.Renavigate();
 }