protected async override void SelectAccount(IAccount account) { var githubAccount = (BitbucketAccount)account; if (githubAccount.DontRemember) { ShowViewModel <AddAccountViewModel>(new AddAccountViewModel.NavObject { AttemptedAccountId = githubAccount.Id }); return; } try { IsLoggingIn = true; var client = await _loginService.LoginAccount(githubAccount); _applicationService.ActivateUser(githubAccount, client); } catch (Exception e) { DisplayAlert("Unable to login: " + e.Message); ShowViewModel <AddAccountViewModel>(new AddAccountViewModel.NavObject() { AttemptedAccountId = githubAccount.Id }); } finally { IsLoggingIn = false; } }
protected async Task Startup() { var accounts = (await _accountsService.GetAccounts()).ToList(); if (!accounts.Any()) { GoToNewAccount.Execute(null); return; } var account = await _accountsService.GetActiveAccount(); if (account == null) { GoToAccounts.Execute(null); return; } var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password); //Lets login! try { ImageUrl = null; Status = null; IsLoggingIn = true; Uri accountAvatarUri = null; Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out accountAvatarUri); ImageUrl = accountAvatarUri; Status = "Logging in as " + account.Username; var client = await _loginFactory.LoginAccount(account); _applicationService.ActivateUser(account, client); if (!isEnterprise) { StarOrWatch(); } GoToMenu.Execute(typeof(MenuViewModel)); } catch (GitHubSharp.UnauthorizedException e) { DisplayAlertAsync("The credentials for the selected account are incorrect. " + e.Message) .ToObservable() .BindCommand(GoToAccounts); } catch (Exception e) { DisplayAlert(e.Message); GoToAccounts.Execute(null); } finally { IsLoggingIn = false; } }
protected async override void SelectAccount(IAccount account) { var githubAccount = (GitHubAccount)account; var isEnterprise = githubAccount.IsEnterprise || !string.IsNullOrEmpty(githubAccount.Password); if (githubAccount.DontRemember) { //Hack for now if (isEnterprise) { ShowViewModel <AddAccountViewModel>(new AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id }); } else { ShowViewModel <LoginViewModel>(LoginViewModel.NavObject.CreateDontRemember(githubAccount)); } return; } try { IsLoggingIn = true; var client = await _loginFactory.LoginAccount(githubAccount); _applicationService.ActivateUser(githubAccount, client); } catch (GitHubSharp.UnauthorizedException e) { DisplayAlert("The credentials for the selected account are incorrect. " + e.Message); if (isEnterprise) { ShowViewModel <AddAccountViewModel>(new AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = githubAccount.Id }); } else { ShowViewModel <LoginViewModel>(LoginViewModel.NavObject.CreateDontRemember(githubAccount)); } } catch (Exception e) { ReportException(e); } finally { IsLoggingIn = false; } }
protected async override void Startup() { if (!_applicationService.Accounts.Any()) { ShowViewModel <Accounts.AccountsViewModel>(); ShowViewModel <Accounts.AddAccountViewModel>(); return; } var account = GetDefaultAccount() as BitbucketAccount; if (account == null) { ShowViewModel <Accounts.AccountsViewModel>(); return; } if (account.DontRemember) { ShowViewModel <Accounts.AccountsViewModel>(); ShowViewModel <Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject() { AttemptedAccountId = account.Id }); return; } //Lets login! try { IsLoggingIn = true; var client = await _loginService.LoginAccount(account); _applicationService.ActivateUser(account, client); } catch (Exception e) { DisplayAlert("Unable to login successfully: " + e.Message); ShowViewModel <Accounts.AccountsViewModel>(); ShowViewModel <Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject() { AttemptedAccountId = account.Id }); } finally { IsLoggingIn = false; } }
private async Task Login() { try { IsLoggingIn = true; var ret = await Task.Run(() => Client.GetAuthorizationCode(ClientId, ClientSecret, Code)); var data = await Task.Run(() => { UsersModel u; var c = Client.BearerLogin(ret.AccessToken, out u); return(Tuple.Create(c, u)); }); var bitbucketClient = data.Item1; var usersModel = data.Item2; var account = _accountsService.Find(usersModel.User.Username); if (account == null) { account = new BitbucketAccount { Username = usersModel.User.Username, AvatarUrl = usersModel.User.Avatar, RefreshToken = ret.RefreshToken, Token = ret.AccessToken }; _accountsService.Insert(account); } else { account.RefreshToken = ret.RefreshToken; account.Token = ret.AccessToken; account.AvatarUrl = usersModel.User.Avatar; _accountsService.Update(account); } _applicationService.ActivateUser(account, bitbucketClient); } finally { IsLoggingIn = false; } }
private async Task AttemptLogin(BitbucketAccount account) { Uri accountAvatarUri = null; var avatarUrl = account.AvatarUrl; if (!string.IsNullOrEmpty(avatarUrl)) { var match = Regex.Match(avatarUrl, @"&s=(\d+)", RegexOptions.IgnoreCase); if (match.Success && match.Groups.Count > 1) { avatarUrl = avatarUrl.Replace(match.Groups[0].Value, "&s=128"); } } if (Uri.TryCreate(avatarUrl, UriKind.Absolute, out accountAvatarUri)) { Avatar = new Avatar(accountAvatarUri.AbsoluteUri); } var client = await LoginAccount(account); _applicationService.ActivateUser(account, client); }
protected async override void Startup() { if (!_applicationService.Accounts.Any()) { ShowViewModel <Accounts.AccountsViewModel>(); ShowViewModel <Accounts.NewAccountViewModel>(); return; } var account = GetDefaultAccount() as GitHubAccount; if (account == null) { ShowViewModel <Accounts.AccountsViewModel>(); return; } var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password); if (account.DontRemember) { ShowViewModel <Accounts.AccountsViewModel>(); //Hack for now if (isEnterprise) { ShowViewModel <Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id }); } else { ShowViewModel <Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account)); } return; } //Lets login! try { IsLoggingIn = true; var client = await _loginFactory.LoginAccount(account); _applicationService.ActivateUser(account, client); } catch (GitHubSharp.UnauthorizedException e) { DisplayAlert("The credentials for the selected account are incorrect. " + e.Message); ShowViewModel <Accounts.AccountsViewModel>(); if (isEnterprise) { ShowViewModel <Accounts.AddAccountViewModel>(new Accounts.AddAccountViewModel.NavObject { IsEnterprise = true, AttemptedAccountId = account.Id }); } else { ShowViewModel <Accounts.LoginViewModel>(Accounts.LoginViewModel.NavObject.CreateDontRemember(account)); } } catch (Exception e) { ReportException(e); ShowViewModel <Accounts.AccountsViewModel>(); } finally { IsLoggingIn = false; } }
protected async Task Startup() { if (!_applicationService.Accounts.Any()) { GoToNewAccount.Execute(null); return; } var accounts = GetService <IAccountsService>(); var account = accounts.GetDefault(); if (account == null) { GoToAccounts.Execute(null); return; } var isEnterprise = account.IsEnterprise || !string.IsNullOrEmpty(account.Password); if (account.DontRemember) { GoToAccounts.Execute(null); return; } //Lets login! try { ImageUrl = null; Status = null; IsLoggingIn = true; Uri accountAvatarUri = null; Uri.TryCreate(account.AvatarUrl, UriKind.Absolute, out accountAvatarUri); ImageUrl = accountAvatarUri; Status = "Logging in as " + account.Username; var client = await _loginFactory.LoginAccount(account); _applicationService.ActivateUser(account, client); if (!isEnterprise) { StarOrWatch(); } GoToMenu.Execute(typeof(MenuViewModel)); } catch (GitHubSharp.UnauthorizedException e) { DisplayAlert("The credentials for the selected account are incorrect. " + e.Message); if (isEnterprise) { GoToUrlCommand.Execute(new AddAccountViewModel.NavObject { AttemptedAccountId = account.Id }); } else { GoToUrlCommand.Execute(LoginViewModel.NavObject.CreateDontRemember(account)); } StarOrWatch(); } catch (Exception e) { DisplayAlert(e.Message); GoToAccounts.Execute(null); } finally { IsLoggingIn = false; } }