public ActionResult Index(ComponentPresentation componentPresentation, UserProfile model)
 {
     this.Logger.DebugFormat("Called Update Profile >>>> ", new object[0]);
     try
     {
         ((dynamic) base.ViewBag).Title = componentPresentation.Component.Fields["title"].Value;
     }
     catch (Exception)
     {
     }
     string email = string.Empty;
     if (base.User.Identity.IsAuthenticated)
     {
         email = base.User.Identity.Name;
     }
     bool flag = this.IsEditModelValid(model);
     if (flag)
     {
         try
         {
             MembershipUser user = Membership.GetUser();
             if (user == null)
             {
                 flag = false;
                 this.Logger.DebugFormat("Update Profile mUser null", new object[0]);
             }
             if (model.AddressDetails.Postcode != null)
             {
                 this.FindPostcode(model);
             }
             if (model.RegistrationStatus == "postcode invalid")
             {
                 flag = false;
             }
             if (flag)
             {
                 this.Logger.DebugFormat("User profile start  >>>>", new object[0]);
                 CoatsUserProfile userProfile = CoatsUserProfile.GetProfile(user.Email);
                 if (userProfile != null)
                 {
                     string selectedKeywords = base.Request["CraftType"];
                     string str3 = base.Request["email-newsletter"];
                     string str4 = base.Request["visibile-profile"];
                     PublicasterServiceRequest request = new PublicasterServiceRequest();
                     string newsletter = "No";
                     if (str3.Trim() == WebConfiguration.Current.EmailNewsletterYes.Trim())
                     {
                         newsletter = "yes";
                     }
                     if (((selectedKeywords != null) || (str3 != null)) || (str4 != null))
                     {
                         List<TridionTcmUri> keywordsSelectListItems = GetKeywordsSelectListItems(selectedKeywords);
                         List<TridionTcmUri> second = GetKeywordsSelectListItems(str3);
                         List<TridionTcmUri> list3 = GetKeywordsSelectListItems(str4);
                         IEnumerable<TridionTcmUri> enumerable = keywordsSelectListItems.Union<TridionTcmUri>(second).Union<TridionTcmUri>(list3);
                         Dictionary<string, string> dictionary = new Dictionary<string, string>();
                         foreach (TridionTcmUri uri in enumerable)
                         {
                             dictionary.Add(uri.TcmId, "tcm");
                         }
                         userProfile.Keywords = dictionary;
                         model.Keywords = dictionary;
                     }
                     if (!string.IsNullOrEmpty(model.NewPassword))
                     {
                         if (model.NewPassword == model.VerifyNewPassword)
                         {
                             if (!string.IsNullOrEmpty(model.CurrentPassword))
                             {
                                 CoatsUserProfile profile = CoatsUserProfile.GetProfile(email);
                                 if (model.CurrentPassword == profile.PASSWORD)
                                 {
                                     model.CustomerDetails.Password = model.NewPassword;
                                 }
                                 else
                                 {
                                     flag = false;
                                     base.ModelState.AddModelError("CurrentPasswordIncorrect", Helper.GetResource("CurrentPasswordIncorrect"));
                                 }
                             }
                             else
                             {
                                 flag = false;
                             }
                         }
                         else
                         {
                             flag = false;
                             base.ModelState.AddModelError("NewPasswordsNotMatch", Helper.GetResource("NewPasswordsNotMatch"));
                         }
                     }
                     if (flag)
                     {
                         this.MapUserProfileForUpdate(model, userProfile);
                         userProfile.Save();
                         if ((str3 != null) && WebConfiguration.Current.CheckEmailNewsletterOption)
                         {
                             if (str3.Trim() == WebConfiguration.Current.EmailNewsletterYes.Trim())
                             {
                                 EmailUtility utility = new EmailUtility();
                                 string fromEmailAddress = ConfigurationManager.AppSettings["PasswordReminderEmailFrom"];
                                 string emailTemplate = ConfigurationManager.AppSettings["RegisterConfirmationEmailTemplate"];
                                 string registerThankYou = this._settings.RegisterThankYou;
                                 string str9 = HttpUtility.UrlEncode(General.Encrypt(userProfile.MAIL.Trim()));
                                 registerThankYou = registerThankYou + "?UserEmail=" + str9;
                                 model.CustomerDetails.SiteUrl = registerThankYou;
                                 model.CustomerDetails.DisplayName = userProfile.DISPLAYNAME;
                                 model.CustomerDetails.EmailAddress = userProfile.MAIL;
                                 string str10 = utility.SendEmail(model.CustomerDetails, emailTemplate, fromEmailAddress, userProfile.MAIL);
                                 this.Logger.DebugFormat("ProfileController : Register Confirmation Email > result {0}", new object[] { str10 });
                                 request.createJsonPublicasterRequest(userProfile.MAIL, userProfile.NAME, userProfile.SURNAME, selectedKeywords, userProfile.DISPLAYNAME, newsletter);
                             }
                             else
                             {
                                 request.UnSubscripePublicaster(userProfile.MAIL);
                             }
                         }
                         CoatsUserProfile profile3 = CoatsUserProfile.GetProfile(userProfile.MAIL);
                         CookieHelper.WriteFormsCookie(userProfile.MAIL, userProfile.DISPLAYNAME, userProfile.NAME, userProfile.SURNAME, userProfile.LONG, userProfile.LAT, "");
                         ((dynamic) base.ViewBag).profileStatus = "saved";
                         if (profile3 == null)
                         {
                             flag = false;
                             base.ModelState.AddModelError(string.Empty, "");
                             this.Logger.DebugFormat("Update Profile newUser null", new object[0]);
                         }
                     }
                 }
             }
         }
         catch (Exception exception)
         {
             this.Logger.DebugFormat("Update Profile exception {0} {1}", new object[] { exception.Message, exception.InnerException });
             flag = false;
         }
     }
     if (base.ModelState.ContainsKey("CustomerDetails.DisplayName"))
     {
         base.ModelState["CustomerDetails.DisplayName"].Errors.Clear();
     }
     if (base.ModelState.ContainsKey("CustomerDetails.EmailAddress"))
     {
         base.ModelState["CustomerDetails.EmailAddress"].Errors.Clear();
     }
     if (!flag)
     {
         UserProfile profile4 = this.GetModel();
         base.ModelState.AddModelError(string.Empty, "");
         var typeArray = (from x in base.ModelState
             where x.Value.Errors.Count > 0
             select new { 
                 Key = x.Key,
                 Errors = x.Value.Errors
             }).ToArray();
         foreach (var type in typeArray)
         {
             this.Logger.DebugFormat("Update Profile error {0}", new object[] { type });
         }
         this.GetModelData(profile4);
         base.Session["feedback"] = Helper.GetResource("ProfileError");
         ((dynamic) base.ViewBag).profileStatus = "error";
         return base.View(profile4);
     }
     UserProfile profile5 = this.GetModel();
     base.Session["feedback"] = Helper.GetResource("ProfileChangesSaved");
     return base.View(profile5);
 }
        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);
        }