private async Task<bool> SignIn () { var account = new Account { Username = Username, Password = Password }; return await AccountService.Instance.Login (account); }
public async Task Register (Account account, User user) { using (var client = MobileServiceClientFactory.CreateClient ()) { await client.GetTable<User> ().InsertAsync (user); } account.UserId = user.Id; await Insert (account, false); }
private async Task ExecuteSignUpUserCommand () { if (IsBusy) { return; } IsBusy = true; var user = new User { Name = string.Format ("{0} {1}", FirstName, LastName), ProfileImage = GravatarService.CalculateUrl (Email) }; var account = new Account { Username = Username, Password = Password, Email = Email, UserId = user.Id }; try { DialogService.ShowLoading (Strings.CreatingAccount); if (await ConnectivityService.IsConnected ()) { await CreateAccount (account, user); await SignIn (account); NavigateToMainUI (); DialogService.HideLoading (); } else { DialogService.ShowError (Strings.NoInternetConnection); } } catch (Exception ex) { Insights.Report (ex); } IsBusy = false; }
public async Task<bool> Login () { bool result = false; try { await BlobCache.Secure.Vacuum (); if (!string.IsNullOrEmpty (AuthenticationToken)) { var loginInfo = await BlobCache.Secure.GetLoginAsync (); var account = new Account { Username = loginInfo.UserName, Password = loginInfo.Password }; await Insert (account, true); Account = await GetCurrentAccount (account); User = await GetCurrentUser (); await FriendService.Instance.RefreshFriendsList (); await FriendService.Instance.RefreshPendingFriendsList (); var moreInformation = new Dictionary<string, string> { { "Name", User.Name }, { "Email", Account.Email } }; Xamarin.Insights.Identify(Account.Username, moreInformation); result = true; } } catch { result = false; } return result; }
private async Task CreateAccount (Account account, User user) { await AccountService.Instance.Register (account, user); }
private async Task SignIn (Account account) { await AccountService.Instance.Login (account); }
private async Task<Account> GetCurrentAccount (Account account) { using (var handler = new ZumoAuthHeaderHandler ()) { using (var client = MobileServiceClientFactory.CreateClient (handler)) { var currentAccount = await client.GetTable <Account> () .Where (acct => acct.Username == account.Username) .Select (acct => acct).ToListAsync (); return currentAccount [0]; } } }
private async Task Insert (Account account, bool isLogin) { using (var handler = new AuthenticationHandler ()) { using (var client = MobileServiceClientFactory.CreateClient (handler)) { var table = client.GetTable<Account> (); var parameters = new Dictionary<string, string> { { "login", isLogin.ToString ().ToLower ()} }; await table.InsertAsync (account, parameters); } } }
public async Task<bool> Login (Account account) { bool result; try { await Insert (account, true); Account = await GetCurrentAccount (account); User = await GetCurrentUser (); await FriendService.Instance.RefreshFriendsList (); await FriendService.Instance.RefreshPendingFriendsList (); await BlobCache.Secure.SaveLogin (account.Username, account.Password, "default", DateTimeOffset.Now.AddDays (30)); CrossSettings.Current.AddOrUpdateValue<string> ("profileImage", User.ProfileImage); CrossSettings.Current.AddOrUpdateValue<string> ("profileName", User.Name); // Store token / credentials await BlobCache.LocalMachine.InsertObject <string> ("authenticationToken", AccountService.Instance.AuthenticationToken, DateTimeOffset.Now.AddDays (30)); var moreInformation = new Dictionary <string, string> { { "Name", User.Name }, { "Email", Account.Email } }; Xamarin.Insights.Identify(Account.Username, moreInformation); result = true; } catch (Exception ex) { Xamarin.Insights.Report (ex); result = false; } return result; }