예제 #1
0
        public UserLogin(
            CustomerOriginEnum?originID,
            string sEmail,
            DasKennwort sPassword,
            string sRemoteIp,
            string promotionName,
            DateTime?promotionPageVisitTime
            )
        {
            m_oResult = null;

            sEmail = NormalizeUserName(sEmail);

            m_oData = new UserSecurityData(this)
            {
                Email       = sEmail,
                OldPassword = sPassword.Decrypt(),
            };

            this.originName = originID.HasValue ? originID.Value.ToString() : "-- null --";

            m_oSpLoad = new UserDataForLogin(DB, Log)
            {
                Email    = sEmail,
                OriginID = originID.HasValue ? (int)originID.Value : (int?)null,
            };

            m_oSpResult = new UserLoginCheckResult(DB, Log)
            {
                Ip            = sRemoteIp,
                LotteryCode   = promotionName,
                PageVisitTime = promotionPageVisitTime,
            };
        }         // constructor
        }         // GenerateConfirmationToken

        private void CreateSecurityUserStuff()
        {
            if (this.model.Origin == null)
            {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0}: no origin specified.", this.uniqueID);
                throw new BadDataException();
            }             // if

            if (this.model.PasswordQuestion == null)
            {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0}: no security question specified.", this.uniqueID);
                throw new BadDataException();
            }             // if

            try {
                string rawPassword = this.model.RawPassword.Decrypt();

                var data = new UserSecurityData(this)
                {
                    Email            = this.model.UserName,
                    NewPassword      = rawPassword,
                    PasswordQuestion = this.model.PasswordQuestion.Value,
                    PasswordAnswer   = this.model.PasswordAnswer,
                };

                Log.Debug("Sign up attempt '{0}': validating user name...", this.uniqueID);

                data.ValidateEmail();

                Log.Debug("Sign up attempt '{0}': validating password...", this.uniqueID);

                data.ValidateNewPassword();

                Log.Debug("Sign up attempt '{0}': validated user name and password.", this.uniqueID);

                var passUtil = new PasswordUtility(CurrentValues.Instance.PasswordHashCycleCount);

                HashedPassword hashedPassword = passUtil.Generate(this.model.UserName, rawPassword);

                var sp = new CreateUserForCustomer(DB, Log)
                {
                    OriginID           = (int)this.model.Origin.Value,
                    Email              = this.model.UserName,
                    EzPassword         = hashedPassword.Password,
                    Salt               = hashedPassword.Salt,
                    CycleCount         = hashedPassword.CycleCount,
                    SecurityQuestionID = this.model.PasswordQuestion,
                    SecurityAnswer     = this.model.PasswordAnswer,
                    Ip = this.model.RemoteIp,
                };

                UserID = 0;

                sp.ForEachRowSafe(this.dbTransaction, (sr, bRowsetStart) => {
                    if (!sr.ContainsField("UserID"))
                    {
                        return(ActionResult.Continue);
                    }

                    UserID    = sr["UserID"];
                    SessionID = sr["SessionID"];
                    return(ActionResult.SkipAll);
                });

                Status = MembershipCreateStatus.ProviderError;

                switch (UserID)
                {
                case (int)CreateUserForCustomer.Errors.DuplicateUser:
                    ErrorMsg =
                        "This email address already exists in our system. " +
                        "Please try to log-in or request new password.";

                    Status = MembershipCreateStatus.DuplicateEmail;

                    Log.Warn(
                        "Sign up attempt '{0}': user with email {1} and origin {2} already exists.",
                        this.uniqueID,
                        this.model.UserName,
                        this.model.Origin.Value
                        );

                    break;

                case (int)CreateUserForCustomer.Errors.OriginNotFound:
                    Log.Alert("Sign up attempt '{0}': origin {1} was not found.", this.uniqueID, this.model.Origin.Value);
                    SetInternalErrorMsg();
                    break;

                case (int)CreateUserForCustomer.Errors.RoleNotFound:
                case (int)CreateUserForCustomer.Errors.FailedToCreateUser:
                case (int)CreateUserForCustomer.Errors.FailedToAttachRole:
                case (int)CreateUserForCustomer.Errors.FailedToCreateSession:
                case (int)CreateUserForCustomer.Errors.ConflictsWithInternal:
                case (int)CreateUserForCustomer.Errors.ConflictsWithBroker:
                    Log.Alert(
                        "Sign up attempt '{0}' - internal DB error: {1}.",
                        this.uniqueID,
                        ((CreateUserForCustomer.Errors)UserID).DescriptionAttr()
                        );
                    SetInternalErrorMsg();
                    break;

                default:
                    if (UserID <= 0)
                    {
                        Log.Alert(
                            "Sign up attempt '{0}': {1} returned unexpected result: {2}.",
                            this.uniqueID,
                            sp.GetType().Name,
                            UserID
                            );
                        SetInternalErrorMsg();
                    }
                    else
                    {
                        Log.Msg(
                            "Sign up attempt '{0}': user '{1}' with origin {2} was inserted into Security_User table.",
                            this.uniqueID,
                            this.model.UserName,
                            this.model.Origin.Value
                            );
                        Status = MembershipCreateStatus.Success;
                    }                     // if

                    break;
                }                 // switch
            } catch (AException ae) {
                SetInternalErrorMsg();
                Log.Alert("Sign up attempt {0} threw an exception: {1}.", this.uniqueID, ae.Message);
                throw new InternalErrorException();
            } catch (Exception e) {
                SetInternalErrorMsg();
                Log.Alert(e, "Sign up attempt {0} threw an exception.", this.uniqueID);
                throw new InternalErrorException();
            }     // try
        }         // CreateSecurityUserStuff