예제 #1
0
        private async void AutoReLogin()
        {
            System.Diagnostics.Debug.WriteLine("AutoReLogin");

            var response = await service.AutoReLoginRequest();

            switch (response.Item1)
            {
            case 1:
                var res = response.Item2;
                if (res.ContainsKey("access_token"))
                {
                    using (SQLiteConnection conn = new SQLiteConnection(App.DatabasePath))
                    {
                        var _user = conn.Table <UserModel>().FirstOrDefault();
                        conn.Execute($"UPDATE UserModel SET Token = '{res["access_token"].ToString()}' WHERE Id = {_user.Id}");
                        App.CurrentUser.Token = res["access_token"].ToString();

                        Rank   = Int32.Parse(res["rank"].ToString());
                        Wallet = Int32.Parse(res["wallet"].ToString());
                    }
                }
                else
                {
                    using (SQLiteConnection conn = new SQLiteConnection(App.DatabasePath))
                    {
                        conn.Execute("DELETE FROM UserModel");
                        await _navigationService.NavigateAsync("/LoginPage");
                    }
                }

                break;

            case 2:
            case 3:
                using (SQLiteConnection conn = new SQLiteConnection(App.DatabasePath))
                {
                    conn.Execute("DELETE FROM UserModel");
                    await _navigationService.NavigateAsync("/LoginPage");
                }
                break;

            default:
                break;
            }
        }