Пример #1
0
        /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException"></exception>
        private void CheckParameters()
        {
            RepositoryState s = repo.GetRepositoryState();

            if (this.operation != RebaseCommand.Operation.BEGIN)
            {
                // these operations are only possible while in a rebasing state
                if (repo.GetRepositoryState() != RepositoryState.REBASING_INTERACTIVE)
                {
                    throw new WrongRepositoryStateException(MessageFormat.Format(JGitText.Get().wrongRepositoryState
                                                                                 , repo.GetRepositoryState().Name()));
                }
            }
            else
            {
                if (s == RepositoryState.SAFE)
                {
                    if (this.upstreamCommit == null)
                    {
                        throw new JGitInternalException(MessageFormat.Format(JGitText.Get().missingRequiredParameter
                                                                             , "upstream"));
                    }
                    return;
                }
                else
                {
                    throw new WrongRepositoryStateException(MessageFormat.Format(JGitText.Get().wrongRepositoryState
                                                                                 , repo.GetRepositoryState().Name()));
                }
            }
        }
        public async Task <bool> RestorePasswor(RestorePasswordModel model)
        {
            if (!model.IsCompare())
            {
                return(false);
            }

            var user = await GetByUserName(model.UserName);//GetFirst(m => m.UserName == model.UserName);

            if (user == null)
            {
                throw new CoreException("User Not Valid", 5);
            }
            if (!string.IsNullOrEmpty(model.Token))
            {
            }
            if (CheckUserOtp(user, model.Otp))
            {
                user.Password = RepositoryState.GetHashString(model.Password);
            }
            else
            {
                //4 Restore Password
                throw new CoreException("Error Otp", 4);
            }
            await Update(user);

            return(true);
        }
Пример #3
0
        public async Task <RegisterResult> RegisterAsync(RegisterUser model)
        {
            RegisterResult result = new RegisterResult();

            if (AuthOptions.SetNameAsPhone)
            {
                model.UserName = RepositoryState.ParsePhone(model.UserName);
            }
            var user = _dbSet.FirstOrDefault(m => m.UserName == model.UserName || m.Email == model.UserName);

            if (user != null)
            {
                throw new CoreException("User Name or Password not Found", 7);
                return(result);
            }
            user = AddRegister(model);
            if (AuthOptions.SetNameAsPhone)
            {
                model.UserName = RepositoryState.ParsePhone(model.UserName);
                if (string.IsNullOrEmpty(model.UserName))
                {
                    throw new CoreException("UserName is Not Valid", 6);
                }
                user.PhoneNumber = model.UserName;
            }
            //_dbSet.Add(user);
            Add(user);
            result.IsRegister = true;
            result.Name       = user.UserName;
            return(result);
        }
Пример #4
0
        public async Task <ResponseData> SendOtp(string phoneNumber, string orginator = "3700")
        {
            try
            {
                var partner = this.GetProject(_project, DefaultRest);
                var message = SendModal.Create(partner);
                partner.RunConfig(_confList, message);
                message.Messages.Add(new Message()
                {
                    Recipient = RepositoryState.ParsePhone(phoneNumber), MessageId = "123456", Sms = new Sms()
                    {
                        Originator = orginator, Content = new Entity.Sms.Content()
                    }
                });
                RestViewModal viewModal = new RestViewModal()
                {
                    Header = Request.Headers.ToDict()
                };
                var result = await _message.SendOtp(partner, message, viewModal);

                return(this.GetResponse(result));
            }
            catch (Exception ext)
            {
                return(this.GetResponse());
            }
        }
Пример #5
0
        public virtual async Task <NetResult <LoginResult> > Login([FromBody] LoginViewModal model)
        {
            try
            {
                var result = await _user.Login(model);

                if (result.Item1 != null)
                {
                    return(result.Item1);
                }
                if (result.Item2 != null || result.Item2.ShouldSendOtp)
                {
                    var otp = RepositoryState.RandomInt();
                    _user.SetOtp(result.Item2, otp);
                    SenNotify(result.Item2, otp);
                    return(new LoginResult()
                    {
                        UserName = result.Item2.UserName,
                        UserId = result.Item2.Id.ToString(),
                        IsSentOtp = true,
                    });
                }
                return(null);
            }
            catch (Exception ext)
            {
                return(ext);
            }
        }
Пример #6
0
        public virtual async Task <NetResult <SuccessResult> > IsRegister(string userName)
        {
            SuccessResult result = new SuccessResult();

            try
            {
                if (AuthModalOption.SetNameAsPhone && !userName.Contains("@"))
                {
                    userName = RepositoryState.ParsePhone(userName);
                }
                var user = _user.GetFirst(m => m.UserName == userName || m.Email == userName);
                if (user == null)
                {
                    result.Success = false;
                }
                else
                {
                    result.Success = true;
                }
                return(result);
            }
            catch (Exception ext)
            {
                result.Success = false;
                //return ext;
            }
            return(result);
        }
        public void WithFullBranchState_BranchesInheritParentFiles()
        {
            var f1 = new FileInfo("file1").WithBranch("branch", "1.1.0.2");
            var f2 = new FileInfo("file2").WithBranch("branch", "1.1.0.2");
            var f3 = new FileInfo("file3").WithBranch("branch", "1.2.0.2");

            var mainCommit1  = new Commit("c1").WithRevision(f1, "1.1").WithRevision(f2, "1.1").WithRevision(f3, "1.1");
            var mainCommit2  = new Commit("c2").WithRevision(f3, "1.2");
            var branchCommit = new Commit("c3").WithRevision(f1, "1.1.2.1");

            mainCommit2.AddBranch(branchCommit);
            var commits = new[] { mainCommit1, mainCommit2, branchCommit };

            var state = RepositoryState.CreateWithFullBranchState(commits.CreateAllFiles());

            foreach (var c in commits)
            {
                state.Apply(c);
            }

            var liveFiles = state["branch"].LiveFiles.OrderBy(i => i);

            Assert.IsTrue(liveFiles.SequenceEqual("file1", "file2", "file3"));
            Assert.AreEqual(state["branch"]["file1"].ToString(), "1.1.2.1");
            Assert.AreEqual(state["branch"]["file2"].ToString(), "1.1");
            Assert.AreEqual(state["branch"]["file3"].ToString(), "1.2");
        }
        public virtual async Task <(LoginResult, TUser)> Login(LoginViewModal model)
        {
            if (AuthOptions.SetNameAsPhone)
            {
                model.UserName = RepositoryState.ParsePhone(model.UserName);
            }
            var user = _dbSet.Where(m => (m.UserName == model.UserName || m.Email == model.UserName) && m.Password == RepositoryState.GetHashString(model.Password)).FirstOrDefault();

            if (user == null)
            {
                throw new CoreException("User Name or Password not Found", 7);
            }

            if (AuthOptions.CheckDeviceId)
            {
                if (user.CheckDevice(model.DeviceId))
                {
                    user.ChangeLastIncome(model.DeviceId);
                    return(Login(user), user);
                }
                user.ShouldSendOtp = true;
                //TODO
                return(null, user);
            }
            return(Login(user), user);
        }
Пример #9
0
        public async Task <ActionResult> Report(string repoUrl)
        {
            try {
                RepoParserAPI.EnsureIsRunning();

                string[] parts = repoUrl.Split("/");
                if (parts.Length < 2)
                {
                    return(BadRequest("Wrong repository identifier. Value must be in the form: '{repositoryOwner}/{repositoryName}'."));
                }

                string repoOwner = parts[0];
                string repoName  = parts[1];
                string baseUrl   = "https://app.powerbi.com/reportEmbed?reportId=f24e2ae2-f708-43c0-8923-ae68091c7e9f&autoAuth=true&ctid=82c51a82-548d-43ca-bcf9-bf4b7eb1d012&config=eyJjbHVzdGVyVXJsIjoiaHR0cHM6Ly93YWJpLW5vcnRoLWV1cm9wZS1yZWRpcmVjdC5hbmFseXNpcy53aW5kb3dzLm5ldC8ifQ%3D%3D";

                using (SqlConnection connection = new SqlConnection(m_config.Value.DbConnectionString))
                {
                    connection.Open();

                    RepositoryState repo = DbStatements.GetRepository(connection, $"{repoOwner}/{repoName}");
                    switch (repo.ParseStatus)
                    {
                    case PARSE_STATUS_DONE:
                    {
                        string iframeUrl = $"{baseUrl}&$filter=Languages/RepoId%20eq%20%27{repo.Id}%27%20and%20Contributors/RepoId%20eq%20%27{repo.Id}%27";
                        // TODO: Check date time when repository was processed - restart if expired

                        return(Ok(iframeUrl));
                    }

                    case PARSE_STATUS_QUEUED:
                    case PARSE_STATUS_PARSING:
                        return(Accepted());

                    case PARSE_STATUS_FAILED:
                        return(Forbid());    // TODO: Handle repos that failed to parse

                    case PARSE_STATUS_NONE:
                    {
                        repo.Id          = Guid.NewGuid().ToString();
                        repo.Url         = $"{repoOwner}/{repoName}";
                        repo.ParseStatus = PARSE_STATUS_QUEUED;

                        DbStatements.InsertRepository(connection, repo);
                        RepoParserAPI.ProcessRepository(m_config.Value.StorageConnectionString, repo.Id, repoOwner, repoName);

                        return(Accepted());
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Пример #10
0
 private static T ConvertResult <T>(ResponseData result)
 {
     if (typeof(ResponseData).GUID == typeof(T).GUID)
     {
         return((T)Convert.ChangeType(result, typeof(T)));
     }
     return((T)RepositoryState.CreateObject <T>());
 }
Пример #11
0
        /// <summary>
        /// Closes the current repository.
        /// </summary>
        /// <seealso cref="OpenRepository" />
        /// <seealso cref="State" />
        /// <remarks>
        /// This operation will only have an effect if the current <see cref="State" /> is either <see cref="RepositoryState.Opened" /> or <see cref="RepositoryState.Faulted" />.
        /// An error will not be thrown if the current state is <see cref="RepositoryState.Closed" />.
        /// </remarks>
        public void CloseRepository()
        {
            if (_currentRepository != null)
            {
                _currentRepository.Dispose();
            }

            _state = RepositoryState.Closed;
        }
Пример #12
0
        public virtual async Task <(LoginResult, TUser)> Login(string username, string password)
        {
            var user = _dbSet.Where(m => m.UserName == username && m.Password == RepositoryState.GetHashString(password)).FirstOrDefault();

            if (user == null)
            {
            }
            return(Login(user), user);
        }
Пример #13
0
        private void UpdateState()
        {
            var state = GetState();

            if (_state != state)
            {
                _state = state;
                StateChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Пример #14
0
        internal void OnStateChanged()
        {
            var state = GetState();

            if (_state != state)
            {
                _state = state;
                StateChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Пример #15
0
 private static T ConvertValue <T>(string value)
 {
     if (typeof(ResponseData).GUID == typeof(T).GUID)
     {
         return((T)Convert.ChangeType(new ResponseData {
             Message = value
         }, typeof(T)));
     }
     return((T)RepositoryState.CreateObject <T>());
 }
        /// <summary>
        /// Set Refresh token for user
        /// </summary>
        /// <param name="user"></param>
        public void SetRefresh(TUser user)
        {
            var refresh = "";
            var random  = new Random();

            for (var i = 0; i < 10; i++)
            {
                refresh += random.Next(15);
            }
            user.RefreshToken = RepositoryState.GetHashString(refresh);
        }
Пример #17
0
 public PRRepositoryInfo(string name, string description, RepositoryState state, string?id = null, DateTime?latestActivity = null, DateTime?proxyPushNotification = null, string?initProgress = null, string?readmeName = null, RepositoryActivity?monthlyActivity = null)
 {
     Id                    = id;
     Name                  = name;
     Description           = description;
     LatestActivity        = latestActivity;
     ProxyPushNotification = proxyPushNotification;
     State                 = state;
     InitProgress          = initProgress;
     ReadmeName            = readmeName;
     MonthlyActivity       = monthlyActivity;
 }
Пример #18
0
        private void UpdateState()
        {
            var state = GetState();

            if (_state != state)
            {
                _state = state;
                var handler = StateChanged;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            }
        }
Пример #19
0
        /// <summary>
        /// Gets or creates the UI state for a repository.
        /// </summary>
        /// <param name="repositoryUrl">The URL of the repository.</param>
        /// <returns>A <see cref="RepositoryUIState"/> object.</returns>
        public RepositoryUIState GetOrCreateRepositoryState(string repositoryUrl)
        {
            var result = RepositoryState.FirstOrDefault(x => x.RepositoryUrl == repositoryUrl);

            if (result == null)
            {
                result = new RepositoryUIState {
                    RepositoryUrl = repositoryUrl
                };
                RepositoryState.Add(result);
            }

            return(result);
        }
Пример #20
0
        internal void OnStateChanged()
        {
            var state = GetState();

            if (_state != state)
            {
                _state = state;
                var handler = StateChanged;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
            }
        }
        public virtual async Task <TUser> GetByUserName(string userName)
        {
            TUser user = null;

            if (AuthOptions.SetNameAsPhone)
            {
                user = _dbSet.FirstOrDefault(m => m.UserName == RepositoryState.ParsePhone(userName));
            }
            else
            {
                user = _dbSet.FirstOrDefault(m => m.UserName == userName);
            }
            return(user);
            //return _dbSet.FirstOrDefault(m => m.UserName == userName);
        }
        public async Task <bool> ChangePassword(TUser user, ChangePasswordModel model)
        {
            if (!model.IsCompare())
            {
                throw new CoreException("Compare password is not valid", 3);
            }
            if (user.Password != RepositoryState.GetHashString(model.OldPassword))
            {
                throw new CoreException(" Passwor is not valid", 2);
            }
            user.Password = RepositoryState.GetHashString(model.Password);
            await Update(user);

            return(true);
        }
Пример #23
0
        public virtual async Task <bool> RegisterAsync(TUser model)
        {
            var user = await
                       _dbSet.FirstOrDefaultAsync(m => m.UserName == model.UserName &&
                                                  m.Password == RepositoryState.GetHashString(model.Password));

            if (user != null)
            {
                return(false);
            }
            model.Password = RepositoryState.GetHashString(model.Password);
            _dbSet.Add(model);
            _context.SaveChanges();
            return(true);
        }
Пример #24
0
 /// <summary>Sets default values for not explicitly specified options.</summary>
 /// <remarks>
 /// Sets default values for not explicitly specified options. Then validates
 /// that all required data has been provided.
 /// </remarks>
 /// <param name="state">the state of the repository we are working on</param>
 /// <exception cref="NGit.Api.Errors.InvalidTagNameException">if the tag name is null or invalid
 ///     </exception>
 /// <exception cref="System.NotSupportedException">if the tag is signed (not supported yet)
 ///     </exception>
 private void ProcessOptions(RepositoryState state)
 {
     if (tagger == null)
     {
         tagger = new PersonIdent(repo);
     }
     if (name == null || !Repository.IsValidRefName(Constants.R_TAGS + name))
     {
         throw new InvalidTagNameException(MessageFormat.Format(JGitText.Get().tagNameInvalid
                                                                , name == null ? "<null>" : name));
     }
     if (signed)
     {
         throw new NotSupportedException(JGitText.Get().signingNotSupportedOnTag);
     }
 }
        public void WithFullBranchState_FileAddedOnBranch()
        {
            var f1 = new FileInfo("file1").WithBranch("branch", "1.1.0.2");
            var f2 = new FileInfo("file2").WithBranch("branch", "1.1.0.2");

            var mainCommit = new Commit("c1").WithRevision(f1, "1.1");
            var commits    = new[] { mainCommit };
            var allFiles   = commits.CreateAllFiles(f2);

            var state = RepositoryState.CreateWithFullBranchState(allFiles);

            state.Apply(mainCommit);

            Assert.AreEqual(state["branch"].LiveFiles.Single(), "file1");
            Assert.AreEqual(state["branch"]["file1"].ToString(), "1.1");
            Assert.AreSame(state["branch"]["file2"], Revision.Empty);
        }
Пример #26
0
 public virtual async Task <NetResult <SuccessResult> > ChangePassword([FromBody] ChangePasswordModel model)
 {
     try
     {
         SuccessResult result = new SuccessResult();
         var           user   = _user.Get(this.UserId <TKey>());
         if (RepositoryState.GetHashString(user.Password) == RepositoryState.GetHashString(model.OldPassword))
         {
             result.Success = await _user.ChangePassword(user, model);
         }
         return(result);
     }
     catch (Exception ext)
     {
         return(ext);
     }
 }
Пример #27
0
 /// <summary>Sets default values for not explicitly specified options.</summary>
 /// <remarks>
 /// Sets default values for not explicitly specified options. Then validates
 /// that all required data has been provided.
 /// </remarks>
 /// <param name="state">the state of the repository we are working on</param>
 /// <exception cref="NGit.Api.Errors.NoMessageException">if the commit message has not been specified
 ///     </exception>
 private void ProcessOptions(RepositoryState state)
 {
     if (committer == null)
     {
         committer = new PersonIdent(repo);
     }
     if (author == null)
     {
         author = committer;
     }
     // when doing a merge commit parse MERGE_HEAD and MERGE_MSG files
     if (state == RepositoryState.MERGING_RESOLVED)
     {
         try
         {
             parents = repo.ReadMergeHeads();
         }
         catch (IOException e)
         {
             throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionOccurredDuringReadingOfGIT_DIR
                                                                  , Constants.MERGE_HEAD, e), e);
         }
         if (message == null)
         {
             try
             {
                 message = repo.ReadMergeCommitMsg();
             }
             catch (IOException e)
             {
                 throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionOccurredDuringReadingOfGIT_DIR
                                                                      , Constants.MERGE_MSG, e), e);
             }
         }
     }
     if (message == null)
     {
         // as long as we don't suppport -C option we have to have
         // an explicit message
         throw new NoMessageException(JGitText.Get().commitMessageNotSpecified);
     }
 }
Пример #28
0
 /// <summary>
 /// Opens a local repository present in the given path.
 /// </summary>
 /// <param name="localRepositoryPath">The local repository path.</param>
 /// <seealso cref="CloseRepository" />
 /// <seealso cref="State" />
 public void OpenRepository(string localRepositoryPath)
 {
     try
     {
         _currentRepository = new Repository(localRepositoryPath);
         if (_currentRepository != null)
         {
             _state = RepositoryState.Opened;
         }
         else
         {
             _state = RepositoryState.Unknown;
         }
     }
     catch
     {
         _state = RepositoryState.Faulted;
         throw;
     }
 }
        public virtual async Task <ClaimsIdentity> LoginClaims(string username, string password)
        {
            var user = await _dbSet.FirstOrDefaultAsync(m => m.UserName == username &&
                                                        m.Password == RepositoryState.GetHashString(password));

            if (user == null)
            {
                return(null);
            }
            _userRole.Where(m => m.UserId == user.Id);
            var clams = Claims(user);

            if (clams == null)
            {
                return(null);
            }
            var claimsIdentity = new ClaimsIdentity(clams, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);

            return(claimsIdentity);
        }
        public void WithFullBranchState_FileAddedOnParentAfterBranch()
        {
            var f1 = new FileInfo("file1").WithBranch("branch", "1.1.0.2");
            var f2 = new FileInfo("file2").WithBranch("branch", "1.1.0.2");

            var commits = new List <Commit>()
            {
                new Commit("c1").WithRevision(f1, "1.1"),
                new Commit("c2").WithRevision(f1, "1.1.2.1"),
                new Commit("c3").WithRevision(f2, "1.1"),
            };
            var allFiles = commits.CreateAllFiles(f2);

            var state = RepositoryState.CreateWithFullBranchState(allFiles);

            foreach (var commit in commits)
            {
                state.Apply(commit);
            }

            Assert.AreEqual(state["branch"].LiveFiles.Count(), 2);
            Assert.AreEqual(state["branch"]["file1"].ToString(), "1.1.2.1");
            Assert.AreEqual(state["branch"]["file2"].ToString(), "1.1");
        }
Пример #31
0
 internal void OnStateChanged()
 {
     var state = GetState();
     if(_state != state)
     {
         _state = state;
         var handler = StateChanged;
         if(handler != null) handler(this, EventArgs.Empty);
     }
 }
Пример #32
0
 private void UpdateState()
 {
     var state = GetState();
     if(_state != state)
     {
         _state = state;
         var handler = StateChanged;
         if(handler != null) handler(this, EventArgs.Empty);
     }
 }