Exemplo n.º 1
0
        internal async Task TryLoginAsync()
        {
            if (IsSignedIn || String.IsNullOrWhiteSpace(UserName) || String.IsNullOrWhiteSpace(Password))
            {
                return;
            }
            var session = App.Settings.Credential;

            if (session != null && !session.Expired)             // Login with credential cookie
            {
                LightKindomHtmlClient.Credential = session;
                IsSignedIn = true;
                return;
            }
            IsLoading   = true;
            LoadingText = "Logging into Light Kindom";
            try
            {
                var credential = await LightKindomHtmlClient.LoginAsync(UserName, Password);

                IsSignedIn              = true;
                App.Settings.UserName   = UserName;
                App.Settings.Password   = Password;
                App.Settings.Credential = credential;
            }
            catch (Exception exception)
            {
                MessageBox.Show("Login failed, please check your network and username / password.");
            }
            IsLoading   = false;
            LoadingText = "";
        }
Exemplo n.º 2
0
        public static async Task <bool> SignInAutomaticllyAsync(bool forecRefresh = false)
        {
            var userName = Settings.UserName;
            var session  = Settings.Credential;
            var password = Settings.Password;

            if (String.IsNullOrEmpty(password) || String.IsNullOrEmpty(userName))
            {
                return(false);
            }
            try
            {
                if (!forecRefresh && !session.Expired)
                {
                    LightKindomHtmlClient.Credential = session;
                    User = new UserInfo {
                        UserName = userName, Password = password, Credential = session
                    };
                }
                else
                {
                    var newSession = await LightKindomHtmlClient.LoginAsync(userName, password);

                    if (newSession == null)
                    {
                        return(false);
                    }
                    Settings.Credential = newSession;
                    User = new UserInfo {
                        UserName = userName, Password = password, Credential = newSession
                    };
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        public static async Task <UserInfo> SignInAsync(string userName, string password)
        {
            try
            {
                var session = await LightKindomHtmlClient.LoginAsync(userName, password);

                if (session == null)
                {
                    return(null);
                }
                Settings.Credential = session;
                Settings.SetUserNameAndPassword(userName, password);
                User = new UserInfo {
                    UserName = userName, Password = password, Credential = session
                };
            }
            catch (Exception)
            {
                return(null);
            }
            return(User);
        }