Exemple #1
0
        public async Task <string> DoLogin(string name, string pass)
        {
            if (name.Length == 0 || pass.Length == 0)
            {
                return(AppResources.ErrorMsgNamePassEmpty);
            }

            string uid       = null;
            bool   isSuccess = false;

            try
            {
                IsBusy = true;
                if (!String.IsNullOrEmpty(Uid) && !string.IsNullOrEmpty(_formHash))
                {
                    await new S1WebClient().Logout(_formHash);
                }
                S1WebClient.ResetCookie();
                var user = await new S1WebClient().Login(name, pass);
                uid = user.Member_uid;
                if (uid != null)
                {
                    Uid         = uid;
                    LoginStatus = name;
                    isSuccess   = true;
                    return(null);
                }
                return(AppResources.ErrorMsgUnknown);
            }
            catch (Exception ex)
            {
                var mainpage = IoC.Get <MainPageViewModel>();
                var userEx   = (ex as S1UserException);
                if ((ex is System.Net.WebException && DeviceNetworkInformation.IsNetworkAvailable) ||
                    (userEx != null && userEx.ErrorType == UserErrorTypes.InvalidData))
                {
                    ServerViewModel.Current.CheckServerStatus(mainpage);
                }
                return(S1Nyan.Utils.Util.ErrorMsg.GetExceptionMessage(ex));
            }
            finally
            {
                IsBusy = false;
                _eventAggregator.Publish(new UserMessage(Messages.LoginStatusChanged, isSuccess));
            }
        }
Exemple #2
0
        public async Task <string> DoLogin(string name, string pass)
        {
            if (name.Length == 0 || pass.Length == 0)
            {
                return(AppResources.ErrorMsgNamePassEmpty);
            }

            string uid       = null;
            bool   isSuccess = false;

            try
            {
                IsBusy = true;
                if (!String.IsNullOrEmpty(Uid) && !string.IsNullOrEmpty(_formHash))
                {
                    await new S1WebClient().Logout(_formHash);
                }
                S1WebClient.ResetCookie();
                var user = await new S1WebClient().Login(name, pass);
                uid = user.Member_uid;
                if (uid != null)
                {
                    Uid         = uid;
                    LoginStatus = name;
                    isSuccess   = true;
                    return(null);
                }
                return(AppResources.ErrorMsgUnknown);
            }
            catch (Exception ex)
            {
                return(S1Nyan.Utils.Util.ErrorMsg.GetExceptionMessage(ex));
            }
            finally
            {
                IsBusy = false;
                _eventAggregator.Publish(new UserMessage(Messages.LoginStatusChanged, isSuccess));
            }
        }