예제 #1
0
        public override Nothing Get(Request r)
        {
            if (RepoAccount.ValidateEmail(r.ID, r.Code))
            {
                return(Nothing);
            }

            throw HttpError.BadRequest("Sorry! Could not validate your email address...");
        }
예제 #2
0
        private bool EmailBelongsToSomeOneElse(Request r)
        {
            if (r.EmailAddress == null)
            {
                return(true);
            }

            var idForEmail = RepoAccount.GetID(r.EmailAddress.LowerCase());

            return(idForEmail != r.ID);
        }
예제 #3
0
 private void CheckIfEmailValidationIsNeeded(Request r)
 {
     if (r.ID.HasNoValue())
     {
         NeedsEmailVerification = true;
     }
     else if (r.ID != RepoAccount.GetID(r.EmailAddress.LowerCase()))
     {
         NeedsEmailVerification = true;
     }
     else
     {
         NeedsEmailVerification = false;
     }
 }
예제 #4
0
        public override Response Post(Request r)
        {
            var acc = RepoAccount.Find(a =>
                                       a.Email == r.UserName.LowerCase(),
                                       a => new
            {
                a.PasswordHash,
                a.IsEmailVerified,
                a.ID,
                a.Title,
                a.FirstName,
                a.LastName
            }).SingleOrDefault();

            if (acc != null)
            {
                if (!BCrypt.Net.BCrypt.Verify(r.Password, acc.PasswordHash))
                {
                    AddError("The supplied credentials are invalid. Please try again...");
                }
            }
            else
            {
                AddError("Sorry, couldn't locate your account...");
            }

            ThrowIfAnyErrors();

            if (!acc.IsEmailVerified)
            {
                AddError("Please verify your email address before logging in...");
            }

            ThrowIfAnyErrors();

            var permissions = default(Allow).All().ToArray();

            var session = new UserSession((Claim.AccountID, acc.ID));

            Response.SignIn(session, permissions);
            Response.FullName = $"{acc.Title} {acc.FirstName} {acc.LastName}";

            return(Response);
        }
예제 #5
0
        public override Response Get(Request r)
        {
            var acc = RepoAccount.FindExcluding(
                r.ID,
                a => new
            {
                a.PasswordHash,
                a.EmailVerificationCode
            });

            if (acc == null)
            {
                throw HttpError.NotFound("Unable to find the right Account!");
            }

            Response.FromEntity(acc);

            return(Response);
        }
예제 #6
0
        private void SendVerificationEmail(Data.Account a)
        {
            if (NeedsEmailVerification)
            {
                var code = PasswordGenerator.Generate(20);
                RepoAccount.SetEmailValidationCode(code, a.ID);

                var salutation = $"{a.Title} {a.FirstName} {a.LastName}";

                var email = new MongoWebApiStarter.Models.Email(
                    Settings.Email.FromName,
                    Settings.Email.FromEmail,
                    salutation,
                    a.Email,
                    "Please validate your Virtual Practice account...",
                    EmailTemplates.Email_Address_Validation);

                email.MergeFields.Add("Salutation", salutation);
                email.MergeFields.Add("ValidationLink", $"{BaseURL}#/account/{a.ID}-{code}/validate");

                email.AddToSendingQueue();
            }
        }
예제 #7
0
        public override Response Patch(Request r)
        {
            r.ID = User.ClaimValue(Claim.AccountID); //post tampering protection

            CheckIfEmailValidationIsNeeded(r);

            var acc = r.ToEntity();

            if (r.ID.HasValue()) // existing account
            {
                RepoAccount.SavePreserving(acc);
            }
            else // new account
            {
                RepoAccount.Save(acc);
            }

            SendVerificationEmail(acc);

            Response.EmailSent = NeedsEmailVerification;
            Response.ID        = acc.ID;

            return(Response);
        }
예제 #8
0
        public async Task SyncData()
        {
            

            var repository = _repoDataContext.VCSRepositories.FirstOrDefault(x => x.Id == _repoReader.Id);
            if (repository == null)
            {
                repository = new VCSRepository
                {
                    CrawlerProviderType = _repoReader.GetType().FullName,
                    Id = _repoReader.Id
                };
                _repoDataContext.VCSRepositories.Add(repository);
            }
            int totalCount = 0;
            DateTime dateBefore = DateTime.Now;
            while (true)
            {
                var dateAfter = dateBefore.Subtract(new TimeSpan(DAYS_PER_QUERY, 0, 0, 0));
                var commits = (await _repoReader.QueryCommits(dateAfter, dateBefore)).Commits;

                if (commits == null)
                {
                    break;
                }

                int count = 0;
                foreach (var crawlerCommit in commits)
                {
                    var authorId = crawlerCommit.AuthorId;
                    var account = _repoDataContext.RepositoryAccounts.Find(repository.Id, authorId);
                    Model.User user;

                    var c = _repoDataContext.Commits.Find(crawlerCommit.Id);
                    if (c != null)
                    {
                        continue;
                    }
                    if (account == null)
                    {
                        var accountInfo = crawlerCommit.Author ?? await _repoReader.GetAuthorDetail(authorId);
                        if (accountInfo == null) continue;

                        account = new RepoAccount
                        {
                            AccountId = authorId,
                            SourceRepoId = repository.Id,
                            Email = accountInfo.Email,
                            Name = accountInfo.Name,
                            SourceRepository = repository
                        };
                        _repoDataContext.RepositoryAccounts.Add(account);

                        user = new Model.User
                        {
                            Accounts = new List<RepoAccount> {account},
                            FullName = account.Name
                        };
                        _repoDataContext.Users.Add(user);
                    }
                    else
                    {
                        user = _repoDataContext.Users.Find(account.PersonId);
                    }
                    if (user == null)
                    {
                        Console.WriteLine("Error, cannot find person");
                        continue;
                    }


                    var commit = new Model.Commit
                    {
                        Id = crawlerCommit.Id,
                        VSCAuthorAccountId = account.AccountId,
                        VSCRepositoryId = repository.Id,
                        AuthorRepoAccount = account,
                        Created = crawlerCommit.Created,
                        Deletions = crawlerCommit.Deletions,
                        Insertions = crawlerCommit.Insertions,
                        Source = repository,
                        ProjectId = crawlerCommit.ProjectName,
                        Message = crawlerCommit.Message
                    };
                    _repoDataContext.Commits.Add(commit);
                    
                    count++;
                    totalCount++;
                }

                _repoDataContext.SaveChanges();
                if (count == 0) break;
                Console.WriteLine($"Total: {totalCount}, Last insert: {count}, Currert period: {dateBefore.ToString("d")}");
                dateBefore = dateAfter;
            }

            //_repoDataContext.SaveChanges();
        }