@@ -36,6 +36,7 @@ public Home()
3636 if ( Application . Current . Properties . ContainsKey ( "Token" )
3737 && Application . Current . Properties . ContainsKey ( "Name" ) )
3838 {
39+ GetUserLoggedIn ( Application . Current . Properties [ "Id" ] . ToString ( ) ) ;
3940 UserName . Text = Application . Current . Properties [ "Name" ] . ToString ( ) ;
4041 Register . Text = "Ver Perfil" ;
4142 }
@@ -50,6 +51,31 @@ public Home()
5051 GetVersionApp ( ) ;
5152 }
5253
54+ public async void GetUserLoggedIn ( string id )
55+ {
56+ try
57+ {
58+ Uri RequestUri = new ( $ "https://matchinggame.vercel.app/api/matching-game/{ id } ") ;
59+ var client = new HttpClient ( ) ;
60+ HttpResponseMessage response = await client . GetAsync ( RequestUri ) ;
61+ if ( response . IsSuccessStatusCode )
62+ {
63+ var content = await response . Content . ReadAsStringAsync ( ) ;
64+ User user = JsonConvert . DeserializeObject < User > ( content ) ;
65+ Application . Current . Properties [ "Name" ] = user . name ;
66+ Application . Current . Properties [ "Photo" ] = user . photo ;
67+ Application . Current . Properties [ "Email" ] = user . email ;
68+ Application . Current . Properties [ "Score" ] = user . score ;
69+ lblScore . Text = user . score . ToString ( ) ;
70+ Application . Current . Properties [ "MaxLevel" ] = user . maxLevel ;
71+ }
72+ }
73+ catch ( Exception )
74+ {
75+ ( Application . Current ) . MainPage = new NavigationPage ( new Home ( ) ) ;
76+ }
77+ }
78+
5379 public async void GetVersionApp ( )
5480 {
5581 try
@@ -74,9 +100,9 @@ public async void GetVersionApp()
74100 }
75101 }
76102 }
77- catch ( Exception error )
103+ catch ( Exception )
78104 {
79- await DisplayAlert ( "Error" , error . Message , "Cancelar" ) ;
105+ ( Application . Current ) . MainPage = new NavigationPage ( new Home ( ) ) ;
80106 }
81107 }
82108
@@ -89,7 +115,7 @@ private async void Register_Clicked(object sender, EventArgs e)
89115 {
90116 if ( Application . Current . Properties . ContainsKey ( "Token" )
91117 && Application . Current . Properties . ContainsKey ( "Name" ) )
92- await Navigation . PushAsync ( new ProfilePage ( ) ) ;
118+ await Navigation . PushModalAsync ( new ProfilePage ( ) ) ;
93119 else
94120 await Navigation . PushAsync ( new RegisterPage ( ) ) ;
95121 }
@@ -98,26 +124,11 @@ protected override bool OnBackButtonPressed()
98124 {
99125 base . OnBackButtonPressed ( ) ;
100126 var existingPages = Navigation . NavigationStack . ToList ( ) ;
101-
102127 foreach ( var page in existingPages )
103- {
104- if ( existingPages [ 0 ] != page )
105- {
128+ if ( existingPages [ existingPages . Count - 1 ] != page )
106129 Navigation . RemovePage ( page ) ;
107- }
108- }
109- //Device.BeginInvokeOnMainThread(async () =>
110- //{
111- // var result = await DisplayAlert("Salir", "¿Desea salir de la aplicación?", "Si", "No");
112- // if (result) await Navigation.PopAsync();
113- //});
114- return false ;
115- }
116130
117- private void PromptForExit ( )
118- {
119- Application . Current . Quit ( ) ;
120- // System.Environment.Exit(0);
131+ return false ;
121132 }
122133
123134 private async void NavigateToInfoPage_Clicked ( object sender , EventArgs e )
0 commit comments