public void ActivateUser(GitHubAccount account, Client client) { Accounts.SetActiveAccount(account); Account = account; Client = client; //Set the default account Accounts.SetDefault(account); //Check the cache size CheckCacheSize(account.Cache); //Assign the cache Client.Cache = new GitHubCache(account); // Show the menu & show a page on the slideout _viewDispatcher.ShowViewModel(new MvxViewModelRequest { ViewModelType = typeof(MenuViewModel) }); // A user has been activated! if (_activationAction != null) { _activationAction(); _activationAction = null; } //Activate push notifications PromptForPushNotifications(); }
public static void LoginWithToken(string accessToken) { var client = GitHubSharp.Client.BasicOAuth(accessToken); var info = client.Execute(client.AuthenticatedUser.GetInfo()); var username = info.Data.Login; GitHubAccount account; bool exists; //Does this user exist? account = Application.Accounts.Find(username); exists = account != null; if (!exists) { account = new GitHubAccount { Username = username } } ; account.OAuth = accessToken; account.AvatarUrl = info.Data.AvatarUrl; if (exists) { Application.Accounts.Update(account); } else { Application.Accounts.Insert(account); } Application.SetUser(account, client); new MonoTouch.Foundation.NSObject().InvokeOnMainThread(TransitionToSlideout); }
public async Task <Client> LoginAccount(GitHubAccount account) { //Create the client Client client = null; if (!string.IsNullOrEmpty(account.OAuth)) { client = Client.BasicOAuth(account.OAuth, account.Domain ?? Client.DefaultApi); } else if (account.IsEnterprise || !string.IsNullOrEmpty(account.Password)) { client = Client.Basic(account.Username, account.Password, account.Domain ?? Client.DefaultApi); } var data = await client.ExecuteAsync(client.AuthenticatedUser.GetInfo()); var userInfo = data.Data; account.Username = userInfo.Login; account.Name = userInfo.Name; account.Email = userInfo.Email; account.AvatarUrl = userInfo.AvatarUrl; client.Username = userInfo.Login; _accounts.Update(account); return(client); }
private void SelectAccount(GitHubAccount githubAccount) { var isEnterprise = githubAccount.IsEnterprise || !string.IsNullOrEmpty(githubAccount.Password); if (githubAccount.DontRemember) { //Hack for now if (isEnterprise) { var vc = new AddAccountViewController(); vc.ViewModel.Init(new AddAccountViewModel.NavObject { AttemptedAccountId = githubAccount.Id }); NavigationController.PushViewController(vc, true); } else { var loginViewController = new LoginViewController(); loginViewController.ViewModel.Init(LoginViewModel.NavObject.CreateDontRemember(githubAccount)); NavigationController.PushViewController(loginViewController, true); } return; } _accountsService.SetDefault(githubAccount); MessageBus.Current.SendMessage(new LogoutMessage()); }
private void SelectAccount(GitHubAccount githubAccount) { var isEnterprise = githubAccount.IsEnterprise || !string.IsNullOrEmpty(githubAccount.Password); _applicationService.ActivateUser(githubAccount, null); MessageBus.Current.SendMessage(new LogoutMessage()); }
private async Task <GitHubUser> SetUser(string userName, GitHubClient gitHubClient) { GitHubUser gitHubUser; if (await IsUserExist(gitHubClient, userName)) { User user = await GetUserData(gitHubClient, userName); IEnumerable <Repository> allRepositories = await GetRepositoriesData(gitHubClient, userName); IEnumerable <Repository> selectedRepositories = GetRepositoriesWithLimit(allRepositories, 5); GitHubAccount account = new GitHubAccount() { Repository = selectedRepositories, User = user }; gitHubUser = GetGitHubUser(account); } else { gitHubUser = AnonymusUser(); } return(gitHubUser); }
public void Insert(GitHubAccount account) { lock (_userDatabase) { _userDatabase.Insert(account); } }
public async Task Deregister(GitHubAccount account) { var del = (AppDelegate)UIApplication.SharedApplication.Delegate; if (string.IsNullOrEmpty(del.DeviceToken)) { throw new InvalidOperationException("Push notifications has not been enabled for this app!"); } if (account.IsEnterprise) { throw new InvalidOperationException("Push notifications are for GitHub.com accounts only!"); } var client = new HttpClient(); var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("token", del.DeviceToken), new KeyValuePair <string, string>("oauth", account.OAuth), new KeyValuePair <string, string>("domain", "https://api.github.com") }); client.Timeout = new TimeSpan(0, 0, 30); var response = await client.PostAsync(DeregisterUri, content); if (response.StatusCode != System.Net.HttpStatusCode.NotFound && response.StatusCode != System.Net.HttpStatusCode.OK) { throw new InvalidOperationException("Unable to deregister! Server returned a " + response.StatusCode + " status code"); } System.Diagnostics.Debug.WriteLine("Push notifications deregistered for: " + account.Username + " (" + account.OAuth + ") on device <" + del.DeviceToken + ">"); }
public void Update(GitHubAccount account) { lock (_userDatabase) { _userDatabase.Update(account); } }
public void CanGetGitHubUserForExistingUser() { int expectedResultRepositoryItems = 4; User user = new User(avatarUrl: "/Content/img/UserNotExist.jpg", name: "Heniu", blog: "", collaborators: 0, email: "", createdAt: DateTime.Now, diskUsage: 0, bio: "", company: "", followers: 0, following: 0, hireable: null, htmlUrl: "", id: 0, ldapDistinguishedName: "", location: "Warszaw", login: "", url: "", ownedPrivateRepos: 0, permissions: null, plan: null, privateGists: 0, publicGists: 0, publicRepos: 0, siteAdmin: false, suspendedAt: null, totalPrivateRepos: 0); List <Repository> repositoryList = new List <Repository>(); for (int i = 0; i < expectedResultRepositoryItems; i++) { repositoryList.Add(new Repository(url: "", gitUrl: "", allowMergeCommit: false, fork: false, forksCount: 0, fullName: "", hasDownloads: false, hasIssues: false, allowRebaseMerge: false, cloneUrl: "", createdAt: DateTime.Now, defaultBranch: "", hasWiki: false, allowSquashMerge: false, description: "", hasPages: false, homepage: "", htmlUrl: "", id: 0, language: "", mirrorUrl: "", name: "", openIssuesCount: 0, owner: null, parent: null, permissions: null, @private: false, pushedAt: DateTime.Now, size: 0, source: null, sshUrl: "", stargazersCount: 0, subscribersCount: 0, svnUrl: "", updatedAt: DateTime.Now)); } GitHubAccount gitHubAccount = new GitHubAccount() { Repository = repositoryList, User = user }; PrivateObject privateObjectGetGitHubUser = new PrivateObject(_gitHub); GitHubUser gitHubUser = (GitHubUser)privateObjectGetGitHubUser.Invoke("GetGitHubUser", gitHubAccount); CheckGitHubUser(new GitHubUserExpectedResults { Name = "Heniu", Location = "Warszaw", AvataruUrl = "/Content/img/UserNotExist.jpg", RepositoryCount = expectedResultRepositoryItems }, gitHubUser); }
private AccountItemViewModel CreateAccountItem(GitHubAccount githubAccount) { var viewModel = new AccountItemViewModel(githubAccount); viewModel.Selected = Equals(githubAccount, ActiveAccount); viewModel.DeleteCommand.Subscribe(_ => DeleteAccount(githubAccount)); viewModel.GoToCommand.Subscribe(_ => LoginAccount(githubAccount)); return(viewModel); }
public void ActivateUser(GitHubAccount account, Client client) { Accounts.SetActiveAccount(account); Account = account; Client = client; //Set the default account Accounts.SetDefault(account); }
private async Task DeleteAccount(GitHubAccount account) { if (Equals(_sessionService.Account, account)) { ActiveAccount = null; } _accounts.Remove(account); await _accountsRepository.Remove(account); }
public static NavObject CreateDontRemember(GitHubAccount account) { return(new NavObject { WebDomain = account.WebDomain, Username = account.Username, AttemptedAccountId = account.Id }); }
public WebLoginViewController(GitHubAccount attemptedAccount) : base(false) { Title = "Login"; _attemptedAccount = attemptedAccount; LoadRequest(); }
private AccountItemViewModel CreateAccountItem(GitHubAccount githubAccount) { var viewModel = new AccountItemViewModel(); viewModel.Account = githubAccount; viewModel.Selected = Equals(githubAccount, ActiveAccount); viewModel.DeleteCommand.Subscribe(_ => DeleteAccountCommand.ExecuteIfCan(githubAccount)); viewModel.SelectCommand.Subscribe(_ => LoginCommand.ExecuteIfCan(githubAccount)); return(viewModel); }
internal AccountItemViewModel(GitHubAccount account) { DeleteCommand = ReactiveCommand.Create(); GoToCommand = ReactiveCommand.Create(); Id = account.Key; Username = account.Username; AvatarUrl = account.AvatarUrl; Domain = account.WebDomain ?? "https://api.github.com"; }
public static NavObject CreateDontRemember(GitHubAccount account) { return(new NavObject { WebDomain = account.WebDomain, IsEnterprise = !string.Equals(account.Domain, GitHubSharp.Client.DefaultApi), Username = account.Username, AttemptedAccountId = account.Id }); }
public void SetDefault(GitHubAccount account) { if (account == null) { _defaults.Clear("DEFAULT_ACCOUNT"); } else { _defaults.Set("DEFAULT_ACCOUNT", account.Id); } }
private async Task LoginAccount(GitHubAccount account) { if (!Equals(_sessionService.Account, account)) { ActiveAccount = account; await _accountsRepository.SetDefault(account); MessageBus.Current.SendMessage(new LogoutMessage()); } Dismiss(); }
private void ShowAccountsAndSelectedUser(GitHubAccount account) { var accountsController = new AccountsViewController(); accountsController.NavigationItem.LeftBarButtonItem = null; var login = new LoginViewController(account); var navigationController = new CustomNavigationController(this, accountsController); navigationController.PushViewController(login, false); Transitions.TransitionToController(navigationController); }
public void SetActiveAccount(GitHubAccount account) { if (account != null) { var accountDir = CreateAccountDirectory(account); if (!Directory.Exists(accountDir)) { Directory.CreateDirectory(accountDir); } } ActiveAccount = account; }
private GitHubUser GetGitHubUser(GitHubAccount account) { return(new GitHubUser() { Name = account.User.Name ?? "None", Location = account.User.Location ?? "None", AvataruUrl = account.User.AvatarUrl ?? "None", Repository = account.Repository.Select(x => new GitHubRepository() { Name = x.Name ?? "None", Language = x.Language ?? "None", StargazerCount = x.StargazersCount }).ToList() }); }
public void Init(NavObject navObject) { if (navObject.AttemptedAccountId >= 0) { _attemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId); } if (_attemptedAccount != null) { Username = _attemptedAccount.Username; Domain = _attemptedAccount.Domain; } }
public void Remove(GitHubAccount account) { lock (_userDatabase) { _userDatabase.Delete(account); } var accountDir = CreateAccountDirectory(account); if (!Directory.Exists(accountDir)) { return; } Directory.Delete(accountDir, true); }
public void CanGetGitHubUserForNotExistingUser() { int expectedRepositoryItems = 0; User user = new User(); List <Repository> repositoryList = new List <Repository>(); GitHubAccount gitHubAccount = new GitHubAccount() { Repository = repositoryList, User = user }; PrivateObject privateObjectGetGitHubUser = new PrivateObject(_gitHub); GitHubUser gitHubUser = (GitHubUser)privateObjectGetGitHubUser.Invoke("GetGitHubUser", gitHubAccount); CheckGitHubUser(new GitHubUserExpectedResults { Name = "None", Location = "None", AvataruUrl = "None", RepositoryCount = expectedRepositoryItems }, gitHubUser); }
public async Task SetSessionAccount(GitHubAccount account) { if (account == null) { Account = null; Client = null; GitHubClient = null; return; } try { var domain = account.Domain ?? Client.DefaultApi; var credentials = new Credentials(account.OAuth); var oldClient = Client.BasicOAuth(account.OAuth, domain); var newClient = OctokitClientFactory.Create(new Uri(domain), credentials); var userInfo = await newClient.User.Current(); account.Name = userInfo.Name; account.Email = userInfo.Email; account.AvatarUrl = userInfo.AvatarUrl; await _accountsRepository.Update(account); // Set all the good stuff. Client = oldClient; GitHubClient = newClient; Account = account; // Identify for the analytics service _analyticsService.Identify(Account.Username); _analyticsService.Track("login"); } catch { Account = null; GitHubClient = null; Client = null; throw; } }
public void Init(NavObject navObject) { if (navObject.AttemptedAccountId >= 0) { _attemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId) as GitHubAccount; } if (_attemptedAccount != null) { Username = _attemptedAccount.Username; IsEnterprise = _attemptedAccount.Domain != null; if (IsEnterprise) { Domain = _attemptedAccount.Domain; } } else { IsEnterprise = navObject.IsEnterprise; } }
public async Task <LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, GitHubAccount account) { var token = await Client.RequestAccessToken(clientId, clientSecret, code, redirect, requestDomain); var client = Client.BasicOAuth(token.AccessToken, apiDomain); var info = (await client.ExecuteAsync(client.AuthenticatedUser.GetInfo())).Data; var username = info.Login; //Does this user exist? var exists = account != null; if (!exists) { account = new GitHubAccount { Username = username } } ; account.OAuth = token.AccessToken; account.AvatarUrl = info.AvatarUrl; account.Name = info.Name; account.Email = info.Email; account.Domain = apiDomain; account.WebDomain = requestDomain; client.Username = username; if (exists) { _accounts.Update(account); } else { _accounts.Insert(account); } return(new LoginData { Client = client, Account = account }); }
public static void SetUser(GitHubAccount account, GitHubSharp.Client client) { if (account == null) { Account = null; Client = null; Accounts.SetDefault(null); return; } Accounts.SetActiveAccount(account); Accounts.SetDefault(account); //Assign the client Client = client; Client.Timeout = 1000 * 30; CheckCacheSize(account.Cache); //Set the cache ClientCache = account.Cache; Client.Cache = new GitHubCache(account.Cache); }