Пример #1
0
        /// <summary>
        /// Get Token and Store in Cache
        /// </summary>
        /// <returns></returns>
        private async Task <bool> GetTokenForUser()
        {
            // Crypt password
            var passwordCrypted = Convert.ToBase64String(Utils.EncryptStringToBytes_Aes(Password));

            _url = GetUrlForCompany(UserName);
            _userLoginService = new UserLoginService(new UserModel {
                UserName = UserName, Password = passwordCrypted, URL = _url
            });
            string token = await _userLoginService.GetToken(new UserModel { UserName = UserName, Password = passwordCrypted });

            if (!String.IsNullOrEmpty(token))
            {
                Application.Current.Properties["UserData"] = Utils.SerializeToJson(new UserModel {
                    UserName = UserName, Password = passwordCrypted, Token = token, URL = _url
                });
                return(true);
            }
            else if (token == null)
            {
                await _pageService.DisplayAlert("Erreur de connexion", "Connectez-vous à internet puis réessayez.", "Ok");

                return(false);
            }
            else
            {
                await _pageService.DisplayAlert("Connexion refusée", "Vous n'êtes pas autorisé à vous connecter.\nVérifiez vos identifiants puis réessayer.", "Ok");

                return(false);
            }
        }