Esempio n. 1
0
        public void Update(BitbucketAccount account)
        {
			lock (_userDatabase)
			{
				_userDatabase.Update(account);
			}
        }
Esempio n. 2
0
        public void Insert(BitbucketAccount account)
        {
			lock (_userDatabase)
			{
				_userDatabase.Insert(account);
			}
        }
Esempio n. 3
0
		public LoginData Authenticate(string user, string pass, BitbucketAccount account)
        {
            try
            {
                //Make some valid checks
                if (string.IsNullOrEmpty(user))
                    throw new ArgumentException("Username is invalid");
                if (string.IsNullOrEmpty(pass))
                    throw new ArgumentException("Password is invalid");

                //Does this user exist?
                bool exists = account != null;
                if (!exists)
					account = new BitbucketAccount { Username = user };

				var client = new Client(user, pass);
				account.Password = pass;
				var data = client.Account.GetInfo(true);
				var userInfo = data.User;
				account.Username = userInfo.Username;
				account.AvatarUrl = userInfo.Avatar;
				client.Username = userInfo.Username;

                if (exists)
                    _accounts.Update(account);
                else
                    _accounts.Insert(account);

				return new LoginData { Client = client, Account = account };
            }
            catch (StatusCodeException ex)
            {
                throw new Exception("Unable to login as user " + user + ". Please check your credentials and try again.");
            }
        }
Esempio n. 4
0
		public async Task<LoginData> LoginWithToken(string clientId, string clientSecret, string code, string redirect, string requestDomain, string apiDomain, BitbucketAccount account)
        {
//			var token = await Task.Run(() => Client.RequestAccessToken(clientId, clientSecret, code, redirect, requestDomain));
//			var client = Client.BasicOAuth(token.AccessToken, apiDomain);
//			var info = await client.ExecuteAsync(client.AuthenticatedUser.GetInfo());
//            var username = info.Data.Login;
//
//            //Does this user exist?
//            var exists = account != null;
//			if (!exists)
//                account = new GitHubAccount { Username = username };
//			account.OAuth = token.AccessToken;
//            account.AvatarUrl = info.Data.AvatarUrl;
//			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 };

			return null;
        }
Esempio n. 5
0
 public void SetDefault(BitbucketAccount account)
 {
     if (account == null)
         _defaults.Set("DEFAULT_ACCOUNT", null);
     else
         _defaults.Set("DEFAULT_ACCOUNT", account.Id);
 }
		public void ActivateUser(BitbucketAccount account, Client client)
        {
            Accounts.SetActiveAccount(account);
            Account = account;
            Client = client;
            _timer.Stop();
            _timer.Start();
        }
Esempio n. 7
0
        public void Init(NavObject navObject)
        {
			if (navObject.AttemptedAccountId >= 0)
				_attemptedAccount = this.GetApplication().Accounts.Find(navObject.AttemptedAccountId) as BitbucketAccount;

            if (_attemptedAccount != null)
            {
                Username = _attemptedAccount.Username;
            }
        }
Esempio n. 8
0
        public void SetActiveAccount(BitbucketAccount account)
        {
			if (account != null)
			{
				var accountDir = CreateAccountDirectory(account);
				if (!Directory.Exists(accountDir))
					Directory.CreateDirectory(accountDir);
			}

            SetDefault(account);
            ActiveAccount = account;
        }
Esempio n. 9
0
        public void Remove(BitbucketAccount account)
        {
			lock (_userDatabase)
			{
				_userDatabase.Delete(account);
			}
            var accountDir = CreateAccountDirectory(account);

            if (!Directory.Exists(accountDir))
                return;
            Directory.Delete(accountDir, true);
        }
Esempio n. 10
0
        /// <summary>
        /// Called when an account is deleted
        /// </summary>
        /// <param name="account">Account.</param>
        protected void AccountDeleted(BitbucketAccount account)
        {
            //Remove the designated username
            var thisAccount = account;
            var accountsService = Mvx.Resolve<IAccountsService>();

            accountsService.Remove(thisAccount);

            if (accountsService.ActiveAccount != null && accountsService.ActiveAccount.Equals(thisAccount))
            {
                accountsService.SetActiveAccount(null);
            }
        }
Esempio n. 11
0
		public async void Login(string code)
		{
			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);
                }

                this.GetApplication().ActivateUser(account, bitbucketClient);
                ShowViewModel<StartupViewModel>();
			}
			catch (Exception e)
			{
                DisplayAlert("Unable to login: " + e.Message);
			}
			finally
			{
				IsLoggingIn = false;
			}
		}
Esempio n. 12
0
		public void ActivateUser(BitbucketAccount account, Client client)
        {
            Accounts.SetActiveAccount(account);
            Account = account;
            Client = client;

			//Set the default account
			Accounts.SetDefault(account);

			//Check the cache size
			CheckCacheSize(account.Cache);

			//Client.Cache = new GitHubCache(account);

            // Show the menu & show a page on the slideout
            _viewDispatcher.ShowViewModel(new MvxViewModelRequest {ViewModelType = typeof (MenuViewModel)});
        }
Esempio n. 13
0
        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;
			}
		}
Esempio n. 14
0
		public async Task<Client> LoginAccount(BitbucketAccount 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);
//			}
//
			client = new Client(account.Username, account.Password);


			var data = await Task.Run(() => client.Account.GetInfo(true));
			var userInfo = data.User;
			account.Username = userInfo.Username;
			account.AvatarUrl = userInfo.Avatar;
			client.Username = userInfo.Username;
            _accounts.Update(account);
            return client;
        }
Esempio n. 15
0
 public AccountElement(BitbucketAccount account)
     : base(account.Username, string.Empty, string.Empty, new Avatar(account.AvatarUrl))
 {
     Account = account;
 }
Esempio n. 16
0
        public bool Exists(BitbucketAccount account)
        {
			return Find(account.Id) != null;
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 protected string CreateAccountDirectory(BitbucketAccount account)
 {
     return Path.Combine(_accountsPath, account.Id.ToString(CultureInfo.InvariantCulture));
 }
Esempio n. 19
0
 public async Task<Client> LoginAccount(BitbucketAccount account)
 {
     //Create the client
     UsersModel userInfo = null;
     var client = await Task.Run(() => Client.BearerLogin(account.Token, out userInfo));
     account.Username = userInfo.User.Username;
     account.AvatarUrl = userInfo.User.Avatar.Replace("/avatar/32", "/avatar/64");
     _accountsService.Update(account);
     return client;
 }
Esempio n. 20
0
 private void SelectAccount(BitbucketAccount account)
 {
     _accountsService.SetActiveAccount(account);
     ShowViewModel<CodeBucket.Core.ViewModels.App.StartupViewModel>();
 }
Esempio n. 21
0
			public static NavObject CreateDontRemember(BitbucketAccount account)
			{
				return new NavObject
				{ 
					Username = account.Username,
					AttemptedAccountId = account.Id
				};
			}