コード例 #1
0
 public VerifyEmailAddressResult VerifyEmailAddress(byte[] id, out PartnerEmailVerificationDTO emailVerification)
 {
     try
     {
         Connector.IsTransaction = true;
         VerifyEmailAddressResult    result = default;
         PartnerEmailVerificationDTO emailVerificationResult = ReadById(id);
         if (emailVerificationResult != null && emailVerificationResult.IsActive)
         {
             PartnerBLL partnerBLL = new PartnerBLL(Connector);
             partnerBLL.Update(emailVerificationResult.Partner.Id, new Dictionary <string, object>()
             {
                 { "HasEmailAddressBeenVerified", true }
             });
             Delete(id);
             result = VerifyEmailAddressResult.OK;
         }
         else
         {
             result = VerifyEmailAddressResult.NotFound;
         }
         Connector.CommitTransaction();
         emailVerification = emailVerificationResult;
         return(result);
     }
     catch (Exception exception)
     {
         Connector.RollbackTransaction();
         throw exception;
     }
 }
コード例 #2
0
ファイル: PartnerSessionBLL.cs プロジェクト: HatunSearch/NET
        public LoginResult Login(PartnerCredentialDTO credential, IPAddress ipAddress, bool keepOpened, out PartnerSessionDTO session)
        {
            Connector.IsTransaction = true;
            PartnerBLL partnerBLL = new PartnerBLL(Connector);
            PartnerDTO partner    = partnerBLL.ReadByUsername(credential.Username);

            if (partner != null)
            {
                if (!partner.IsLocked)
                {
                    byte[] credentialPassword = SHA512Hasher.Hash(credential.Password);
                    if (BinaryComparer.AreEqual(credentialPassword, partner.Password))
                    {
                        if (partner.HasEmailAddressBeenVerified)
                        {
                            DateTime loggedAt = DateTime.UtcNow;
                            session = new PartnerSessionDTO()
                            {
                                Partner   = partner,
                                IPAddress = ipAddress,
                                LoggedAt  = loggedAt
                            };
                            if (!keepOpened)
                            {
                                session.ExpiresOn = loggedAt.AddMinutes(16);
                            }
                            Create(session);
                            Connector.CommitTransaction();
                            return(LoginResult.OK);
                        }
                        else
                        {
                            Connector.RollbackTransaction();
                            session = null;
                            return(LoginResult.EmailAddressHasNotBeenVerified);
                        }
                    }
                    else
                    {
                        PartnerLoginAttemptBLL loginAttemptBLL = new PartnerLoginAttemptBLL(Connector);
                        PartnerLoginAttemptDTO loginAttempt    = new PartnerLoginAttemptDTO()
                        {
                            Partner   = partner,
                            IPAddress = ipAddress
                        };
                        loginAttemptBLL.Create(loginAttempt);
                        Guid partnerId = partner.Id;
                        PartnerSessionDTO             lastSession   = ReadLastByPartner(partnerId);
                        List <PartnerLoginAttemptDTO> loginAttempts = loginAttemptBLL.ReadByPartnerAndTimeStampAsDate(partnerId, lastSession?.LoggedAt ?? DateTime.UtcNow.Date).ToList();
                        if (loginAttempts.Count >= 3)
                        {
                            partnerBLL.Update(partnerId, new Dictionary <string, object>()
                            {
                                { "IsLocked", true }
                            });
                        }
                        Connector.CommitTransaction();
                        session = null;
                        return(LoginResult.PasswordDoesntMatch);
                    }
                }
                else
                {
                    Connector.RollbackTransaction();
                    session = null;
                    return(LoginResult.AccountIsLocked);
                }
            }
            else
            {
                Connector.RollbackTransaction();
                session = null;
                return(LoginResult.AccountDoesntExist);
            }
        }
コード例 #3
0
ファイル: PartnerCardBLL.cs プロジェクト: HatunSearch/NET
        public CreateResult Create(PartnerCardDTO card)
        {
            CreateResult result        = default;
            CardService  cardService   = new CardService();
            TokenService tokenService  = new TokenService();
            Token        stripeToken   = tokenService.Get(card.StripeId);
            Card         stripeNewCard = stripeToken.Card;

            if (stripeNewCard.Funding == "credit")
            {
                Connector.IsTransaction = true;
                try
                {
                    PartnerDTO partner         = card.Partner;
                    string     partnerStripeId = partner.StripeId;
                    if (partnerStripeId == null)
                    {
                        CustomerService customerService = new CustomerService();
                        PartnerBLL      partnerBLL      = new PartnerBLL(Connector);
                        Customer        customer        = customerService.Create(new CustomerCreateOptions()
                        {
                            Email = partner.EmailAddress
                        });
                        partner.StripeId = customer.Id;
                        partnerStripeId  = partner.StripeId;
                        partnerBLL.Update(card.Partner.Id, new Dictionary <string, object> {
                            { "StripeId", partner.StripeId }
                        });
                    }
                    IEnumerable <Card> stripeCards = cardService.List(partnerStripeId);
                    if (stripeCards.Count() < 10)
                    {
                        bool hasAlreadyBeenAdded = false;
                        foreach (Card stripeCard in stripeCards)
                        {
                            if (stripeCard.Fingerprint == stripeNewCard.Fingerprint)
                            {
                                hasAlreadyBeenAdded = true;
                                break;
                            }
                        }
                        if (!hasAlreadyBeenAdded)
                        {
                            CardCreateOptions cardCreateOptions = new CardCreateOptions()
                            {
                                SourceToken = card.StripeId
                            };
                            stripeNewCard = cardService.Create(card.Partner.StripeId, cardCreateOptions);
                            card.StripeId = stripeNewCard.Id;
                            Repository.Insert(card, out Guid? id);
                            card.Id = id.Value;
                            result  = CreateResult.OK;
                        }
                        else
                        {
                            result = CreateResult.CardHasAlreadyBeenAdded;
                        }
                        Connector.CommitTransaction();
                    }
                    else
                    {
                        Connector.RollbackTransaction();
                        result = CreateResult.MaximumAmountOfCardsReached;
                    }
                }
                catch (Exception exception)
                {
                    Connector.RollbackTransaction();
                    throw exception;
                }
            }
            else
            {
                result = CreateResult.CardIsNotCredit;
            }
            return(result);
        }