Ejemplo n.º 1
0
        public void SaveLoginDetails(UserDto user, UserWidgetDataDetails userData, GeminiContext gemini)
        {
            UserWidgetData <List <UserWidgetDataDetails> > userDataRaw = gemini.UserWidgetStore.Get <List <UserWidgetDataDetails> >(user.Entity.Id, Constants.AppId, Constants.ControlId);

            if (userDataRaw == null)
            {
                var data = new UserWidgetData <List <UserWidgetDataDetails> >();

                data.Value = new List <UserWidgetDataDetails>();

                data.Value.Add(userData);

                gemini.UserWidgetStore.Save(user.Entity.Id, Constants.AppId, Constants.ControlId, data.Value);
            }
            else
            {
                /**
                 * We need to make sure there are NO github Authentication records with an empty access token otherwise when we receive the access_token back from them we will not be able to associate that request to the right
                 * Repository with an empty access token
                 * check if there is already an entry for github with empty access token, if yes then delete it
                 */
                var incompleteAuthentication = userDataRaw.Value.Find(f => f.Provider == userData.Provider && f.AccessToken.IsEmpty());

                if (incompleteAuthentication != null)
                {
                    //var index = userDataRaw.Value.FindIndex(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider && f.AccessToken.IsEmpty());
                    DeleteLoginDetails(user, incompleteAuthentication, gemini);

                    userDataRaw = gemini.UserWidgetStore.Get <List <UserWidgetDataDetails> >(user.Entity.Id, Constants.AppId, Constants.ControlId);
                }

                var tmpUser = userDataRaw.Value.Find(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                // If a password for this rep already exist, update the details only
                if (tmpUser != null)
                {
                    var index = userDataRaw.Value.FindIndex(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                    userDataRaw.Value[index].Username = userData.Username;

                    userDataRaw.Value[index].Password = userData.Password;

                    userDataRaw.Value[index].AccessToken = userData.AccessToken;
                }
                else
                {
                    // Add a new user authentication for this user
                    userDataRaw.Value.Add(userData);
                }

                gemini.UserWidgetStore.Save(user.Entity.Id, Constants.AppId, Constants.ControlId, userDataRaw.Value);
            }
        }
Ejemplo n.º 2
0
        public void DeleteLoginDetails(UserDto user, UserWidgetDataDetails userData, GeminiContext gemini)
        {
            UserWidgetData <List <UserWidgetDataDetails> > userDataRaw = gemini.UserWidgetStore.Get <List <UserWidgetDataDetails> >(user.Entity.Id, Constants.AppId, Constants.ControlId);

            if (userDataRaw != null)
            {
                var tmpUser = userDataRaw.Value.FindAll(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                // If a password for this rep already exist, update the details only
                if (tmpUser != null)
                {
                    var index = userDataRaw.Value.FindIndex(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                    userDataRaw.Value.RemoveAt(index);
                }

                gemini.UserWidgetStore.Save(user.Entity.Id, Constants.AppId, Constants.ControlId, userDataRaw.Value);
            }
        }
Ejemplo n.º 3
0
        public void SaveLoginDetails(UserDto user, UserWidgetDataDetails userData, GeminiContext gemini)
        {
            UserWidgetData <List <UserWidgetDataDetails> > userDataRaw = gemini.UserWidgetStore.Get <List <UserWidgetDataDetails> >(user.Entity.Id, Constants.AppId, Constants.ControlId);

            if (userDataRaw == null)
            {
                var data = new UserWidgetData <List <UserWidgetDataDetails> >();

                data.Value = new List <UserWidgetDataDetails>();

                data.Value.Add(userData);

                gemini.UserWidgetStore.Save(user.Entity.Id, Constants.AppId, Constants.ControlId, data.Value);
            }
            else
            {
                var tmpUser = userDataRaw.Value.Find(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                // If a password for this rep already exist, update the details only
                if (tmpUser != null)
                {
                    var index = userDataRaw.Value.FindIndex(f => f.RepositoryUrl == userData.RepositoryUrl && f.Provider == userData.Provider);

                    userDataRaw.Value[index].Password = userData.Password;

                    userDataRaw.Value[index].Username = userData.Username;
                }
                else
                {
                    // Add a new user authentication for this user
                    userDataRaw.Value.Add(userData);
                }

                gemini.UserWidgetStore.Save(user.Entity.Id, Constants.AppId, Constants.ControlId, userDataRaw.Value);
            }
        }
Ejemplo n.º 4
0
        public ActionResult Authenticate(SourceControlProvider provider)
        {
            //Authentication
            string username = Request["username"] ?? string.Empty;

            string password = Request["password"] ?? string.Empty;

            string repositoryUrl = Request["repositoryurl"] ?? string.Empty;

            string filename = Request["filename"] ?? string.Empty;

            string message = string.Empty; //Commit message

            bool success = true;

            string extraData = string.Empty;

            if (username.IsEmpty() || password.IsEmpty() || provider.ToString().IsEmpty() || repositoryUrl.IsEmpty())
            {
                message = "Please make sure Username, Password are not empty";

                success = false;
            }

            if (success)
            {
                UserWidgetDataDetails userData = new UserWidgetDataDetails();

                userData.Username = username.Trim();

                userData.Password = SecretsHelper.Encrypt(password.Trim(), SecretsHelper.EncryptionKey);

                userData.Provider = provider;

                userData.RepositoryUrl = repositoryUrl.Trim();

                userData.AccessToken = string.Empty;

                if (provider == SourceControlProvider.SVN)
                {
                    SVN svn = new SVN();

                    svn.SaveLoginDetails(CurrentUser, userData, GeminiContext);
                }
                else if (provider == SourceControlProvider.GitHub)
                {
                    GitHub github = new GitHub();

                    github.SaveLoginDetails(CurrentUser, userData, GeminiContext);

                    extraData = string.Format("https://github.com/login/oauth/authorize?client_id={0}&redirect_uri={1}apps/saucery/github/authenticate?state={2}&scope=repo", username, UserContext.Url, CurrentUser.Entity.Id);
                }
                else if (provider == SourceControlProvider.TFS2012)
                {
                    TFS2012 tfs2012 = new TFS2012();

                    tfs2012.SaveLoginDetails(CurrentUser, userData, GeminiContext);
                }
                else if (provider == SourceControlProvider.TFS2010)
                {
                    TFS2010 tfs2010 = new TFS2010();

                    tfs2010.SaveLoginDetails(CurrentUser, userData, GeminiContext);
                }
                else if (provider == SourceControlProvider.Git)
                {
                    Git git = new Git();
                    git.SaveLoginDetails(CurrentUser, userData, GeminiContext);
                }
                else if (provider == SourceControlProvider.Bitbucket)
                {
                    Bitbucket bitbucket = new Bitbucket();
                    bitbucket.SaveLoginDetails(CurrentUser, userData, GeminiContext);
                }
            }

            return(JsonSuccess(new { success = success, message = message, extraData = extraData }));
        }