Ejemplo n.º 1
0
        private void DoLogin(UserData userInfo)
        {
            BaseValidator validator = new BaseValidator();

            if (!validator.ValidateLogOnFields(userInfo))
            {
                ShowError(validator.ClientException, LoginError);
                return;
            }

            UserData.Instance.HasSaveUserName    = (bool)saveUserToggleButton.IsChecked;
            UserData.Instance.HasIntegratedLogin = (bool)IntegratedToggleButton.IsChecked;

            ServiceInvoker.Initialize(delegate(object a, ServiceEventArgs serviceEventArgs)
            {
                ServiceResponse result = serviceEventArgs.Result;
                if (!result.Status)
                {
                    ShowError(new AppException(result.ErrorDetails), LoginError);
                    return;
                }

                if (!Convert.ToBoolean(result.Output))
                {
                    ShowError(new AppException(result.ErrorDetails), LoginError);
                    return;
                }

                IsolatedStorageSettings.ApplicationSettings.Save();

                string postData = JsonConvert.SerializeObject(userInfo);
                ServiceInvoker.InvokeServiceUsingPost("api/t360/Security/DoLogin", postData, true, delegate(object obj, ServiceEventArgs arg)
                {
                    ServiceResponse response = arg.Result;

                    if (!response.Status)
                    {
                        if (T360ErrorCodes.Disclaimer.Equals(response.ErrorDetails[0].Code))
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                UserData.Instance.HasDisclaimer   = true;
                                UserData.Instance.DisclaimerTitle = response.ErrorDetails[0].Data[0];
                                UserData.Instance.DisclaimerData  = response.ErrorDetails[0].Data[1];
                                UserActivity.Instance.LoadTimer();
                                UserData.Instance.IsAuthenticated = true;
                                Uri uri = new Uri("/Tymetrix.T360.Mobile.Client.AppWP7;component/Disclaimer/Disclaimer.xaml", UriKind.Relative);
                                this.NavigationService.Navigate(uri);
                                this.ProgressBar.Hide();
                            });
                        }
                        else if (T360ErrorCodes.PasswordReset.Equals(response.ErrorDetails[0].Code) ||
                                 T360ErrorCodes.RequestPasswordReset.Equals(response.ErrorDetails[0].Code) ||
                                 T360ErrorCodes.TooSimplePassword.Equals(response.ErrorDetails[0].Code))
                        {
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                Credential credential = Credential.Instance;
                                credential.Rules      = response.ErrorDetails[0].Data;
                                credential.ShowKeepCurrentPassword = T360ErrorCodes.RequestPasswordReset.Equals(response.ErrorDetails[0].Code);
                                UserActivity.Instance.LoadTimer();
                                UserData.Instance.IsAuthenticated = true;
                                Uri uri = new Uri("/Tymetrix.T360.Mobile.Client.AppWP7;component/ResetPassword/ResetPassword.xaml", UriKind.Relative);
                                this.NavigationService.Navigate(uri);
                                this.ProgressBar.Hide();
                            });
                        }
                        else
                        {
                            ShowError(new AppException(response.ErrorDetails), LoginError);
                        }
                        return;
                    }
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        ProcessUserData(response.Output, "/Tymetrix.T360.Mobile.Client.AppWP7");
                    });
                });
            });
        }