Subversion Repository Public Repository

Nextrek

Diff Revisions 798 vs 799 for /Android/SmartCharging/SmartCharging_WP/SmartCharging/LoginPage.xaml.cs

Diff revisions: vs.
  @@ -1,4 +1,6 @@
1 - using SmartCharging.Common;
1 + using Facebook.Client;
2 + using Facebook.Client.Controls;
3 + using SmartCharging.Common;
2 4 using SmartCharging.DataModel;
3 5 using SmartCharging.Net;
4 6 using System;
  @@ -42,6 +44,9 @@
42 44 this.navigationHelper = new NavigationHelper(this);
43 45 this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
44 46 this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
47 + Session.OnFacebookAppRequestFinished = new FacebookDelegate((result)=>{
48 +
49 + });
45 50 this.SMA = SmartChargeAPI.Instance;
46 51
47 52 }
  @@ -74,27 +79,11 @@
74 79 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
75 80 /// a dictionary of state preserved by this page during an earlier
76 81 /// session. The state will be null the first time a page is visited.</param>
77 - private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
82 + private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
78 83 {
79 - CredentialStorage cs = new CredentialStorage();
80 - PasswordCredential credentials = cs.GetCredential();
81 - this.hideLoading();
82 - // autologin
83 - if (credentials != null)
84 - {
85 - this.showLoading();
86 - credentials.RetrievePassword();
87 - User user = await this.SMA.Login(credentials.UserName, credentials.Password);
88 - this.hideLoading();
89 - if (user != null)
90 - {
91 - this.goToUserPage();
92 - }
93 - else
94 - {
95 - cs.RemoveCredentials();
96 - }
97 - }
84 +
85 +
86 +
98 87
99 88 }
100 89
  @@ -161,7 +150,7 @@
161 150 }
162 151
163 152 private void goToUserPage()
164 - {
153 + {
165 154 var aw = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
166 155 () => {
167 156 this.Frame.Navigate(typeof(StandardUserLoggedInPage));
  @@ -202,5 +191,24 @@
202 191 {
203 192 this.Loader.Visibility = Visibility.Collapsed;
204 193 }
194 +
195 + private async void loginButton_SessionStateChanged(object sender, Facebook.Client.Controls.SessionStateChangedEventArgs e)
196 + {
197 + if (e.SessionState == Facebook.Client.Controls.FacebookSessionState.Opened){
198 + showLoading();
199 + GraphUser gu = await Utils.RetriveUserInfo(Session.ActiveSession.CurrentAccessTokenData.AccessToken);
200 + if (gu != null && !String.IsNullOrEmpty(gu.Id)) {
201 + User user = await this.SMA.FacebookLogin(gu.Id, Session.ActiveSession.CurrentAccessTokenData.AccessToken);
202 + if (user != null)
203 + {
204 + this.goToUserPage();
205 + }
206 + }
207 +
208 + hideLoading();
209 + }
210 + }
211 +
212 +
205 213 }
206 214 }