Ejemplo n.º 1
0
 public void ContinueLoginAndSchedule()
 {
     NotifyLoading(true);
     SimvaApi <IStudentsApi> .ContinueLogin()
     .Then(simvaController =>
     {
         this.auth            = simvaController.AuthorizationInfo;
         this.simvaController = simvaController;
         return(UpdateSchedule());
     })
     .Then(schedule =>
     {
         var result = new AsyncCompletionSource();
         StartCoroutine(AsyncCoroutine(LaunchActivity(schedule.Next), result));
         return(result);
     })
     .Catch(error =>
     {
         NotifyLoading(false);
         NotifyManagers(error.Message);
     })
     .Finally(() =>
     {
         OpenIdUtility.tokenLogin = false;
     });
 }
Ejemplo n.º 2
0
        private void Login()
        {
            SimvaConf.Local = new SimvaConf();
            var carga = new AsyncCompletionSource();

            Observable.FromCoroutine(() => LoadSimvaConf(SimvaConf.Local.LoadAsync(), carga)).Subscribe();

            isLogin = true;
            carga.Then(() =>
            {
                IAsyncOperation <SimvaApi <ITeachersApi> > loginCall = null;
                if (ProjectConfigData.existsKey("Simva.RefreshToken"))
                {
                    loginCall = SimvaApi <ITeachersApi> .Login(new AuthorizationInfo
                    {
                        ClientId     = "uadventure",
                        RefreshToken = ProjectConfigData.getProperty("Simva.RefreshToken")
                    });
                }
                else
                {
                    loginCall = SimvaApi <ITeachersApi> .Login(true);
                }

                loginCall.Then(simvaController =>
                {
                    this.simvaController = simvaController;
                    this.simvaConf       = simvaController.SimvaConf;
                    var apiClient        = ((TeachersApi)this.simvaController.Api).ApiClient;
                    apiClient.onAuthorizationInfoUpdate += auth =>
                    {
                        ProjectConfigData.setProperty("Simva.RefreshToken", auth.RefreshToken);
                    };
                    ProjectConfigData.setProperty("Simva.RefreshToken", apiClient.AuthorizationInfo.RefreshToken);
                    ProjectConfigData.storeToXML();
                })
                .Catch(error =>
                {
                    ProjectConfigData.setProperty("Simva.RefreshToken", null);
                    ProjectConfigData.storeToXML();
                    Controller.Instance.ShowErrorDialog("Simva.Login.Error.Title", "Simva.Login.Error.Message");
                })
                .Finally(() => isLogin = false);
            });
        }
 public void LoginAndSchedule(string token)
 {
     NotifyLoading(true);
     SimvaApi <IStudentsApi> .LoginWithToken(token)
     .Then(simvaController =>
     {
         this.auth            = simvaController.AuthorizationInfo;
         this.simvaController = simvaController;
         return(UpdateSchedule());
     })
     .Then(schedule =>
     {
         var result = new AsyncCompletionSource();
         StartCoroutine(AsyncCoroutine(LaunchActivity(schedule.Next), result));
         return(result);
     })
     .Catch(error =>
     {
         NotifyLoading(false);
         NotifyManagers(error.Message);
     });
 }
Ejemplo n.º 4
0
 public override IEnumerator OnGameReady()
 {
     if (PlayerPrefs.HasKey("simva_auth"))
     {
         NotifyLoading(true);
         this.auth          = JsonConvert.DeserializeObject <AuthorizationInfo>(PlayerPrefs.GetString("simva_auth"));
         this.auth.ClientId = "uadventure";
         SimvaApi <IStudentsApi> .Login(this.auth)
         .Then(simvaController =>
         {
             this.auth            = simvaController.AuthorizationInfo;
             this.simvaController = simvaController;
             return(UpdateSchedule());
         })
         .Then(schedule =>
         {
             var result = new AsyncCompletionSource();
             StartCoroutine(AsyncCoroutine(LaunchActivity(schedule.Next), result));
             return(result);
         })
         .Catch(error =>
         {
             NotifyLoading(false);
             NotifyManagers(error.Message);
         })
         .Finally(() =>
         {
             OpenIdUtility.tokenLogin = false;
         });
     }
     else if (HasLoginInfo())
     {
         ContinueLoginAndSchedule();
     }
     yield return(null);
 }
Ejemplo n.º 5
0
        private void DoRegisterAndLogin()
        {
            DoBorderWithTitle("Set up your account", () =>
            {
                if (GUILayout.Button("Login") && ValidateLogin())
                {
                    var myWindow = GetActiveWindow();
                    SimvaApi <ITeachersApi> .Login(true)
                    .Then(simvaController =>
                    {
                        if (simvaController != null)
                        {
                            this.simvaController = simvaController;
                            var apiClient        = ((TeachersApi)this.simvaController.Api).ApiClient;
                            apiClient.onAuthorizationInfoUpdate += auth =>
                            {
                                ProjectConfigData.setProperty("Simva.RefreshToken", auth.RefreshToken);
                            };
                            ProjectConfigData.setProperty("Simva.RefreshToken", apiClient.AuthorizationInfo.RefreshToken);
                            ProjectConfigData.storeToXML();
                        }
                    })
                    .Catch(error =>
                    {
                        Debug.Log(error.Message);
                        Controller.Instance.ShowErrorDialog("Simva.Register.Failed.Title", "Simva.Register.Failed.Message");
                    })
                    .Finally(() =>
                    {
                        BringWindowToTop(myWindow);
                        isLogin = false;
                    });
                }

                return;

                // Username field
                registerUser = EditorGUILayout.TextField("Username", registerUser);
                // Password field
                registerPassword = EditorGUILayout.PasswordField("Password", registerPassword);
                // Email field
                email = EditorGUILayout.TextField("Email", email);
                // TOS Field
                tos = DoTermsAndConditionsField(tos);

                using (new EditorGUI.DisabledGroupScope(!tos))
                {
                    if (GUILayout.Button("Create account") && ValidateRegister())
                    {
                        isLogin = true;
                        //var randomUser = GenerateRandomBase58Key(32);

                        /*SimvaApi<ITeachersApi>.Register(registerUser, email, registerPassword, true)
                         *  .Then(registered =>
                         *  {
                         *      return registered ? SimvaApi<ITeachersApi>.LoginWithCredentials(registerUser, registerPassword) : null;
                         *  })
                         *  .Then(simvaController =>
                         *  {
                         *      if (simvaController != null)
                         *      {
                         *          this.simvaController = simvaController;
                         *          var apiClient = ((TeachersApi)this.simvaController.Api).ApiClient;
                         *          apiClient.onAuthorizationInfoUpdate += auth =>
                         *          {
                         *              ProjectConfigData.setProperty("Simva.RefreshToken", auth.RefreshToken);
                         *          };
                         *          ProjectConfigData.setProperty("Simva.RefreshToken", apiClient.AuthorizationInfo.RefreshToken);
                         *          ProjectConfigData.storeToXML();
                         *      }
                         *  })
                         *  .Catch(error =>
                         *  {
                         *      Controller.Instance.ShowErrorDialog("Simva.Register.Failed.Title", "Simva.Register.Failed.Message");
                         *  })
                         *  .Finally(() => isLogin = false);*/
                    }
                }

                // Separator
                DoSeparator("Or");

                user     = EditorGUILayout.TextField("User", user);
                password = EditorGUILayout.PasswordField("Password", password);
                if (GUILayout.Button("Login") && ValidateLogin())
                {
                    SimvaApi <ITeachersApi> .LoginWithCredentials(user, password)
                    .Then(simvaController =>
                    {
                        if (simvaController != null)
                        {
                            this.simvaController = simvaController;
                            var apiClient        = ((TeachersApi)this.simvaController.Api).ApiClient;
                            apiClient.onAuthorizationInfoUpdate += auth =>
                            {
                                ProjectConfigData.setProperty("Simva.RefreshToken", auth.RefreshToken);
                            };
                            ProjectConfigData.setProperty("Simva.RefreshToken", apiClient.AuthorizationInfo.RefreshToken);
                            ProjectConfigData.storeToXML();
                        }
                    })
                    .Catch(error =>
                    {
                        Controller.Instance.ShowErrorDialog("Simva.Register.Failed.Title", "Simva.Register.Failed.Message");
                    })
                    .Finally(() =>
                    {
                        isLogin = false;
                    });
                }
            });
        }