Exemple #1
0
        // GET: /Broker/BrokerHome/
        public System.Web.Mvc.ActionResult Index(string sourceref = "")
        {
            CustomerOrigin uiOrigin = UiCustomerOrigin.Get();

            ms_oLog.Debug("UI origin is {0}", uiOrigin.Stringify());

            if (uiOrigin.IsAlibaba())
            {
                return(RedirectToAction(
                           "Index",
                           User.Identity.IsAuthenticated ? "Profile" : "Wizard",
                           new { Area = "Customer" }
                           ));
            }             // if

            var oModel = new BrokerHomeModel();

            if (!string.IsNullOrWhiteSpace(sourceref))
            {
                var cookie = new HttpCookie(Constant.SourceRef, sourceref)
                {
                    Expires  = DateTime.Now.AddMonths(3),
                    HttpOnly = true,
                    Secure   = true
                };
                Response.Cookies.Add(cookie);
            }             // if

            oModel.MessageOnStart = (Session[Constant.Broker.MessageOnStart] ?? string.Empty).ToString().Trim();

            if (!string.IsNullOrWhiteSpace(oModel.MessageOnStart))
            {
                oModel.MessageOnStartSeverity = (Session[Constant.Broker.MessageOnStartSeverity] ?? string.Empty).ToString();

                Session[Constant.Broker.MessageOnStart]         = null;
                Session[Constant.Broker.MessageOnStartSeverity] = null;
            }             // if

            if (User.Identity.IsAuthenticated)
            {
                oModel.Auth = this.m_oHelper.IsBroker(User.Identity.Name) ? User.Identity.Name : Constant.Broker.Forbidden;

                ms_oLog.Info(
                    "Broker page sent to browser with authentication result '{0}' for identified name '{1}'.",
                    oModel.Auth,
                    User.Identity.Name
                    );
            }             // if

            oModel.Terms = (Session[Constant.Broker.Terms] ?? string.Empty).ToString().Trim();
            Session[Constant.Broker.Terms] = null;

            if (!string.IsNullOrWhiteSpace(oModel.Terms))
            {
                oModel.TermsID = Convert.ToInt32(Session[Constant.Broker.TermsID]);
                Session[Constant.Broker.TermsID] = null;
            }             // if

            return(View("Index", oModel));
        }         // Index
Exemple #2
0
        public static void SetAuth(string sLoginEmail, HttpContextBase oContext = null, string sRole = "Broker")
        {
            GenericPrincipal oNewUser;

            if (string.IsNullOrWhiteSpace(sLoginEmail))
            {
                FormsAuthentication.SignOut();
                oNewUser = new GenericPrincipal(new GenericIdentity(string.Empty), null);
                ObjectFactory.GetInstance <IEzbobWorkplaceContext>().RemoveSessionOrigin();
            }
            else
            {
                FormsAuthentication.SetAuthCookie(sLoginEmail, true);
                oNewUser = new GenericPrincipal(new GenericIdentity(sLoginEmail), new [] { sRole });

                Uri            requestUrl = (oContext != null) ? oContext.Request.Url : HttpContext.Current.Request.Url;
                CustomerOrigin uio        = UiCustomerOrigin.Get(requestUrl);
                ObjectFactory.GetInstance <IEzbobWorkplaceContext>().SetSessionOrigin(uio.GetOrigin());
            }             // if

            if (oContext == null)
            {
                HttpContext.Current.User = oNewUser;
            }
            else
            {
                oContext.User = oNewUser;
            }
        }         // SetAuth
        }         // GetSecuritySeals

        private static CustomerOrigin GetOriginFromViewBag(dynamic viewBag)
        {
            CustomerOrigin origin = null;

            try {
                if (viewBag != null)
                {
                    origin = viewBag.CustomerOrigin;
                }
            } catch {
                // Silently ignore.
            }             // try

            return(origin ?? ObjectFactory.GetInstance <CustomerOriginRepository>().GetDefault());
        }         // GetOriginFromViewBag
Exemple #4
0
        public JsonResult QuestionForEmail(string email)
        {
            if (!ModelState.IsValid)
            {
                return(GetModelStateErrors(ModelState));
            }

            try {
                if (this.brokerHelper.IsBroker(email))
                {
                    return(Json(new { broker = true }, JsonRequestBehavior.AllowGet));
                }
            } catch (Exception e) {
                log.Warn(
                    e,
                    "Failed to check whether the email '{0}' is a broker email, continuing as a customer.",
                    email
                    );
            }             // try

            CustomerOrigin uiOrigin = UiCustomerOrigin.Get();

            try {
                StringActionResult sar = this.serviceClient.Instance.GetCustomerSecurityQuestion(
                    email,
                    uiOrigin.GetOrigin()
                    );

                if (string.IsNullOrWhiteSpace(sar.Value))
                {
                    return(Json(new {
                        error = "Security question not found for user " + email,
                    }, JsonRequestBehavior.AllowGet));
                }                 // if

                return(Json(new { question = sar.Value, }, JsonRequestBehavior.AllowGet));
            } catch (Exception e) {
                log.Alert(
                    e,
                    "Failed to detect security question for customer '{0}' with origin '{1}'.",
                    email,
                    uiOrigin.GetOrigin()
                    );
                return(Json(new { error = "User : '******' was not found" }, JsonRequestBehavior.AllowGet));
            }     // try
        }         // QuestionForEmail
Exemple #5
0
        }         // CustomerLogOn

        public ActionResult LogOff()
        {
            EndSession("LogOff customer", true);
            this.context.RemoveSessionOrigin();

            switch (this.logOffMode)
            {
            case LogOffMode.SignUpOfEnv:
                return(RedirectToAction("Index", "Wizard", new { Area = "Customer" }));

            case LogOffMode.LogOnOfEnv:
                return(RedirectToAction("LogOn", "Account", new { Area = "" }));

            default:
                CustomerOrigin uiOrigin = UiCustomerOrigin.Get();
                return(Redirect(uiOrigin.FrontendSite));
            }     // switch
        }         // LogOff
Exemple #6
0
        }         // constructor

        public bool IsBroker(string sContactEmail)
        {
            BoolActionResult bar = null;

            CustomerOrigin uio = UiCustomerOrigin.Get();

            if (!string.IsNullOrWhiteSpace(sContactEmail))
            {
                try {
                    m_oLog.Debug(
                        "Checking whether '{0}' with origin '{1}' is a broker email.",
                        sContactEmail,
                        uio.Stringify()
                        );

                    bar = m_oServiceClient.Instance.IsBroker(sContactEmail, uio.CustomerOriginID);
                }
                catch (Exception e) {
                    m_oLog.Warn(
                        e,
                        "Failed to determine whether '{0}' with origin '{1}' is a broker email.",
                        sContactEmail,
                        uio.Stringify()
                        );
                }         // try
            }             // if

            var bIsBroker = (bar != null) && bar.Value;

            m_oLog.Debug(
                "'{0}' with origin '{2}' is {1}a broker email.",
                sContactEmail,
                bIsBroker ? "" : "not ",
                uio.Stringify()
                );

            return(bIsBroker);
        }         // IsBroker
Exemple #7
0
        public JsonResult RestorePassword(string email = "", string answer = "")
        {
            if (!ModelState.IsValid)
            {
                return(GetModelStateErrors(ModelState));
            }

            if (string.IsNullOrWhiteSpace(answer))
            {
                throw new EmptyAnswerExeption("Answer is empty.");
            }

            CustomerOrigin uiOrigin = UiCustomerOrigin.Get();

            try {
                StringActionResult sar = this.serviceClient.Instance.ValidateSecurityAnswer(
                    email,
                    uiOrigin.GetOrigin(),
                    answer
                    );

                if (string.IsNullOrWhiteSpace(sar.Value))
                {
                    return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new { error = "Wrong answer to secret question." }, JsonRequestBehavior.AllowGet));
            } catch (Exception e) {
                log.Alert(
                    e,
                    "Failed to validate an answer to security question for customer '{0}' with origin '{1}'.",
                    email,
                    uiOrigin.GetOrigin()
                    );

                return(Json(new { error = "Wrong answer to secret questions" }, JsonRequestBehavior.AllowGet));
            }     // try
        }         // RestorePassword
        }         // Get

        public static void Set(dynamic viewBag, string phoneNumber = null, CustomerOrigin customerOrigin = null)
        {
            customerOrigin         = customerOrigin ?? Get();
            viewBag.CustomerOrigin = customerOrigin;
            viewBag.PhoneNumber    = phoneNumber ?? customerOrigin.PhoneNumber;
        }         // Set
Exemple #9
0
        public JsonResult SignUp(
            User model,
            string FirstName,
            string Surname,
            string signupPass1,
            string signupPass2,
            string securityQuestion,
            string mobilePhone,
            string mobileCode,
            string isInCaptchaMode,
            int whiteLabelId
            )
        {
            string    id          = Guid.NewGuid().ToString("N");
            const int idChunkSize = 4;

            string uniqueID = string.Join("-",
                                          Enumerable.Range(0, id.Length / idChunkSize).Select(i => id.Substring(i * idChunkSize, idChunkSize))
                                          );

            log.Debug("Sign up client attempt id: '{0}'...", uniqueID);

            this.cookiesToRemoveOnSignup.Clear();

            if (!ModelState.IsValid)
            {
                return(GetModelStateErrors(ModelState));
            }

            if (model.SecurityAnswer.Length > 199)
            {
                throw new Exception(DbStrings.MaximumAnswerLengthExceeded);
            }

            CustomerOrigin uiOrigin = UiCustomerOrigin.Get();

            string alibabaID = GetAndRemoveCookie("alibaba_id");

            if (uiOrigin.IsAlibaba() && string.IsNullOrWhiteSpace(alibabaID))
            {
                return(Json(new {
                    success = false,
                    errorMessage = "No Alibaba customer id provided.",
                }, JsonRequestBehavior.AllowGet));
            }             // if

            var blm = new WizardBrokerLeadModel(Session);

            CampaignSourceRef campaignSourceRef = null;

            if (!blm.BrokerFillsForCustomer)
            {
                campaignSourceRef = new CampaignSourceRef {
                    FContent = GetAndRemoveCookie("fcontent"),
                    FMedium  = GetAndRemoveCookie("fmedium"),
                    FName    = GetAndRemoveCookie("fname"),
                    FSource  = GetAndRemoveCookie("fsource"),
                    FTerm    = GetAndRemoveCookie("fterm"),
                    FUrl     = GetAndRemoveCookie("furl"),
                    FDate    = ToDate(GetAndRemoveCookie("fdate")),
                    RContent = GetAndRemoveCookie("rcontent"),
                    RMedium  = GetAndRemoveCookie("rmedium"),
                    RName    = GetAndRemoveCookie("rname"),
                    RSource  = GetAndRemoveCookie("rsource"),
                    RTerm    = GetAndRemoveCookie("rterm"),
                    RUrl     = GetAndRemoveCookie("rurl"),
                    RDate    = ToDate(GetAndRemoveCookie("rdate")),
                };
            }             // if

            string visitTimes = GetAndRemoveCookie("sourceref_time");

            var signupModel = new SignupCustomerMultiOriginModel {
                UserName               = model.EMail,
                Origin                 = uiOrigin.GetOrigin(),
                RawPassword            = new DasKennwort(signupPass1),
                RawPasswordAgain       = new DasKennwort(signupPass2),
                PasswordQuestion       = Convert.ToInt32(securityQuestion),
                PasswordAnswer         = model.SecurityAnswer,
                RemoteIp               = RemoteIp(),
                FirstName              = FirstName,
                LastName               = Surname,
                CaptchaMode            = isInCaptchaMode == "True",
                MobilePhone            = mobilePhone,
                MobileVerificationCode = mobileCode,
                BrokerFillsForCustomer = blm.BrokerFillsForCustomer,
                WhiteLabelID           = whiteLabelId,
                IsTest                 = (Request.Cookies["istest"] != null) ? true : (bool?)null,
                CampaignSourceRef      = campaignSourceRef,
                GoogleCookie           = blm.BrokerFillsForCustomer ? string.Empty : GetAndRemoveCookie("__utmz"),
                ReferenceSource        = blm.BrokerFillsForCustomer ? "Broker" : GetAndRemoveCookie("sourceref"),
                AlibabaID              = blm.BrokerFillsForCustomer ? null : GetAndRemoveCookie("alibaba_id"),
                ABTesting              = GetAndRemoveCookie("ezbobab"),
                VisitTimes             = visitTimes,
                FirstVisitTime         = HttpUtility.UrlDecode(visitTimes),
                RequestedLoanAmount    = GetAndRemoveCookie("loan_amount"),
                RequestedLoanTerm      = GetAndRemoveCookie("loan_period"),
                BrokerLeadID           = blm.LeadID,
                BrokerLeadEmail        = blm.LeadEmail,
                BrokerLeadFirstName    = blm.FirstName,
            };

            log.Debug(
                "Sign up client attempt id: '{0}', model is {1}.",
                uniqueID,
                signupModel.ToLogStr()
                );

            try {
                log.Debug("Sign up client attempt id: '{0}', requesting backend sign up.", uniqueID);

                UserLoginActionResult signupResult = this.serviceClient.Instance.SignupCustomerMultiOrigin(signupModel);

                log.Debug("Sign up client attempt id: '{0}', backend sign up complete.", uniqueID);

                MembershipCreateStatus status = (MembershipCreateStatus)Enum.Parse(
                    typeof(MembershipCreateStatus),
                    signupResult.Status
                    );

                log.Debug("Sign up client attempt id: '{0}', status is {1}.", uniqueID, status);

                if (status == MembershipCreateStatus.DuplicateEmail)
                {
                    return(Json(
                               new {
                        success = false,
                        errorMessage = signupResult.ErrorMessage,
                    },
                               JsonRequestBehavior.AllowGet
                               ));
                }                 // if

                if ((status != MembershipCreateStatus.Success) || !string.IsNullOrWhiteSpace(signupResult.ErrorMessage))
                {
                    throw new Exception(string.IsNullOrWhiteSpace(signupResult.ErrorMessage)
                                                ? string.Format("Failed to sign up (error code is '{0}').", uniqueID)
                                                : signupResult.ErrorMessage
                                        );
                }                 // if

                ObjectFactory.GetInstance <IEzbobWorkplaceContext>().SessionId =
                    signupResult.SessionID.ToString(CultureInfo.InvariantCulture);

                Session["UserSessionId"] = signupResult.SessionID;

                this.context.SetSessionOrigin(uiOrigin.GetOrigin());
                FormsAuthentication.SetAuthCookie(model.EMail, false);
                HttpContext.User = new GenericPrincipal(new GenericIdentity(model.EMail), new[] { "Customer" });

                RemoveCookiesOnSignup();

                log.Debug("Sign up client attempt id: '{0}', sign up complete.", uniqueID);

                return(Json(
                           new {
                    success = true,
                    antiforgery_token = AntiForgery.GetHtml().ToString(),
                    refNumber = signupResult.RefNumber,
                },
                           JsonRequestBehavior.AllowGet
                           ));
            } catch (Exception e) {
                log.Alert(e, "Failed to sign up, client attempt id: {0}.", uniqueID);

                return(Json(
                           new {
                    success = false,
                    errorMessage = string.Format(
                        "Failed to sign up, please call support (error code is '{0}').",
                        uniqueID
                        ),
                },
                           JsonRequestBehavior.AllowGet
                           ));
            }     // try
        }         // SignUp
Exemple #10
0
        }         // constructor

        public WizardModel BuildWizardModel(
            Customer cus,
            HttpSessionStateBase session,
            string profile,
            string requestUrl,
            bool isProfile
            )
        {
            CustomerOrigin uiOrigin = cus == null?UiCustomerOrigin.Get() : cus.CustomerOrigin;

            var wizardModel = new WizardModel();

            Log.InfoFormat(
                "BuildWizardModel URL: {0} origin {1} customer {2}",
                requestUrl,
                uiOrigin.Name,
                cus == null ? "null" : cus.Id.ToString()
                );

            var customerModel = new CustomerModel {
                loggedIn         = cus != null,
                bankAccountAdded = false,
                Origin           = uiOrigin.Name,
            };

            if (!string.IsNullOrEmpty(profile))
            {
                wizardModel.WhiteLabel     = _whiteLabelProviderRepository.GetByName(profile);
                customerModel.IsWhiteLabel = wizardModel.WhiteLabel != null;
                customerModel.WhiteLabelId = wizardModel.WhiteLabel != null ? wizardModel.WhiteLabel.Id : 0;
            }

            wizardModel.Customer = customerModel;

            if (!customerModel.loggedIn)
            {
                customerModel.IsBrokerFill =
                    (session[Constant.Broker.FillsForCustomer] ?? Constant.No).ToString() == Constant.Yes;

                return(wizardModel);
            }             // if

            if (cus == null)
            {
                return(wizardModel);
            }

            var customer = m_oCustomerRepository.GetAndInitialize(cus.Id);

            if (customer == null)
            {
                return(wizardModel);
            }

            var user = m_oUsers.Get(cus.Id);

            customerModel.Origin = customer.CustomerOrigin.Name;
            customerModel.IsTest = customer.IsTest;

            if (customer.WhiteLabel != null)
            {
                wizardModel.WhiteLabel     = customer.WhiteLabel;
                customerModel.IsWhiteLabel = wizardModel.WhiteLabel != null;
                customerModel.WhiteLabelId = customer.WhiteLabel.Id;
            }             // if

            customerModel.Id         = customer.Id;
            customerModel.RefNumber  = customer.RefNumber;
            customerModel.userName   = user.Name;
            customerModel.Email      = customer.Name;
            customerModel.EmailState = EmailConfirmationState.Get(customer);

            customerModel.CustomerPersonalInfo = customer.PersonalInfo;

            customerModel.IsAlibaba = customer.IsAlibaba;

            if (customer.PropertyStatus != null)
            {
                customerModel.PropertyStatus = new PropertyStatusModel {
                    Id          = customer.PropertyStatus.Id,
                    Description = customer.PropertyStatus.Description,
                    IsOwnerOfOtherProperties = customer.PropertyStatus.IsOwnerOfOtherProperties,
                    IsOwnerOfMainAddress     = customer.PropertyStatus.IsOwnerOfMainAddress
                };
            }
            else
            {
                customerModel.PropertyStatus = new PropertyStatusModel();
            }             // if

            customerModel.BusinessTypeReduced = customerModel.CustomerPersonalInfo == null?
                                                TypeOfBusinessReduced.Personal.ToString() : customer.PersonalInfo.TypeOfBusiness.Reduce().ToString();

            customerModel.mpAccounts   = customer.GetMarketPlaces();
            customerModel.CreditSum    = customer.CreditSum;
            customerModel.CreditResult = customer.CreditResult.ToString();
            customerModel.Status       = customer.Status.ToString();

            var account = new AccountSettingsModel {
                SecurityQuestions = m_oQuestions.GetQuestions(),

                SecurityQuestionModel = new SecurityQuestionModel {
                    Question = user.SecurityQuestion == null ? 0 : user.SecurityQuestion.Id,
                    Answer   = user.SecurityAnswer
                },
            };

            customerModel.AccountSettings = account;

            customerModel.GreetingMailSentDate = customer.GreetingMailSentDate;

            var company = customer.Company;

            customerModel.CanHaveDirectors = false;

            if (company != null)
            {
                customerModel.CanHaveDirectors = company.TypeOfBusiness != TypeOfBusiness.SoleTrader;

                customerModel.CompanyInfo    = CompanyInfoMap.FromCompany(company);
                customerModel.CompanyAddress = company.CompanyAddress.ToArray();

                customerModel.CompanyInfo.Directors.AddRange(
                    m_oExperianDirectors.Find(customer.Id)
                    .Select(ed => DirectorModel.FromExperianDirector(ed, company.TypeOfBusiness.Reduce()))
                    );
            }             // if

            if (customer.AddressInfo != null)
            {
                customerModel.PersonalAddress          = customer.AddressInfo.PersonalAddress.ToArray();
                customerModel.PrevPersonAddresses      = customer.AddressInfo.PrevPersonAddresses.ToArray();
                customerModel.OtherPropertiesAddresses = customer.AddressInfo.OtherPropertiesAddresses.ToArray();
            }             // if

            customerModel.CompanyEmployeeCountInfo = new CompanyEmployeeCountInfo(customer.Company);

            customerModel.CustomerStatusName = customer.CollectionStatus.Name;

            // customerModel.LoyaltyPoints = customer.LoyaltyPoints();
            customerModel.IsOffline  = customer.IsOffline;
            customerModel.IsDisabled = !customer.CollectionStatus.IsEnabled;

            customerModel.LastSavedWizardStep = ((customer.WizardStep == null) || customer.WizardStep.TheLastOne)
                                ? string.Empty
                                : customer.WizardStep.Name;

            customerModel.QuickOffer = BuildQuickOfferModel(customer);

            CustomerRequestedLoan ra = customer.CustomerRequestedLoan.OrderByDescending(x => x.Created).FirstOrDefault();

            customerModel.RequestedLoan = ra ?? new CustomerRequestedLoan();

            customerModel.IsBrokerFill = customer.FilledByBroker;
            customerModel.DefaultCardSelectionAllowed = customer.DefaultCardSelectionAllowed;

            var cr = customer.LastCashRequest;

            customerModel.IsCurrentCashRequestFromQuickOffer = (cr != null) && (cr.QuickOffer != null);

            customerModel.IsLoanDetailsFixed = !m_oChangeLoanDetailsModelBuilder.IsAmountChangingAllowed(cr);

            customerModel.LastCashRequestID = (cr == null) ? 0 : cr.Id;

            if (isProfile)
            {
                BuildProfileModel(customerModel, customer);
            }

            return(wizardModel);
        }         // BuildWizardModel