コード例 #1
0
 public ActionResult Index(IComponentPresentation componentPresentation, EmailNewsletter emailNewsletter, string ReturnUrl = "", string stepoverride = "register")
 {
     if (!base.User.Identity.IsAuthenticated)
     {
         stepoverride = "register";
     }
     ((dynamic) base.ViewBag).Stage = stepoverride;
     try
     {
         ((dynamic) base.ViewBag).Title = componentPresentation.Component.Fields["title"].Value;
     }
     catch (Exception)
     {
     }
     Registration model = new Registration {
         RegistrationForm = new RegistrationForm(),
         LoginForm = new LoginForm()
     };
     NameValueCollection @params = base.Request.Params;
     if (!string.IsNullOrEmpty(@params["action"]))
     {
         if (@params["action"] == "addtoshoppinglist")
         {
             ((dynamic) base.ViewBag).Title = Helper.GetResource("SignupShoppingList");
         }
         if (@params["action"] == "download")
         {
             ((dynamic) base.ViewBag).Title = Helper.GetResource("SignupDownload");
         }
     }
     if (!string.IsNullOrEmpty(ReturnUrl))
     {
         model.LoginForm.ReturnUrl = ReturnUrl + "?" + base.Request.QueryString.ToString().Replace("iframe=true", "");
         model.RegistrationForm.returnUrl = ReturnUrl + "?" + base.Request.QueryString.ToString().Replace("iframe=true", "");
     }
     else if (!string.IsNullOrWhiteSpace(base.Request.QueryString["source"]))
     {
         model.RegistrationForm.returnUrl = model.LoginForm.ReturnUrl = base.Request.QueryString["source"];
     }
     else
     {
         model.LoginForm.ReturnUrl = base.Url.Content(WebConfiguration.Current.MyProfile);
         model.RegistrationForm.returnUrl = base.Url.Content(WebConfiguration.Current.MyProfile);
     }
     this.GetModelData(model.RegistrationForm);
     if ((emailNewsletter.Techniques != null) && (emailNewsletter.Techniques.Count > 0))
     {
         model.RegistrationForm.CraftTypeList = emailNewsletter.Techniques;
     }
     if (!string.IsNullOrEmpty(emailNewsletter.EmailAddress))
     {
         model.RegistrationForm.CustomerDetails.EmailAddress = emailNewsletter.EmailAddress;
     }
     SelectListItem item = model.RegistrationForm.EmailNewsletter.SingleOrDefault<SelectListItem>(e => e.Text == "No");
     if (item != null)
     {
         item.Selected = true;
     }
     return base.View(model);
 }
コード例 #2
0
 public ActionResult EmailNewsletterSignup(EmailNewsletter emailNewsLetter)
 {
     Registration model = new Registration();
     LoginForm form = new LoginForm();
     RegistrationForm form2 = new RegistrationForm();
     model.RegistrationForm = form2;
     model.LoginForm = form;
     this.GetModelData(model.RegistrationForm);
     model.RegistrationForm.CraftTypeList = emailNewsLetter.Techniques;
     SelectListItem item = model.RegistrationForm.EmailNewsletter.SingleOrDefault<SelectListItem>(e => e.Text == "Yes");
     if (item != null)
     {
         item.Selected = true;
     }
     SelectListItem item2 = model.RegistrationForm.EmailNewsletter.SingleOrDefault<SelectListItem>(e => e.Text == "No");
     if (item2 != null)
     {
         item2.Selected = false;
     }
     model.RegistrationForm.CustomerDetails.EmailAddress = emailNewsLetter.EmailAddress;
     return base.View("Index", model);
 }
コード例 #3
0
        public ActionResult Index(ComponentPresentation componentPresentation, Registration model, string Stage)
        {
            bool flag = base.Request.IsAjaxRequest();
            bool flag2 = false;
            bool flag3 = false;
            string errorMessage = string.Empty;
            string returnUrl = string.Empty;
            LoginForm loginForm = model.LoginForm;
            RegistrationForm registrationForm = model.RegistrationForm;
            string str3 = !string.IsNullOrWhiteSpace(base.Request["source"]) ? base.Request["source"] : string.Empty;
            if (loginForm != null)
            {
                if (!string.IsNullOrEmpty(loginForm.ReturnUrl))
                {
                    returnUrl = loginForm.ReturnUrl;
                }
                if (!string.IsNullOrEmpty(str3))
                {
                    returnUrl = str3;
                }
                errorMessage = Helper.GetResource("LoginFailed");
                if (this.Login(loginForm))
                {
                    errorMessage = Helper.GetResource("LoginSuccess");
                    flag3 = true;
                    flag2 = true;
                }
                else
                {
                    ((dynamic) base.ViewBag).Stage = "register";
                    base.ModelState.AddModelError("LoginFailed", errorMessage);
                }
                if (flag)
                {
                    return base.Json(new { 
                        success = flag3,
                        allowRedirect = flag2,
                        redirect = returnUrl,
                        message = errorMessage
                    });
                }
            }
            if (registrationForm != null)
            {
                EmailUtility utility;
                string str4;
                string str5;
                string str6;
                Exception exception;
                if (!string.IsNullOrEmpty(registrationForm.returnUrl))
                {
                    returnUrl = registrationForm.returnUrl;
                }
                if (!string.IsNullOrEmpty(str3))
                {
                    returnUrl = str3;
                }
                errorMessage = Helper.GetResource("RegistrationFailed");
                PublicasterServiceRequest request = new PublicasterServiceRequest();
                switch (Stage)
                {
                    case "register":
                        errorMessage = Helper.GetResource("RegistrationFailed");
                        if (!this.IsProfileValid(registrationForm))
                        {
                            ((dynamic) base.ViewBag).Stage = "register";
                            flag3 = false;
                            errorMessage = Helper.GetResource("RegistrationFailed");
                            base.ModelState.AddModelError("UnableToCreateNewUser", Helper.GetResource("UnableToCreateNewUser"));
                            break;
                        }
                        if (this.Register(registrationForm))
                        {
                            ((dynamic) base.ViewBag).Stage = "preferences";
                            flag3 = true;
                            errorMessage = Helper.GetResource("RegisteredSuccessfully");
                            this.Logger.InfoFormat("RegistrationController : User created: {0} - {1}", new object[] { registrationForm.CustomerDetails.DisplayName, registrationForm.CustomerDetails.EmailAddress });
                            try
                            {
                                if (!WebConfiguration.Current.CheckEmailNewsletterOption)
                                {
                                    utility = new EmailUtility();
                                    str4 = ConfigurationManager.AppSettings["PasswordReminderEmailFrom"];
                                    str5 = ConfigurationManager.AppSettings["RegisterConfirmationEmailTemplate"];
                                    str6 = utility.SendEmail(registrationForm.CustomerDetails, str5, str4, registrationForm.CustomerDetails.EmailAddress);
                                    this.Logger.DebugFormat("RegistrationController : Register Confirmation Email > result {0}", new object[] { str6 });
                                }
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                                this.Logger.Debug("Unable to send confirmation email to user.");
                            }
                        }
                        else
                        {
                            ((dynamic) base.ViewBag).Stage = "register";
                            flag3 = false;
                            errorMessage = Helper.GetResource("UnableToCreateNewUser");
                            base.ModelState.AddModelError("UnableToCreateNewUser", Helper.GetResource("UnableToCreateNewUser"));
                        }
                        break;

                    case "preferences":
                        errorMessage = Helper.GetResource("PreferencesFailed");
                        model.RegistrationForm.returnUrl = this._settings.RegisterWelcome;
                        if (this.Preferences(registrationForm))
                        {
                            ((dynamic) base.ViewBag).Stage = "profile";
                            flag3 = true;
                            errorMessage = Helper.GetResource("PreferencesSaved");
                            try
                            {
                                MvcApplication.CraftsPrincipal user = (MvcApplication.CraftsPrincipal) base.HttpContext.User;
                                CoatsUserProfile profile = CoatsUserProfile.GetProfile(base.User.Identity.Name);
                                utility = new EmailUtility();
                                str4 = ConfigurationManager.AppSettings["PasswordReminderEmailFrom"];
                                str5 = ConfigurationManager.AppSettings["RegisterConfirmationEmailTemplate"];
                                string newsletter = "No";
                                string interests = string.Empty;
                                foreach (KeyValuePair<string, string> pair in registrationForm.Keywords)
                                {
                                    interests = interests + pair.Key + ",";
                                }
                                if (interests.Length > 0)
                                {
                                    interests = interests.Substring(0, interests.LastIndexOf(",") - 1);
                                }
                                KeyValuePair<string, string> pair2 = registrationForm.Keywords.SingleOrDefault<KeyValuePair<string, string>>(e => e.Key == WebConfiguration.Current.EmailNewsletterYes);
                                if (pair2.Key != null)
                                {
                                    newsletter = "yes";
                                }
                                if (WebConfiguration.Current.CheckEmailNewsletterOption && (pair2.Key != null))
                                {
                                    newsletter = "yes";
                                    string str9 = string.Empty;
                                    if (base.Request.Url != null)
                                    {
                                        str9 = base.Request.Url.Scheme + "://" + base.Request.Url.Host;
                                    }
                                    else
                                    {
                                        str9 = ConfigurationManager.AppSettings["SiteUrl"];
                                    }
                                    string registerThankYou = this._settings.RegisterThankYou;
                                    string str11 = HttpUtility.UrlEncode(General.Encrypt(profile.MAIL.Trim()));
                                    str9 = registerThankYou + "?UserEmail=" + str11;
                                    registrationForm.CustomerDetails.SiteUrl = str9;
                                    registrationForm.CustomerDetails.DisplayName = profile.DISPLAYNAME;
                                    registrationForm.CustomerDetails.LastName = profile.SURNAME;
                                    registrationForm.CustomerDetails.FirstName = profile.NAME;
                                    registrationForm.CustomerDetails.EmailAddress = profile.MAIL;
                                    str6 = utility.SendEmail(registrationForm.CustomerDetails, str5, str4, profile.MAIL);
                                    this.Logger.DebugFormat("RegistrationController : Register Confirmation Email > result {0}", new object[] { str6 });
                                    string clientIP = this.GetClientIP();
                                    this._registrationrepository.SaveRegisterData(registrationForm.CustomerDetails.EmailAddress, clientIP, "");
                                    request.createJsonPublicasterRequest(registrationForm.CustomerDetails.EmailAddress, registrationForm.CustomerDetails.FirstName, registrationForm.CustomerDetails.LastName, interests, registrationForm.CustomerDetails.DisplayName, newsletter);
                                }
                            }
                            catch (Exception exception2)
                            {
                                exception = exception2;
                                this.Logger.Debug("Unable to send confirmation email to user.");
                            }
                        }
                        else
                        {
                            ((dynamic) base.ViewBag).Stage = "preferences";
                            flag3 = false;
                        }
                        break;

                    case "profile":
                        errorMessage = Helper.GetResource("PreferencesSaved");
                        model.RegistrationForm.returnUrl = this._settings.RegisterWelcome;
                        if (this.Preferences(registrationForm))
                        {
                            flag3 = true;
                            errorMessage = Helper.GetResource("ProfileSaved");
                            base.HttpContext.Session["registrationStatus"] = "";
                            returnUrl = this._settings.RegisterWelcome;
                            flag2 = true;
                        }
                        else
                        {
                            ((dynamic) base.ViewBag).Stage = "profile";
                            flag3 = false;
                        }
                        break;
                }
            }
            if (flag2)
            {
                returnUrl = !string.IsNullOrEmpty(returnUrl) ? returnUrl : base.Url.Content(WebConfiguration.Current.MyProfile);
                if (flag)
                {
                    return base.Json(new { 
                        success = flag3,
                        allowRedirect = flag2,
                        redirect = returnUrl,
                        message = errorMessage
                    });
                }
                base.HttpContext.Response.Redirect(returnUrl);
            }
            model.RegistrationForm = (registrationForm != null) ? registrationForm : new RegistrationForm();
            model.LoginForm = (loginForm != null) ? loginForm : new LoginForm();
            model.RegistrationForm.returnUrl = returnUrl;
            model.LoginForm.ReturnUrl = returnUrl;
            this.GetModelData(model.RegistrationForm);
            return base.View(model);
        }