Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SageFrameConfig pb = new SageFrameConfig();
        IsUseFriendlyUrls = pb.GetSettingBollByKey(SageFrameSettingKeys.UseFriendlyUrls);
        //if (!IsPostBack)
        //{
            profileText = GetSageMessage("LoginStatus", "MyProfile");
            Literal lnkProfileUrl = (Literal)LoginView1.TemplateControl.FindControl("lnkProfileUrl");
            RegisterURL = pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + ".aspx";
            if (pb.GetSettingsByKey(SageFrameSettingKeys.PortalShowProfileLink) == "1")
            {

                if (IsUseFriendlyUrls)
                {
                    if (GetPortalID > 1)
                    {
                        profileURL = "<a  href='" + ResolveUrl("~/portal/" + GetPortalSEOName + "/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalUserProfilePage) + ".aspx") + "'>" + profileText + "</a>";
                    }
                    else
                    {
                        profileURL = "<a  href='" + ResolveUrl("~/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalUserProfilePage) + ".aspx") + "'>" + profileText + "</a>";
                    }
                }
                else
                {
                    profileURL = "<a  href='" + ResolveUrl("~/Default.aspx?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalUserProfilePage)) + "'>" + profileText + "</a>";
                }
            }
            else
            {
                profileURL = "";
            }
            if (IsUseFriendlyUrls)
            {
                if (GetPortalID > 1)
                {
                    RegisterURL = ResolveUrl("~/portal/" + GetPortalSEOName + "/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + ".aspx");
                }
                else
                {
                    RegisterURL = ResolveUrl("~/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + ".aspx");
                }
            }
            else
            {
                RegisterURL = ResolveUrl("~/Default.aspx?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage));
            }
            if (HttpContext.Current.User != null)
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated == true)
                {
                    Label lblProfileURL = LoginView1.FindControl("lblProfileURL") as Label;
                    if (lblProfileURL != null)
                    {
                        if (profileURL != "")
                        {
                            lblProfileURL.Text = "<li>" + profileURL + "</li>";
                            lblProfileURL.Visible = true;
                        }
                        else
                        {
                            lblProfileURL.Visible = false;
                        }
                    }
                    else
                    {
                        Response.Redirect(pb.GetSettingsByKey(SageFrameSettingKeys.PortalDefaultPage) + ".aspx");

                    }
                    
                }
            }
            int UserRegistrationType = pb.GetSettingIntByKey(SageFrameSettingKeys.PortalUserRegistration);
            if (UserRegistrationType > 0)
            {
                RegisterURL = "<span class='cssClassRegister'><a href='" + RegisterURL + "'>" + GetSageMessage("LoginStatus", "Register") +"</a></span>";
            }
            else
            {
                RegisterURL = "";
            }
        //}
    }
        private void GetFormData()
        {
            #region "Loop for all controls"

            if (EditUserName == string.Empty)
            {
                EditUserName = GetUsername;
                //EditUserName = GetUsername;
            }

            foreach (Control cont in pnlForm.Controls)//grdList.TemplateControl.Controls
            {

                if (cont.GetType() == typeof(Table))
                {
                    foreach (Control pnlCon1 in cont.Controls)
                    {
                        if (pnlCon1.GetType() == typeof(TableRow))
                        {
                            foreach (Control pnlCon2 in pnlCon1.Controls)
                            {
                                if (pnlCon2.GetType() == typeof(TableCell))
                                {
                                    foreach (Control pnlCon3 in pnlCon2.Controls)
                                    {
                                        int ProfileID = 0;
                                        string ProfileValue = string.Empty;
                                        //TextBox
                                        if (pnlCon3.GetType() == typeof(TextBox))
                                        {
                                            TextBox txt = (TextBox)pnlCon3;
                                            if (txt != null)
                                            {
                                                string conID = txt.ID;
                                                string[] IDColl = conID.Split("_".ToCharArray());
                                                if (IDColl.Length > 0)
                                                {
                                                    ProfileID = Int32.Parse(IDColl[1].ToString());
                                                    ProfileValue = txt.Text.Trim();
                                                    if (txt.ToolTip != null && txt.ToolTip.ToLower() == "DateTime".ToLower())
                                                    {
                                                        DateTime mdate = new DateTime();
                                                        bool isProperDate = DateTime.TryParse(txt.Text.Trim(), out mdate);
                                                        if (isProperDate)
                                                        {
                                                            if (DateTime.Now == mdate)
                                                            {
                                                               // ShowMessage(SageMessageTitle.Notification.ToString(), "Please provide actual date of birth!", "", SageMessageType.Error);
                                                                ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "PleaseProvideActualDateOfBirth"), "", SageMessageType.Error);
                                                                return;
                                                            }
                                                            if (DateTime.Now < mdate)
                                                            {
                                                               // ShowMessage(SageMessageTitle.Notification.ToString(), "Please provide actual date of birth!", "", SageMessageType.Error);
                                                                ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "ProvideActualDateOfBirth"), "", SageMessageType.Error);
                                                                return;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        //DropDownList
                                        if (pnlCon3.GetType() == typeof(DropDownList))
                                        {
                                            DropDownList ddl = (DropDownList)pnlCon3;
                                            if (ddl != null && ddl.Items.Count > 0)
                                            {
                                                string conID = ddl.ID;
                                                string[] IDColl = conID.Split("_".ToCharArray());
                                                if (IDColl.Length > 0)
                                                {
                                                    ProfileID = Int32.Parse(IDColl[1].ToString());
                                                    ProfileValue = ddl.SelectedItem.Text;
                                                }
                                            }
                                        }
                                        //CheckBoxList
                                        if (pnlCon3.GetType() == typeof(CheckBoxList))
                                        {
                                            CheckBoxList chbl = (CheckBoxList)pnlCon3;
                                            if (chbl != null)
                                            {
                                                string conID = chbl.ID;
                                                string[] IDColl = conID.Split("_".ToCharArray());
                                                if (IDColl.Length > 0)
                                                {
                                                    ProfileID = Int32.Parse(IDColl[1].ToString());
                                                    ProfileValue = chbl.SelectedItem.Text;
                                                }
                                            }
                                        }
                                        //RadioButtonList
                                        if (pnlCon3.GetType() == typeof(RadioButtonList))
                                        {
                                            RadioButtonList rdbl = (RadioButtonList)pnlCon3;
                                            if (rdbl != null)
                                            {
                                                string conID = rdbl.ID;
                                                string[] IDColl = conID.Split("_".ToCharArray());
                                                if (IDColl.Length > 0)
                                                {
                                                    ProfileID = Int32.Parse(IDColl[1].ToString());
                                                    ProfileValue = rdbl.SelectedItem.Text;
                                                }
                                            }
                                        }

                                        //File Upload
                                        if (pnlCon3.GetType() == typeof(FileUpload))
                                        {
                                            FileUpload asFlu = (FileUpload)pnlCon3;
                                            if (asFlu != null)
                                            {
                                                if (asFlu.HasFile)
                                                {
                                                    string Ext = asFlu.PostedFile.ContentType;
                                                    if (!string.IsNullOrEmpty(Ext))
                                                        Ext = Ext.Replace(".", "");
                                                    SageFrameConfig pagebase = new SageFrameConfig();
                                                    if (PictureManager.IsValidIImageTypeWitMime(Ext))
                                                    {
                                                        int MaxFileSize = (pagebase.GetSettingIntByKey(SageFrameSettingKeys.PortalUserProfileMaxImageSize) * 1024);//Converted MB in to  KB
                                                        if (asFlu.PostedFile.ContentLength <= MaxFileSize)
                                                        {
                                                            string conID = asFlu.ID;
                                                            string[] IDColl = conID.Split("_".ToCharArray());
                                                            if (IDColl.Length > 0)
                                                            {
                                                                ProfileID = Int32.Parse(IDColl[1].ToString());
                                                                string path = HttpContext.Current.Server.MapPath("~/");
                                                                string MapPath = "Modules\\Admin\\UserManagement\\ProfileImage";
                                                                MapPath = Path.Combine(path, MapPath);
                                                                string savedPathMedium = "Modules\\Admin\\UserManagement\\ProfileImage\\MediumProfileImage";
                                                                savedPathMedium = Path.Combine(path, savedPathMedium);
                                                                string savedPathSmall = "Modules\\Admin\\UserManagement\\ProfileImage\\SmallProfileImage";
                                                                savedPathSmall = Path.Combine(path, savedPathSmall);

                                                                var folderPaths = db.sp_ProfileImageFoldersGet(EditUserName, ProfileID, GetPortalID);
                                                                foreach (sp_ProfileImageFoldersGetResult imageFolders in folderPaths)
                                                                {
                                                                    DeleteImageFiles(MapPath + '\\' + imageFolders.Value);
                                                                    DeleteImageFiles(savedPathMedium + '\\' + imageFolders.Value);
                                                                    DeleteImageFiles(savedPathSmall + '\\' + imageFolders.Value);
                                                                }

                                                                char[] separator = new char[] { '.' };
                                                                string[] fileNames = asFlu.FileName.Split(separator);
                                                                string fileName = fileNames[0];
                                                                string extension = string.Empty;
                                                                if (fileNames.Length > 1)
                                                                {
                                                                    extension = fileNames[fileNames.Length - 1];
                                                                }
                                                                fileName = PictureManager.GetFileName(fileName);
                                                                string strLargeImagePath = PictureManager.SaveImage(asFlu, fileName + "." + extension, MapPath);
                                                                string strMediumImagePath = PictureManager.CreateMediumThumnail(strLargeImagePath, GetPortalID,fileName + "." + extension, savedPathMedium, pagebase.GetSettingIntByKey(SageFrameSettingKeys.PortalUserProfileMediumImageSize));
                                                                string strSmallImagePath = PictureManager.CreateSmallThumnail(strLargeImagePath, GetPortalID, fileName + "." + extension, savedPathSmall, pagebase.GetSettingIntByKey(SageFrameSettingKeys.PortalUserProfileSmallImageSize));

                                                                //string FullPath = Server.MapPath(MapPath + asFlu.PostedFile.FileName);                                                        
                                                                //asFlu.SaveAs(FullPath);
                                                                ProfileValue = fileName + "." + extension;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "InvalidImageFileSize"), "", SageMessageType.Error);
                                                            return;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "InvalidImageFile"), "", SageMessageType.Error);
                                                        return;
                                                    }
                                                }
                                                else
                                                {
                                                    string conID = asFlu.ID;
                                                    string[] IDColl = conID.Split("_".ToCharArray());
                                                    if (IDColl.Length > 0)
                                                    {
                                                        ProfileID = Int32.Parse(IDColl[1].ToString());
                                                        HtmlGenericControl sageDiv = (HtmlGenericControl)pnlCon2.FindControl("BDDiv_" + ProfileID);
                                                        Image BDimg = (Image)sageDiv.FindControl("Bdimg_" + ProfileID);
                                                        if (BDimg != null)
                                                        {
                                                            string strImage = BDimg.ImageUrl;
                                                            if (!string.IsNullOrEmpty(strImage))
                                                            {
                                                                strImage = strImage.Remove(0, strImage.LastIndexOf("/"));
                                                                ProfileValue = strImage;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        //Inserting in Data Base                                
                                        System.Nullable<int> UserProfileID = 0;
                                        if (ProfileID != 0)
                                        {
                                            db.sp_UserProfileAdd(ref UserProfileID, EditUserName, ProfileID, ProfileValue, true, DateTime.Now,
                                                GetPortalID, GetUsername);
                                        }
                                    }
                                }

                            }
                        }
                    }
                }
            }

            #endregion
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        IncludeLanguageJS();
        Extension = SageFrameSettingKeys.PageExtension;
        SageFrameConfig pb = new SageFrameConfig();
        IsUseFriendlyUrls = pb.GetSettingBollByKey(SageFrameSettingKeys.UseFriendlyUrls);
        profileText = GetSageMessage("LoginStatus", "MyProfile");
        Literal lnkProfileUrl = (Literal)LoginView1.TemplateControl.FindControl("lnkProfileUrl");
        RegisterURL = pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + Extension;
        if (pb.GetSettingsByKey(SageFrameSettingKeys.PortalShowProfileLink) == "1")
        {
            string profilepage = pb.GetSettingsByKey(SageFrameSettingKeys.PortalUserProfilePage);
            profilepage = profilepage.ToLower().Equals("user-profile")
                              ? string.Format("/sf/{0}", profilepage)
                              : string.Format("/{0}", profilepage);
            if (GetPortalID > 1)
            {
                profileURL = "<a  href='" + ResolveUrl("~/portal/" + GetPortalSEOName + profilepage + Extension) + "'>" +
                             profileText + "</a>";
            }
            else
            {
                profileURL = "<a  href='" + ResolveUrl("~" + profilepage + Extension) + "'>" + profileText + "</a>";
            }
        }
        else
        {
            profileURL = string.Empty;
        }
        string userName = GetUsername;
        if (userName.ToLower() == "anonymoususer")
        {
            divAnonymousTemplate.Visible = true;
            divLoggedInTemplate.Visible = false;
            userName = "******";
        }
        else
        {
            divAnonymousTemplate.Visible = false;
            divLoggedInTemplate.Visible = true;
        }
      //  Label lblWelcomeMsg = LoginView1.FindControl("lblWelcomeMsg") as Label;
       // lblWelcomeMsg.Text = "<h2><span onload='GetMyLocale(this)'>Welcome " + userName + "!</span></h2>";

        lblWelcomeMsg.Text = lblWelcomeMsg.Text + " " + userName;
        if (IsUseFriendlyUrls)
        {
            if (GetPortalID > 1)
            {
                RegisterURL = ResolveUrl("~/portal/" + GetPortalSEOName + "/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + Extension);
            }
            else
            {
                RegisterURL = ResolveUrl("~/" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage) + Extension);
            }
        }
        else
        {
            RegisterURL = ResolveUrl("~/Default" + Extension + "?ptlid=" + GetPortalID + "&ptSEO=" + GetPortalSEOName + "&pgnm=" + pb.GetSettingsByKey(SageFrameSettingKeys.PortalRegistrationPage));
        }               
       
        int UserRegistrationType = pb.GetSettingIntByKey(SageFrameSettingKeys.PortalUserRegistration);
        if (UserRegistrationType > 0)
        {
            RegisterURL = "<span><a href='" + RegisterURL + "'>" + GetSageMessage("LoginStatus", "Register") + "</a></span>";
        }
        else
        {
            RegisterURL = "";
        }
    }
    public int RegisterUser(int storeID, int portalID, string firstName, string userName, string lastName, string password, string email)
    {
        SageFrameConfig pagebase = new SageFrameConfig();
        MembershipController _member = new MembershipController();
        int returnValue = 0;
        try
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(email))
            {
                returnValue = 1;// ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserRegistration", "PleaseEnterAllRequiredFields"), "", SageMessageType.Alert);
            }
            else
            {
                int UserRegistrationType = pagebase.GetSettingIntByKey(SageFrameSettingKeys.PortalUserRegistration);

                bool isUserActive = UserRegistrationType == 2 ? true : false;

                UserInfo objUser = new UserInfo();
                objUser.ApplicationName = Membership.ApplicationName;
                objUser.FirstName = firstName;
                objUser.UserName = userName;
                objUser.LastName = lastName;
                string Pwd, PasswordSalt;
                PasswordHelper.EnforcePasswordSecurity(_member.PasswordFormat, password, out Pwd, out PasswordSalt);
                objUser.Password = Pwd;
                objUser.PasswordSalt = PasswordSalt;
                objUser.Email = email;
                objUser.SecurityQuestion = "";
                objUser.SecurityAnswer = "";
                objUser.IsApproved = true;
                objUser.CurrentTimeUtc = DateTime.Now;
                objUser.CreatedDate = DateTime.Now;
                objUser.UniqueEmail = 0;
                objUser.PasswordFormat = _member.PasswordFormat;
                objUser.PortalID = portalID;
                objUser.AddedOn = DateTime.Now;
                objUser.AddedBy = "";
                objUser.UserID = Guid.NewGuid();
                objUser.RoleNames = SystemSetting.REGISTER_USER_ROLENAME;
                objUser.StoreID = storeID;
                objUser.CustomerID = 0;

                UserCreationStatus status = new UserCreationStatus();
                //CheckRegistrationType(UserRegistrationType, ref objUser);

                int customerId;
                string sessionCode;
                sessionCode = GetSessionCode();
                MembershipDataProvider.RegisterPortalUser(objUser, out status, out customerId, UserCreationMode.REGISTER);
                if (status == UserCreationStatus.DUPLICATE_USER)
                {
                    returnValue = 2;// ShowMessage(SageMessageTitle.Notification.ToString(), UserName.Text.Trim() + " " + GetSageMessage("UserManagement", "NameAlreadyExists"), "", SageMessageType.Alert);
                    //GenerateCaptchaImage();
                }
                else if (status == UserCreationStatus.DUPLICATE_EMAIL)
                {
                    returnValue = 3; //ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("UserManagement", "EmailAddressAlreadyIsInUse"), "", SageMessageType.Alert);
                    //GenerateCaptchaImage();
                }
                else if (status == UserCreationStatus.SUCCESS)
                {
                    UpdateCartAnonymoususertoRegistered(storeID, portalID, customerId, sessionCode);
                    returnValue = 4;

                }
            }
        }

        catch (Exception ex)
        {
            throw ex; // ProcessException(ex);
        }
        return returnValue;
    }