Esempio n. 1
0
    protected void Uppic(AuthorProfile ap)
    {
        if (fudPhoto.FileName == string.Empty)
        {
            return;
        }
        HttpPostedFile pf          = fudPhoto.PostedFile;
        int            intDocLen   = pf.ContentLength;
        string         contentType = pf.ContentType;

        byte[] Docbuffer = new byte[intDocLen];

        Stream objStream;

        objStream = pf.InputStream;
        objStream.Read(Docbuffer, 0, intDocLen);

        Res res = new Res();

        res.FileName    = Path.GetFileName(pf.FileName);
        res.ResType     = pf.ContentType;
        res.Description = "Profile";
        res.Author      = ap.UserName;
        res.Points      = 0;
        res.Save();

        res.CurrentPostFileBuffer = Docbuffer;
        res.BlobUpdate();

        res.CurrentPostFileBuffer = null;

        ap.PhotoURL = res.Id.ToString();
    }
Esempio n. 2
0
        public static void SeedDb(IConfiguration configuration)
        {
            var services = new ServiceCollection();

            services.AddDbContext <AppDbContext>(o =>
                                                 o.UseSqlServer(configuration.GetConnectionString("Default")));

            var serviceProvider = services.BuildServiceProvider();

            using (serviceProvider.CreateScope())
            {
                var context         = serviceProvider.GetService <AppDbContext>();
                var user            = new User("Test");
                var authorProfile   = new AuthorProfile("Tom", "Bina", "About me");
                var authorValidator = new AuthorValidator(context);
                var author          = Author.Create(user, authorProfile, authorValidator).Result;

                for (var i = 0; i < 20; i++)
                {
                    var blogPostContent = new BlogPostContent("This is a test subject.", "Let's begin with a test intro", "And here's the test content");
                    var category        = new Category("Test", 1, "Test description");
                    var blogPost        = new BlogPost(blogPostContent, author, category);
                    context.BlogPosts.Add(blogPost);
                }

                context.SaveChanges();
            }
            serviceProvider.Dispose();
        }
    private void BindTeacher()
    {
        ddlObj.Items.Clear();
        ListItem dli = new ListItem("教师团", "教师团");

        ddlObj.Items.Add(dli);
        if (Page.User.IsInRole("administrators"))
        {
            foreach (MembershipUser user in Membership.GetAllUsers())
            {
                AuthorProfile ap = AuthorProfile.GetProfile(user.UserName);

                if (ap.IsTeacher || ap.IsOrgan)
                {
                    ListItem li = new ListItem(ap.DisplayName, user.UserName);
                    ddlObj.Items.Add(li);
                    ddlObj.SelectedValue = User.Identity.Name;
                }
            }
        }
        else
        {
            ListItem li = new ListItem(AuthorProfile.GetProfile(Page.User.Identity.Name).DisplayName, Page.User.Identity.Name);
            ddlObj.Items.Add(li);
            ddlObj.SelectedValue = User.Identity.Name;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["id"] != null)
            {
                lbID.Text = Request.Params["id"];
            }
            ap = AuthorProfile.GetProfile(lbID.Text);
            //机构名称
            lbTitle.Text = ap.Company;
            strTitle = ap.Company;
            strCity = ap.Address;
            strGSJS = ap.AboutMe;
            strFWGKH = ap.Description1;
            this.Title = ap.Company;

            if (Request.Cookies["OrgansViewCount_" + lbID.Text] == null)
            {
                HttpCookie MyCookie = new HttpCookie("OrgansViewCount_" + lbID.Text);
                DateTime now = DateTime.Now;

                MyCookie["IP"] = Request.UserHostAddress;
                MyCookie["tid"] = lbID.Text;
                MyCookie.Expires = now.AddHours(1);

                Response.Cookies.Add(MyCookie);
                ap.ViewCount++;
                ap.Save();
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        gridComments.PageSize = 10;

        string confirm = "return confirm('{0}');";
        string msg     = "";

        if (Request.Path.ToLower().Contains("approved.aspx"))
        {
            btnAction.Text          = "允许发布";
            msg                     = string.Format(labels.areYouSure, "发布", "选中的精彩展示");
            btnAction.OnClientClick = string.Format(confirm, msg);
        }
        else if (Request.Path.ToLower().Contains("default.aspx"))
        {
            btnAction.Text    = "新增";
            btnAction.ToolTip = "增加新的培训现场";
            if (!AuthorProfile.GetProfile(Page.User.Identity.Name).IsPrivate)
            {
                btnAction.Enabled = false;
                btnDelete.Enabled = false;
            }
            else
            {
                btnAction.OnClientClick = GetEditHtml((Guid.NewGuid()).ToString(), "Editor.aspx", 600, 460);
            }
        }

        if (!Page.IsPostBack)
        {
            BindGrid();
        }
    }
Esempio n. 6
0
        public static AuthorProfile GetProfile(string id)
        {
            if (!Utils.StringIsNullOrWhitespace(id))
            {
                bool canEditRoles;
                if (!CanUserEditProfile(id, out canEditRoles))
                {
                    return(null);
                }

                return(AuthorProfile.GetProfile(id) ?? new AuthorProfile()
                {
                    DisplayName = string.Empty,
                    FirstName = string.Empty,
                    MiddleName = string.Empty,
                    LastName = string.Empty,
                    Birthday = new DateTime(1001, 1, 1),
                    PhotoUrl = string.Empty,
                    EmailAddress = string.Empty,
                    PhoneMobile = string.Empty,
                    PhoneMain = string.Empty,
                    PhoneFax = string.Empty,
                    CityTown = string.Empty,
                    RegionState = string.Empty,
                    Country = string.Empty,
                    AboutMe = string.Empty
                });
            }

            return(null);
        }
        /// <summary>
        /// The fill profiles.
        /// </summary>
        /// <returns>
        /// A list of AuthorProfile.
        /// </returns>
        public override List <AuthorProfile> FillProfiles()
        {
            var profiles = new List <AuthorProfile>();
            var blogs    = new List <Blog>();

            if (Blog.CurrentInstance.IsSiteAggregation)
            {
                blogs = Blog.Blogs;
            }
            else
            {
                blogs.Add(Blog.CurrentInstance);
            }

            foreach (Blog blog in blogs)
            {
                var folder = string.Format("{0}profiles{1}", GetFolder(blog), Path.DirectorySeparatorChar);

                if (!Directory.Exists(folder))
                {
                    continue;
                }

                profiles.AddRange(from file in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirectoryOnly)
                                  select new FileInfo(file)
                                  into info
                                  select info.Name.Replace(".xml", string.Empty)
                                  into username
                                  select AuthorProfile.Load(username));
            }

            return(profiles);
        }
    protected void GridList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HtmlAnchor    a1     = e.Row.Cells[0].FindControl("a1") as HtmlAnchor;
            HtmlAnchor    aPages = e.Row.Cells[0].FindControl("aPages") as HtmlAnchor;
            AuthorProfile crl    = ((AuthorProfile)e.Row.DataItem) as AuthorProfile;
            a1.HRef = aPages.HRef = GetEditHtml(crl.UserName.ToString());

            Label         ltDes     = e.Row.Cells[0].FindControl("ltDes") as Label;
            Label         ltAddress = e.Row.Cells[0].FindControl("ltAddress") as Label;
            AuthorProfile fd        = e.Row.DataItem as AuthorProfile;
            if (fd != null)
            {
                if (fd.AboutMe == null)
                {
                    ltDes.Text = "";
                }
                else
                {
                    ltDes.Text = StripString(fd.AboutMe, 90, true);
                }
                if (fd.Address == null)
                {
                    ltAddress.Text = "";
                }
                else
                {
                    ltAddress.Text = fd.Address;
                }
            }
        }
    }
Esempio n. 9
0
    private void BindWellcom()
    {
        string aType = "";

        if (User.IsInRole("students"))
        {
            aType = "学员";
        }
        if (User.IsInRole("teachers"))
        {
            aType = "授课讲师";
        }
        if (User.IsInRole("organs"))
        {
            aType = "培训机构";
        }
        if (User.IsInRole("administrators"))
        {
            aType = "管理员";
        }


        AuthorProfile ap      = AuthorProfile.GetProfile(User.Identity.Name);
        string        state   = ap.IsPrivate && ap.NoMess != string.Empty ? "<font color='green'>已通过审核</font>" : "<font color='red'>审核不通过,请联系管理员</font>";
        string        wellcom = "<font color='green'>" + AuthorProfile.GetProfile(User.Identity.Name).DisplayName + "</font>,欢迎您回来! ";

        if (aType != "管理员")
        {
            wellcom += "您现有积分:<font color='#3265C3'>" + ap.Points + "</font>点 会员类别:<font color='green'>" + aType + "</font> ";
            wellcom += " 会员级别:<font color='green'>普通会员</font> 帐户状态:" + state;
        }

        ltWellcom.Text = wellcom;
    }
    protected void btnok_Click(object sender, EventArgs e)
    {
        string reg_uid = Request["reg_uid"];

        Membership.CreateUser(Request["reg_uid"], Request["reg_pwd1"], Request["reg_email"]);
        //reg_nicheng reg_company
        //reg_phone1 reg_phone2 reg_phone3 reg_mobile reg_qqmsn
        AuthorProfile pc = new AuthorProfile(reg_uid);

        pc.DisplayName = Request["reg_nicheng"];
        pc.CityTown    = Request["reg_shi"];
        pc.Company     = Request["reg_company"];
        if (Request["reg_phone2"] != string.Empty)
        {
            pc.PhoneMain = Request["reg_phone1"].Trim() != string.Empty ?Request["reg_phone1"] + "-":"" + Request["reg_phone2"] + Request["reg_phone3"].Trim() != string.Empty ? "-" + Request["reg_phone3"] : "";
        }

        pc.PhoneMobile = Request["reg_mobile"];
        pc.MSN_QQ      = Request["reg_qqmsn"];
        pc.IsPrivate   = true;//学员注册直接审核通过
        pc.Save();

        Roles.AddUserToRole(reg_uid, "students");
        Response.Redirect(Utils.AbsoluteWebRoot + "reg/regok.aspx?uType=std", true);
    }
    private void bindUL(string fieldId)
    {
        Field  fd   = Field.GetField(new Guid(fieldId));
        string tmpl = "<div style='display:block;'><div style='float:left'><a href=\"" + Utils.AbsoluteWebRoot + "Views/TrainingView.aspx?id={0}\"  title=\"{1}\">{2}</a></div><div style='float:right'><span style='color: #FF6600'>{3}</span>天&nbsp;{4}</div></div><div style='clear:both;height=0px;'/>";
        //Utils.AbsoluteWebRoot
        int liCount = 0;

        foreach (Training item in Training.Trainings)
        {
            if (item.Fields.Contains(fd) && item.IsPublished)
            {
                HtmlGenericControl li      = new HtmlGenericControl("li");
                string             tchName = item.Teacher;
                AuthorProfile      ap      = AuthorProfile.GetProfile(item.Teacher);
                if (ap != null)
                {
                    tchName = ap.DisplayName;
                }
                li.InnerHtml = string.Format(tmpl, item.Id.ToString(), item.Title, jup(item.Title), item.Days.ToString(), tchName);
                li.Style.Add(HtmlTextWriterStyle.Width, "99%");
                list.Controls.Add(li);
                liCount++;
                if (liCount >= 10)
                {
                    break;
                }
            }
        }
    }
Esempio n. 12
0
        public static JsonProfile GetProfile(string id)
        {
            if (!Utils.StringIsNullOrWhitespace(id))
            {
                bool canEditRoles;
                if (!CanUserEditProfile(id, out canEditRoles))
                {
                    return(null);
                }

                var pf = AuthorProfile.GetProfile(id);

                if (pf == null)
                {
                    pf              = new AuthorProfile(id);
                    pf.Birthday     = DateTime.Parse("01/01/1900");
                    pf.DisplayName  = id;
                    pf.EmailAddress = Utils.GetUserEmail(id);
                    pf.FirstName    = id;
                    pf.Private      = true;
                    pf.Save();
                }

                return(AuthorProfile.ToJson(id));
            }

            return(null);
        }
    protected void Uppic(AuthorProfile ap)
    {
        if (fudPhoto.FileName == string.Empty)
        {
            return;
        }
        HttpPostedFile pf = fudPhoto.PostedFile;
        int intDocLen = pf.ContentLength;
        string contentType = pf.ContentType;

        byte[] Docbuffer = new byte[intDocLen];

        Stream objStream;
        objStream = pf.InputStream;
        objStream.Read(Docbuffer, 0, intDocLen);

        Res res = new Res();
        res.FileName = Path.GetFileName(pf.FileName);
        res.ResType = pf.ContentType;
        res.Description = "Profile";
        res.Author = ap.UserName;
        res.Points = 0;
        res.Save();

        res.CurrentPostFileBuffer = Docbuffer;
        res.BlobUpdate();

        res.CurrentPostFileBuffer = null;

        ap.PhotoURL = res.Id.ToString();
    }
    private void BindGrid()
    {
        List <AuthorProfile> aps = new List <AuthorProfile>();

        foreach (MembershipUser user in Membership.GetAllUsers())
        {
            AuthorProfile ap = AuthorProfile.GetProfile(user.UserName);
            if (ap != null && ap.IsOrgan && !ap.IsAdmin && ap.IsPrivate)
            {
                aps.Add(ap);
            }
        }
        int iCount = aps.Count;

        if (iCount >= 10)
        {
            for (int i = iCount; i > 10; i--)
            {
                aps.RemoveAt(i - 1);
            }
        }

        GridView1.DataSource = aps;
        GridView1.DataBind();
    }
    protected void GridTeachers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HtmlAnchor  aPages = e.Row.Cells[0].FindControl("aPages") as HtmlAnchor;
            PlaceHolder ltTchs = e.Row.Cells[1].FindControl("ltTchs") as PlaceHolder;
            HtmlAnchor  aMore  = e.Row.Cells[0].FindControl("aMore") as HtmlAnchor;
            Field       fd     = e.Row.DataItem as Field;
            if (fd != null)
            {
                aPages.HRef = aMore.HRef = Utils.AbsoluteWebRoot + @"TeacherList.aspx?fid=" + fd.Id;
                int num = 0;
                foreach (MembershipUser user in Membership.GetAllUsers())
                {
                    AuthorProfile ap = AuthorProfile.GetProfile(user.UserName);
                    if (ap != null && ap.IsTeacher && !ap.IsAdmin && ap.IsPrivate && ap.Fields.Contains(fd.Id.ToString()) && num < 9)
                    {
                        HtmlAnchor aTch = new HtmlAnchor();
                        aTch.HRef      = Utils.AbsoluteWebRoot + @"Views\TeacherView.aspx?uid=" + ap.UserName;
                        aTch.Title     = ap.DisplayName;
                        aTch.InnerText = StripString(ap.DisplayName, 4);
                        //aTch.Style.Add(HtmlTextWriterStyle.Color, "#333333");
                        ltTchs.Controls.Add(aTch);

                        Literal lt = new Literal();
                        lt.Text = " ";
                        ltTchs.Controls.Add(lt);
                        num++;
                    }
                }
            }
        }
    }
        /// <summary>
        /// The delete profile.
        /// </summary>
        /// <param name="profile">
        /// The profile.
        /// </param>
        public override void DeleteProfile(AuthorProfile profile)
        {
            var fileName = string.Format("{0}profiles{1}{2}.xml", GetFolder(profile.Blog), Path.DirectorySeparatorChar, profile.Id);

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            if (AuthorProfile.Profiles.Contains(profile))
            {
                AuthorProfile.Profiles.Remove(profile);
            }

            // remove profile picture
            var dir = BlogService.GetDirectory("/avatars");

            foreach (var f in dir.Files)
            {
                var dot = f.Name.IndexOf(".");
                var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                if (profile.UserName == img)
                {
                    f.Delete();
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// The delete profile.
        /// </summary>
        /// <param name="profile">
        /// The profile.
        /// </param>
        public override void DeleteProfile(AuthorProfile profile)
        {
            var fileName = string.Format("{0}profiles{1}{2}.xml", GetFolder(profile.Blog), Path.DirectorySeparatorChar, profile.Id);
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            if (AuthorProfile.Profiles.Contains(profile))
            {
                AuthorProfile.Profiles.Remove(profile);
            }

            // remove profile picture
            var dir = BlogService.GetDirectory("/avatars");
            foreach (var f in dir.Files)
            {
                var dot = f.Name.IndexOf(".");
                var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                if (profile.UserName == img)
                {
                    f.Delete();
                }
            }
        }
Esempio n. 18
0
        public override async Task InitializeAsync()
        {
            using (var context = TestContext.CreateNewContext())
            {
                var user = new User("Test");

                var authorProfile   = new AuthorProfile("Tom", "Bina", "About me");
                var authorValidator = new AuthorValidator(RequestDbContext);
                var author          = await Author.Create(user, authorProfile, authorValidator);

                await context.SaveChangesAsync();

                for (var i = 0; i < 2; i++)
                {
                    var dateRange   = new DateRange(new DateTime(2017, 1, 1), new DateTime(2017, 1, 2));
                    var resumeEvent = new ResumeEvent(author, dateRange, "Test", "Test");

                    context.ResumeEvents.Add(resumeEvent);
                    await context.SaveChangesAsync();
                }

                await context.SaveChangesAsync();

                var userService = new Mock <IUserService>();
                userService.Setup(exp => exp.GetOrCreateCurrentUserAsync()).ReturnsAsync(user);
                userService.Setup(exp => exp.TryGetCurrentUserAsync()).ReturnsAsync(user.ToSuccessResult());
                _userService   = userService.Object;
                _authorService = new AuthorService(_userService, RequestDbContext);
            }
        }
Esempio n. 19
0
        public static JsonProfile GetProfile(string id)
        {
            if (!Utils.StringIsNullOrWhitespace(id))
            {
                bool canEditRoles;
                if (!CanUserEditProfile(id, out canEditRoles))
                    return null;

                var pf = AuthorProfile.GetProfile(id);

                if (pf == null)
                {
                    pf = new AuthorProfile(id);
                    pf.Birthday = DateTime.Parse("01/01/1900");
                    pf.DisplayName = id;
                    pf.EmailAddress = Utils.GetUserEmail(id);
                    pf.FirstName = id;
                    pf.Private = true;
                    pf.Save();
                }

                return AuthorProfile.ToJson(id);
            }

            return null;
        }
    protected void btnok_Click(object sender, EventArgs e)
    {
        string reg_uid = Request["reg_uid"];
        Membership.CreateUser(Request["reg_uid"], Request["reg_pwd1"], Request["reg_email"]);

        AuthorProfile pc = new AuthorProfile(reg_uid);
        pc.DisplayName = Request["reg_xingming"];

        //pc.Company = Request["reg_company"];
        if (Request["reg_phone2"] != string.Empty)
        {
            pc.PhoneMain = (Request["reg_phone1"].Trim() != string.Empty ? Request["reg_phone1"] + "-" : "") + Request["reg_phone2"] + (Request["reg_phone3"].Trim() != string.Empty ? "-" + Request["reg_phone3"] : "");
        }

        pc.PhoneMobile = Request["reg_mobile"];
        if (Request["reg_fax2"] != string.Empty)
        {
            pc.PhoneFax = (Request["reg_fax1"].Trim() != string.Empty ? Request["reg_fax1"] + "-" : "") + Request["reg_fax2"];
        }
        pc.CityTown = Request["reg_shi"];
        pc.MSN_QQ = Request["reg_qqmsn"];
        pc.Company = Request["reg_company"];
        pc.Address = Request["reg_address"];
        pc.AboutMe = Request["reg_jianjie"];
        pc.Description1 = Request["reg_kehu"];

        Uppic(pc);
        pc.Save();

        Roles.AddUserToRole(reg_uid, "organs");

        Response.Redirect(Utils.AbsoluteWebRoot + "reg/regok.aspx?uType=org", true);
    }
Esempio n. 21
0
    protected void lbSaveProfile_Click(object sender, EventArgs e)
    {
        string userProfileToSave = ViewState["selectedProfile"] as string;
        AuthorProfile pc = AuthorProfile.GetProfile(userProfileToSave);
        if (pc == null)
            pc = new AuthorProfile(userProfileToSave);

        pc.IsPrivate = cbIsPublic.Checked;
        pc.DisplayName = tbDisplayName.Text;
        pc.FirstName = tbFirstName.Text;
        pc.MiddleName = tbMiddleName.Text;
        pc.LastName = tbLastName.Text;

        DateTime date;
        if (DateTime.TryParse(tbBirthdate.Text, out date))
            pc.Birthday = date;

        pc.PhotoURL = tbPhotoUrl.Text;
        pc.PhoneMain = tbPhoneMain.Text;
        pc.PhoneMobile = tbPhoneMobile.Text;
        pc.PhoneFax = tbPhoneFax.Text;
        pc.EmailAddress = tbEmailAddress.Text;
        pc.CityTown = tbCityTown.Text;
        pc.RegionState = tbRegionState.Text;
        pc.Country = ddlCountry.SelectedValue;
        pc.Company = tbCompany.Text;
        pc.AboutMe = tbAboutMe.Text;

        pc.Save();
    }
Esempio n. 22
0
    private void SetDDLUser()
    {
        int count = 0;

        foreach (MembershipUser user in Membership.GetAllUsers())
        {
            ListItem li = new ListItem(user.UserName, user.UserName);
            if (Request.Params["p"] != null)
            {
                AuthorProfile ap = AuthorProfile.GetProfile(user.UserName);
                if (ap == null || (!ap.IsPrivate && ap.NoMess == string.Empty))
                {
                    ddlUserList.Items.Add(li);
                    count++;
                }
            }
            else
            {
                ddlUserList.Items.Add(li);
                count++;
            }
        }
        if (count == 0)
        {
            Response.Redirect(Utils.RelativeWebRoot + "admin/pages/default.aspx");
        }
        ddlUserList.SelectedValue = User.Identity.Name;
    }
Esempio n. 23
0
        /// <summary>
        /// Remove any existing profile images
        /// </summary>
        /// <param name="profile">User profile</param>
        static void UpdateProfileImage(AuthorProfile profile)
        {
            var dir = BlogEngine.Core.Providers.BlogService.GetDirectory("/avatars");

            if (string.IsNullOrEmpty(profile.PhotoUrl))
            {
                foreach (var f in dir.Files)
                {
                    var dot = f.Name.IndexOf(".");
                    var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                    if (profile.UserName == img)
                    {
                        f.Delete();
                    }
                }
            }
            else
            {
                foreach (var f in dir.Files)
                {
                    var dot = f.Name.IndexOf(".");
                    var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                    // delete old profile image saved with different name
                    // for example was admin.jpg and now admin.png
                    if (profile.UserName == img && f.Name != profile.PhotoUrl.Replace("\"", ""))
                    {
                        f.Delete();
                    }
                }
            }
        }
        /// <summary>
        /// Retrieves a Page from the provider based on the specified id.
        /// </summary>
        /// <param name="id">The AuthorProfile id.</param>
        /// <returns>An AuthorProfile.</returns>
        public override AuthorProfile SelectProfile(string id)
        {
            var profile = new AuthorProfile(id);

            if (Blog.CurrentInstance.IsSiteAggregation)
            {
                foreach (Blog blog in Blog.Blogs)
                {
                    if (blog.IsActive && !blog.IsDeleted)
                    {
                        profile = SelectProfile(id, blog);

                        if (profile != null)
                        {
                            return(profile);
                        }
                    }
                }
            }
            else
            {
                return(SelectProfile(id, Blog.CurrentInstance));
            }

            return(profile);
        }
Esempio n. 25
0
    protected void Page_Load(object sender, EventArgs e)
    {
        gridComments.PageSize = 10;

        string confirm = "return confirm('{0}');";
        string msg     = "";

        if (Request.Path.ToLower().Contains("approved.aspx"))
        {
            btnAction.Text          = "允许发布";
            msg                     = string.Format(labels.areYouSure, "发布", "选中的资料");
            btnAction.OnClientClick = string.Format(confirm, msg);
        }
        else if (Request.Path.ToLower().Contains("default.aspx"))
        {
            if (!AuthorProfile.GetProfile(Page.User.Identity.Name).IsPrivate)
            {
                btnAdd.Enabled    = false;
                btnDelete.Enabled = false;
            }

            btnAction.Visible = false;
        }

        if (!Page.IsPostBack)
        {
            BindGrid();
        }
    }
Esempio n. 26
0
    /// <summary>
    /// Handles the RowDeleting event of the grid control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewDeleteEventArgs"/> instance containing the event data.</param>
    void grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string username = (string)gridUsers.DataKeys[e.RowIndex].Value;

        string[] roles = Roles.GetRolesForUser(username);
        Membership.DeleteUser(username);

        if (roles.Length > 0)
        {
            Roles.RemoveUserFromRoles(username, roles);
        }

        AuthorProfile profile = AuthorProfile.GetProfile(username);

        if (profile != null)
        {
            profile.Delete();
        }

        if (HttpContext.Current.User.Identity.Name.Equals(username, StringComparison.OrdinalIgnoreCase))
        {
            FormsAuthentication.SignOut();
        }

        Response.Redirect(Request.RawUrl);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["id"] != null)
            {
                lbID.Text = Request.Params["id"];
            }
            ap = AuthorProfile.GetProfile(lbID.Text);
            //机构名称
            lbTitle.Text = ap.Company;
            strTitle     = ap.Company;
            strCity      = ap.Address;
            strGSJS      = ap.AboutMe;
            strFWGKH     = ap.Description1;
            this.Title   = ap.Company;


            if (Request.Cookies["OrgansViewCount_" + lbID.Text] == null)
            {
                HttpCookie MyCookie = new HttpCookie("OrgansViewCount_" + lbID.Text);
                DateTime   now      = DateTime.Now;

                MyCookie["IP"]   = Request.UserHostAddress;
                MyCookie["tid"]  = lbID.Text;
                MyCookie.Expires = now.AddHours(1);

                Response.Cookies.Add(MyCookie);
                ap.ViewCount++;
                ap.Save();
            }
        }
    }
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         HtmlAnchor    aPages = e.Row.Cells[0].FindControl("aPages") as HtmlAnchor;
         AuthorProfile crl    = ((AuthorProfile)e.Row.DataItem) as AuthorProfile;
         aPages.HRef = GetEditHtml(crl.UserName.ToString());
     }
 }
Esempio n. 29
0
        public override void DeleteProfile(AuthorProfile profile)
        {
            string fileName = _Folder + "profiles" + Path.DirectorySeparatorChar + profile.Id + ".xml";
            if (File.Exists(fileName))
                File.Delete(fileName);

            if (AuthorProfile.Profiles.Contains(profile))
                AuthorProfile.Profiles.Remove(profile);
        }
 protected void btnNo_Click(object sender, EventArgs e)
 {
     string userProfileToSave = ViewState["selectedProfile"] as string;
     AuthorProfile pc = AuthorProfile.GetProfile(userProfileToSave);
     if (pc == null)
         pc = new AuthorProfile(userProfileToSave);
     pc.IsPrivate = false;
     pc.NoMess = txtNoMess.Text;
     pc.Save();
 }
Esempio n. 31
0
        /// <summary>
        /// The fill profiles.
        /// </summary>
        /// <returns>
        /// A list of AuthorProfile.
        /// </returns>
        public override List <AuthorProfile> FillProfiles()
        {
            var folder = string.Format("{0}profiles{1}", Category.Folder, Path.DirectorySeparatorChar);

            return((from file in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirectoryOnly)
                    select new FileInfo(file)
                    into info
                    select info.Name.Replace(".xml", string.Empty)
                    into username
                    select AuthorProfile.Load(username)).ToList());
        }
Esempio n. 32
0
 /// <summary>
 /// Gets the current user's profile.
 /// </summary>
 /// <returns>
 /// An Author Profile.
 /// </returns>
 protected AuthorProfile UserProfile()
 {
     try
     {
         return(AuthorProfile.GetProfile(Security.CurrentUser.Identity.Name));
     }
     catch (Exception e)
     {
         Utils.Log(e.Message);
         return(null);
     }
 }
Esempio n. 33
0
        private static void ClearCache(object sender, EventArgs e)
        {
            Blog.CurrentInstance.Cache.Remove(widgetCacheKey);

            Blog siteAggregationBlog = Blog.SiteAggregationBlog;

            if (siteAggregationBlog != null)
            {
                siteAggregationBlog.Cache.Remove(widgetCacheKey);
                AuthorProfile.RemoveProfile(siteAggregationBlog.Id);
            }
        }
Esempio n. 34
0
 protected AuthorProfile AdminProfile()
 {
     try
     {
         return(AuthorProfile.GetProfile(System.Threading.Thread.CurrentPrincipal.Identity.Name));
     }
     catch (Exception e)
     {
         Utils.Log(e.Message);
         return(null);
     }
 }
Esempio n. 35
0
        /// <summary>
        /// The delete profile.
        /// </summary>
        /// <param name="profile">
        /// The profile.
        /// </param>
        public override void DeleteProfile(AuthorProfile profile)
        {
            var fileName = string.Format("{0}profiles{1}{2}.xml", this.Folder, Path.DirectorySeparatorChar, profile.Id);
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            if (AuthorProfile.Profiles.Contains(profile))
            {
                AuthorProfile.Profiles.Remove(profile);
            }
        }
    private string GetProfileHtml(string name)
    {
        AuthorProfile ap = AuthorProfile.GetProfile(name);

        if (ap != null)
        {
            return(Utils.AbsoluteWebRoot + @"Views\TeacherView.aspx?uid=" + name);
        }
        else
        {
            return("javascript:void(0);");
        }
    }
    public string GetTeacherDisplayName(string name)
    {
        AuthorProfile ap = AuthorProfile.GetProfile(name);

        if (ap != null)
        {
            return(ap.DisplayName);
        }
        else
        {
            return(name);
        }
    }
 protected void GridTeachers_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         HtmlAnchor    aPages = e.Row.Cells[0].FindControl("aPages") as HtmlAnchor;
         HtmlAnchor    aTch   = e.Row.Cells[0].FindControl("aTch") as HtmlAnchor;
         AuthorProfile ap     = e.Row.DataItem as AuthorProfile;
         if (ap != null)
         {
             aPages.HRef = aTch.HRef = GetEditHtml(ap.UserName);
         }
     }
 }
Esempio n. 39
0
    protected void btnNo_Click(object sender, EventArgs e)
    {
        string        userProfileToSave = ViewState["selectedProfile"] as string;
        AuthorProfile pc = AuthorProfile.GetProfile(userProfileToSave);

        if (pc == null)
        {
            pc = new AuthorProfile(userProfileToSave);
        }
        pc.IsPrivate = false;
        pc.NoMess    = txtNoMess.Text;
        pc.Save();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        lbID.Text = Request.Params["uid"];
        tch = AuthorProfile.GetProfile(lbID.Text);
        this.Title = tch.DisplayName;
        if (Request.Cookies["tchViewCount_" + lbID.Text] == null)
        {
            HttpCookie MyCookie = new HttpCookie("tchViewCount_" + lbID.Text);
            DateTime now = DateTime.Now;

            MyCookie["IP"] = Request.UserHostAddress;
            MyCookie["tid"] = lbID.Text;
            MyCookie.Expires = now.AddHours(1);

            Response.Cookies.Add(MyCookie);
            tch.ViewCount++;
            tch.Save();
        }
    }
Esempio n. 41
0
        /// <summary>
        /// The insert profile.
        /// </summary>
        /// <param name="profile">
        /// The profile.
        /// </param>
        public override void InsertProfile(AuthorProfile profile)
        {
            if (!Directory.Exists(string.Format("{0}profiles", this.Folder)))
            {
                Directory.CreateDirectory(string.Format("{0}profiles", this.Folder));
            }

            var fileName = string.Format("{0}profiles{1}{2}.xml", this.Folder, Path.DirectorySeparatorChar, profile.Id);
            var settings = new XmlWriterSettings { Indent = true };

            using (var writer = XmlWriter.Create(fileName, settings))
            {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("profileData");

                writer.WriteElementString("DisplayName", profile.DisplayName);
                writer.WriteElementString("FirstName", profile.FirstName);
                writer.WriteElementString("MiddleName", profile.MiddleName);
                writer.WriteElementString("LastName", profile.LastName);

                writer.WriteElementString("CityTown", profile.CityTown);
                writer.WriteElementString("RegionState", profile.RegionState);
                writer.WriteElementString("Country", profile.Country);

                writer.WriteElementString("Birthday", profile.Birthday.ToString("yyyy-MM-dd"));
                writer.WriteElementString("AboutMe", profile.AboutMe);
                writer.WriteElementString("PhotoURL", profile.PhotoUrl);

                writer.WriteElementString("Company", profile.Company);
                writer.WriteElementString("EmailAddress", profile.EmailAddress);
                writer.WriteElementString("PhoneMain", profile.PhoneMain);
                writer.WriteElementString("PhoneMobile", profile.PhoneMobile);
                writer.WriteElementString("PhoneFax", profile.PhoneFax);

                writer.WriteElementString("IsPrivate", profile.Private.ToString());

                writer.WriteEndElement();
            }
        }
Esempio n. 42
0
        public override void InsertProfile(AuthorProfile profile)
        {
            if (!Directory.Exists(_Folder + "profiles"))
                Directory.CreateDirectory(_Folder + "profiles");

            string fileName = _Folder + "profiles" + Path.DirectorySeparatorChar + profile.Id + ".xml";
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(fileName, settings))
            {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("profileData");

                writer.WriteElementString("DisplayName", profile.DisplayName);
                writer.WriteElementString("FirstName", profile.FirstName);
                writer.WriteElementString("MiddleName", profile.MiddleName);
                writer.WriteElementString("LastName", profile.LastName);

                writer.WriteElementString("CityTown", profile.CityTown);
                writer.WriteElementString("RegionState", profile.RegionState);
                writer.WriteElementString("Country", profile.Country);

                writer.WriteElementString("Birthday", profile.Birthday.ToString("yyyy-MM-dd"));
                writer.WriteElementString("AboutMe", profile.AboutMe);
                writer.WriteElementString("PhotoURL", profile.PhotoURL);

                writer.WriteElementString("Company", profile.Company);
                writer.WriteElementString("EmailAddress", profile.EmailAddress);
                writer.WriteElementString("PhoneMain", profile.PhoneMain);
                writer.WriteElementString("PhoneMobile", profile.PhoneMobile);
                writer.WriteElementString("PhoneFax", profile.PhoneFax);

                writer.WriteElementString("IsPrivate", profile.IsPrivate.ToString());

                writer.WriteEndElement();
            }
        }
    protected void btnok_Click(object sender, EventArgs e)
    {
        string reg_uid = Request["reg_uid"];
        Membership.CreateUser(Request["reg_uid"], Request["reg_pwd1"],  Request["reg_email"]);
        //reg_nicheng reg_company
        //reg_phone1 reg_phone2 reg_phone3 reg_mobile reg_qqmsn
        AuthorProfile pc = new AuthorProfile(reg_uid);
        pc.DisplayName = Request["reg_nicheng"];
        pc.CityTown = Request["reg_shi"];
        pc.Company = Request["reg_company"];
        if (Request["reg_phone2"]!=string.Empty)
        {
            pc.PhoneMain =  Request["reg_phone1"].Trim() != string.Empty ?Request["reg_phone1"] + "-":"" + Request["reg_phone2"] + Request["reg_phone3"].Trim() != string.Empty ? "-" + Request["reg_phone3"] : "";
        }

        pc.PhoneMobile = Request["reg_mobile"];
        pc.MSN_QQ = Request["reg_qqmsn"];
        pc.IsPrivate = true;//学员注册直接审核通过
        pc.Save();

        Roles.AddUserToRole(reg_uid, "students");
        Response.Redirect(Utils.AbsoluteWebRoot + "reg/regok.aspx?uType=std", true);
    }
    protected void btnok_Click(object sender, EventArgs e)
    {
        string reg_uid = Request["reg_uid"];
        Membership.CreateUser(Request["reg_uid"], Request["reg_pwd1"], Request["reg_email"]);

        AuthorProfile pc = new AuthorProfile(reg_uid);
        pc.DisplayName = Request["reg_xingming"];
        pc.CityTown = Request["reg_shi"];
        //pc.Company = Request["reg_company"];
        if (Request["reg_phone2"] != string.Empty)
        {
            pc.PhoneMain = (Request["reg_phone1"].Trim() != string.Empty ? Request["reg_phone1"] + "-" : "") + Request["reg_phone2"] + (Request["reg_phone3"].Trim() != string.Empty ? "-" + Request["reg_phone3"] : "");
        }

        pc.PhoneMobile = Request["reg_mobile"];
        pc.MSN_QQ = Request["reg_qqmsn"];
        pc.Pay = Request["reg_pay"];
        pc.AboutMe = Request["reg_jianjie"];
        pc.Description1 = Request["reg_kehu"];
        pc.Description2 = Request["reg_zhujiang"];

        string fields = string.Empty;
        for (int i = 0; i < Field.Fields.Count; i++)
        {
            if (Request["reg_lingyu:" + i]!=null)
            {
                Field fld = Field.Fields[i];
                fields += fld.Id + "|";
            }
        }
        pc.Fields = fields.TrimEnd('|');
        Uppic(pc);
        pc.Save();

        Roles.AddUserToRole(reg_uid, "teachers");
        Response.Redirect(Utils.AbsoluteWebRoot + "reg/regok.aspx?uType=tch", true);
    }
Esempio n. 45
0
 /// <summary>
 /// Adds AuthorProfile to database
 /// </summary>
 /// <param name="profile"></param>
 public override void InsertProfile(AuthorProfile profile)
 {
     UpdateProfile(profile);
 }
Esempio n. 46
0
        /// <summary>
        /// Updates AuthorProfile to database
        /// </summary>
        /// <param name="profile"></param>
        public override void UpdateProfile(AuthorProfile profile)
        {
            // Remove Profile
            DeleteProfile(profile);

            // Create Profile Dictionary
            StringDictionary dic = new StringDictionary();

            if (!String.IsNullOrEmpty(profile.DisplayName))
                dic.Add("DisplayName", profile.DisplayName);
            if (!String.IsNullOrEmpty(profile.FirstName))
                dic.Add("FirstName", profile.FirstName);
            if (!String.IsNullOrEmpty(profile.MiddleName))
                dic.Add("MiddleName", profile.MiddleName);
            if (!String.IsNullOrEmpty(profile.LastName))
                dic.Add("LastName", profile.LastName);
            if (!String.IsNullOrEmpty(profile.CityTown))
                dic.Add("CityTown", profile.CityTown);
            if (!String.IsNullOrEmpty(profile.RegionState))
                dic.Add("RegionState", profile.RegionState);
            if (!String.IsNullOrEmpty(profile.Country))
                dic.Add("Country", profile.Country);
            if (!String.IsNullOrEmpty(profile.AboutMe))
                dic.Add("AboutMe", profile.AboutMe);
            if (!String.IsNullOrEmpty(profile.PhotoURL))
                dic.Add("PhotoURL", profile.PhotoURL);
            if (!String.IsNullOrEmpty(profile.Company))
                dic.Add("Company", profile.Company);
            if (!String.IsNullOrEmpty(profile.EmailAddress))
                dic.Add("EmailAddress", profile.EmailAddress);
            if (!String.IsNullOrEmpty(profile.PhoneMain))
                dic.Add("PhoneMain", profile.PhoneMain);
            if (!String.IsNullOrEmpty(profile.PhoneMobile))
                dic.Add("PhoneMobile", profile.PhoneMobile);
            if (!String.IsNullOrEmpty(profile.PhoneFax))
                dic.Add("PhoneFax", profile.PhoneFax);
            if (profile.Birthday != DateTime.MinValue)
                dic.Add("Birthday", profile.Birthday.ToString("yyyy-MM-dd"));

            dic.Add("IsPrivate", profile.IsPrivate.ToString());

            // Save Profile Dictionary
            string connString = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
            string providerName = ConfigurationManager.ConnectionStrings[connStringName].ProviderName;
            DbProviderFactory provider = DbProviderFactories.GetFactory(providerName);

            using (DbConnection conn = provider.CreateConnection())
            {
                conn.ConnectionString = connString;
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    foreach (string key in dic.Keys)
                    {
                        string sqlQuery = "INSERT INTO " + tablePrefix + "Profiles (UserName, SettingName, SettingValue) " +
                                          "VALUES (@user, @name, @value)";
                        if (parmPrefix != "@")
                            sqlQuery = sqlQuery.Replace("@", parmPrefix);
                        cmd.CommandText = sqlQuery;
                        cmd.Parameters.Clear();

                        DbParameter dpUser = provider.CreateParameter();
                        dpUser.ParameterName = parmPrefix + "user";
                        dpUser.Value = profile.Id;
                        cmd.Parameters.Add(dpUser);

                        DbParameter dpName = provider.CreateParameter();
                        dpName.ParameterName = parmPrefix + "name";
                        dpName.Value = key;
                        cmd.Parameters.Add(dpName);

                        DbParameter dpValue = provider.CreateParameter();
                        dpValue.ParameterName = parmPrefix + "value";
                        dpValue.Value = dic[key];
                        cmd.Parameters.Add(dpValue);

                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
Esempio n. 47
0
        /// <summary>
        /// Remove AuthorProfile from database
        /// </summary>
        /// <param name="profile"></param>
        public override void DeleteProfile(AuthorProfile profile)
        {
            string connString = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
            string providerName = ConfigurationManager.ConnectionStrings[connStringName].ProviderName;
            DbProviderFactory provider = DbProviderFactories.GetFactory(providerName);

            using (DbConnection conn = provider.CreateConnection())
            {
                conn.ConnectionString = connString;
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    string sqlQuery = "DELETE FROM " + tablePrefix + "Profiles " +
                                      "WHERE UserName = "******"name";
                    cmd.CommandText = sqlQuery;
                    cmd.CommandType = CommandType.Text;

                    DbParameter dpName = provider.CreateParameter();
                    dpName.ParameterName = parmPrefix + "name";
                    dpName.Value = profile.Id;
                    cmd.Parameters.Add(dpName);

                    cmd.ExecuteNonQuery();
                }
            }
        }
Esempio n. 48
0
        /// <summary>
        /// Loads AuthorProfile from database
        /// </summary>
        /// <param name="id">username</param>
        /// <returns></returns>
        public override AuthorProfile SelectProfile(string id)
        {
            StringDictionary dic = new StringDictionary();
            AuthorProfile profile = new AuthorProfile(id);

            // Retrieve Profile data from Db
            string connString = ConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
            string providerName = ConfigurationManager.ConnectionStrings[connStringName].ProviderName;
            DbProviderFactory provider = DbProviderFactories.GetFactory(providerName);

            using (DbConnection conn = provider.CreateConnection())
            {
                conn.ConnectionString = connString;
                conn.Open();

                using (DbCommand cmd = conn.CreateCommand())
                {
                    string sqlQuery = "SELECT SettingName, SettingValue FROM " + tablePrefix + "Profiles " +
                                        "WHERE UserName = "******"name";
                    cmd.CommandText = sqlQuery;
                    cmd.CommandType = CommandType.Text;

                    DbParameter dpName = provider.CreateParameter();
                    dpName.ParameterName = parmPrefix + "name";
                    dpName.Value = id;
                    cmd.Parameters.Add(dpName);

                    using (DbDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            dic.Add(rdr.GetString(0), rdr.GetString(1));
                        }
                    }
                }
            }

            // Load profile with data from dictionary
            if (dic.ContainsKey("DisplayName"))
                profile.DisplayName = dic["DisplayName"];
            if (dic.ContainsKey("FirstName"))
                profile.FirstName = dic["FirstName"];
            if (dic.ContainsKey("MiddleName"))
                profile.MiddleName = dic["MiddleName"];
            if (dic.ContainsKey("LastName"))
                profile.LastName = dic["LastName"];
            if (dic.ContainsKey("CityTown"))
                profile.CityTown = dic["CityTown"];
            if (dic.ContainsKey("RegionState"))
                profile.RegionState = dic["RegionState"];
            if (dic.ContainsKey("Country"))
                profile.Country = dic["Country"];
            if (dic.ContainsKey("Birthday"))
            {
                DateTime date;
                if (DateTime.TryParse(dic["Birthday"], out date))
                    profile.Birthday = date;
            }
            if (dic.ContainsKey("AboutMe"))
                profile.AboutMe = dic["AboutMe"];
            if (dic.ContainsKey("PhotoURL"))
                profile.PhotoURL = dic["PhotoURL"];
            if (dic.ContainsKey("Company"))
                profile.Company = dic["Company"];
            if (dic.ContainsKey("EmailAddress"))
                profile.EmailAddress = dic["EmailAddress"];
            if (dic.ContainsKey("PhoneMain"))
                profile.PhoneMain = dic["PhoneMain"];
            if (dic.ContainsKey("PhoneMobile"))
                profile.PhoneMobile = dic["PhoneMobile"];
            if (dic.ContainsKey("PhoneFax"))
                profile.PhoneFax = dic["PhoneFax"];
            if (dic.ContainsKey("IsPrivate"))
                profile.IsPrivate = dic["IsPrivate"] == "true";

            return profile;
        }
Esempio n. 49
0
 /// <summary>
 /// Deletes a Page from the data store specified by the provider.
 /// </summary>
 /// <param name="profile">
 /// The profile to delete.
 /// </param>
 public abstract void DeleteProfile(AuthorProfile profile);
 /// <summary>
 /// Deletes the specified Page from the current provider.
 /// </summary>
 /// <param name="profile">
 /// The profile to delete.
 /// </param>
 public static void DeleteProfile(AuthorProfile profile)
 {
     Provider.DeleteProfile(profile);
 }
Esempio n. 51
0
 /// <summary>
 /// The update profile.
 /// </summary>
 /// <param name="profile">
 /// The profile.
 /// </param>
 public override void UpdateProfile(AuthorProfile profile)
 {
     this.InsertProfile(profile);
 }
 /// <summary>
 /// Updates an exsiting Page.
 /// </summary>
 /// <param name="profile">
 /// The profile to update.
 /// </param>
 public static void UpdateProfile(AuthorProfile profile)
 {
     Provider.UpdateProfile(profile);
 }
Esempio n. 53
0
        /// <summary>
        /// Remove any existing profile images
        /// </summary>
        /// <param name="profile">User profile</param>
        static void UpdateProfileImage(AuthorProfile profile)
        {
            var dir = BlogEngine.Core.Providers.BlogService.GetDirectory("/avatars");

            if(string.IsNullOrEmpty(profile.PhotoUrl))
            {
                foreach (var f in dir.Files)
                {
                    var dot = f.Name.IndexOf(".");
                    var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                    if (profile.UserName == img)
                    {
                        f.Delete();
                    }
                }
            }
            else
            {
                foreach (var f in dir.Files)
                {
                    var dot = f.Name.IndexOf(".");
                    var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name;
                    // delete old profile image saved with different name
                    // for example was admin.jpg and now admin.png
                    if (profile.UserName == img && f.Name != profile.PhotoUrl.Replace("\"", ""))
                    {
                        f.Delete();
                    }
                }
            }
        }
Esempio n. 54
0
 static Profile GetProfile(string id)
 {
     if (!Utils.StringIsNullOrWhitespace(id))
     {
         var pf = AuthorProfile.GetProfile(id);
         if (pf == null)
         {
             pf = new AuthorProfile(id);
             pf.Birthday = DateTime.Parse("01/01/1900");
             pf.DisplayName = id;
             pf.EmailAddress = Utils.GetUserEmail(id);
             pf.FirstName = id;
             pf.Private = true;
             pf.Save();
         }
         
         return new Profile { 
             AboutMe = string.IsNullOrEmpty(pf.AboutMe) ? "" : pf.AboutMe,
             Birthday = pf.Birthday.ToShortDateString(),
             CityTown = string.IsNullOrEmpty(pf.CityTown) ? "" : pf.CityTown,
             Country = string.IsNullOrEmpty(pf.Country) ? "" : pf.Country,
             DisplayName = pf.DisplayName,
             EmailAddress = pf.EmailAddress,
             PhoneFax = string.IsNullOrEmpty(pf.PhoneFax) ? "" : pf.PhoneFax,
             FirstName = string.IsNullOrEmpty(pf.FirstName) ? "" : pf.FirstName,
             Private = pf.Private,
             LastName = string.IsNullOrEmpty(pf.LastName) ? "" : pf.LastName,
             MiddleName = string.IsNullOrEmpty(pf.MiddleName) ? "" : pf.MiddleName,
             PhoneMobile = string.IsNullOrEmpty(pf.PhoneMobile) ? "" : pf.PhoneMobile,
             PhoneMain = string.IsNullOrEmpty(pf.PhoneMain) ? "" : pf.PhoneMain,
             PhotoUrl = string.IsNullOrEmpty(pf.PhotoUrl) ? "" : pf.PhotoUrl.Replace("\"", ""),
             RegionState = string.IsNullOrEmpty(pf.RegionState) ? "" : pf.RegionState
         };
     }
     return null;
 }
        /// <summary>
        /// Loads AuthorProfile from database
        /// </summary>
        /// <param name="id">The user name.</param>
        /// <returns>An AuthorProfile.</returns>
        public override AuthorProfile SelectProfile(string id)
        {
            var dic = new StringDictionary();
            var profile = new AuthorProfile(id);

            // Retrieve Profile data from Db

            using (var conn = this.CreateConnection())
            {
                if (conn.HasConnection)
                {
                    if (Blog.CurrentInstance.IsSiteAggregation)
                    {
                        using (var cmd = conn.CreateTextCommand(string.Format("SELECT SettingName, SettingValue FROM {0}Profiles WHERE UserName = {1}name", this.tablePrefix, this.parmPrefix)))
                        {
                            cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), id));

                            using (var rdr = cmd.ExecuteReader())
                            {
                                while (rdr.Read())
                                {
                                    dic.Add(rdr.GetString(0), rdr.GetString(1));
                                }
                            }
                        }
                    }
                    else
                    {
                        using (var cmd = conn.CreateTextCommand(string.Format("SELECT SettingName, SettingValue FROM {0}Profiles WHERE BlogID = {1}blogid AND UserName = {1}name", this.tablePrefix, this.parmPrefix)))
                        {
                            cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString()));
                            cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), id));

                            using (var rdr = cmd.ExecuteReader())
                            {
                                while (rdr.Read())
                                {
                                    dic.Add(rdr.GetString(0), rdr.GetString(1));
                                }
                            }
                        }
                    }
                }
            }

            // Load profile with data from dictionary
            if (dic.ContainsKey("DisplayName"))
            {
                profile.DisplayName = dic["DisplayName"];
            }

            if (dic.ContainsKey("FirstName"))
            {
                profile.FirstName = dic["FirstName"];
            }

            if (dic.ContainsKey("MiddleName"))
            {
                profile.MiddleName = dic["MiddleName"];
            }

            if (dic.ContainsKey("LastName"))
            {
                profile.LastName = dic["LastName"];
            }

            if (dic.ContainsKey("CityTown"))
            {
                profile.CityTown = dic["CityTown"];
            }

            if (dic.ContainsKey("RegionState"))
            {
                profile.RegionState = dic["RegionState"];
            }

            if (dic.ContainsKey("Country"))
            {
                profile.Country = dic["Country"];
            }

            if (dic.ContainsKey("Birthday"))
            {
                DateTime date;
                if (DateTime.TryParse(dic["Birthday"], out date))
                {
                    profile.Birthday = date;
                }
            }

            if (dic.ContainsKey("AboutMe"))
            {
                profile.AboutMe = dic["AboutMe"];
            }

            if (dic.ContainsKey("PhotoURL"))
            {
                profile.PhotoUrl = dic["PhotoURL"];
            }

            if (dic.ContainsKey("Company"))
            {
                profile.Company = dic["Company"];
            }

            if (dic.ContainsKey("EmailAddress"))
            {
                profile.EmailAddress = dic["EmailAddress"];
            }

            if (dic.ContainsKey("PhoneMain"))
            {
                profile.PhoneMain = dic["PhoneMain"];
            }

            if (dic.ContainsKey("PhoneMobile"))
            {
                profile.PhoneMobile = dic["PhoneMobile"];
            }

            if (dic.ContainsKey("PhoneFax"))
            {
                profile.PhoneFax = dic["PhoneFax"];
            }

            if (dic.ContainsKey("IsPrivate"))
            {
                profile.Private = dic["IsPrivate"] == "true";
            }

            return profile;
        }
Esempio n. 56
0
        AuthorProfile SelectProfile(string id, Blog blog)
        {
            var fileName = string.Format("{0}profiles{1}{2}.xml", GetFolder(blog), Path.DirectorySeparatorChar, id);

            if (blog.IsSiteAggregation && !blog.IsPrimary)
                fileName = Path.Combine(BlogConfig.StorageLocation, "blogs", blog.Name, "profiles", id + ".xml");

            var doc = new XmlDocument();

            if (!File.Exists(fileName))
            {
                Utils.Log(string.Format("XmlBlogProvider: can not load profile from \"{0}\"", fileName));
                return null;
            }

            doc.Load(fileName);

            var profile = new AuthorProfile(id);

            if (doc.SelectSingleNode("//DisplayName") != null)
            {
                profile.DisplayName = doc.SelectSingleNode("//DisplayName").InnerText;
            }

            if (doc.SelectSingleNode("//FirstName") != null)
            {
                profile.FirstName = doc.SelectSingleNode("//FirstName").InnerText;
            }

            if (doc.SelectSingleNode("//MiddleName") != null)
            {
                profile.MiddleName = doc.SelectSingleNode("//MiddleName").InnerText;
            }

            if (doc.SelectSingleNode("//LastName") != null)
            {
                profile.LastName = doc.SelectSingleNode("//LastName").InnerText;
            }

            if (doc.SelectSingleNode("//CityTown") != null)
            {
                profile.CityTown = doc.SelectSingleNode("//CityTown").InnerText;
            }

            if (doc.SelectSingleNode("//RegionState") != null)
            {
                profile.RegionState = doc.SelectSingleNode("//RegionState").InnerText;
            }

            if (doc.SelectSingleNode("//Country") != null)
            {
                profile.Country = doc.SelectSingleNode("//Country").InnerText;
            }

            if (doc.SelectSingleNode("//Birthday") != null)
            {
                DateTime date;
                if (DateTime.TryParse(doc.SelectSingleNode("//Birthday").InnerText, out date))
                {
                    profile.Birthday = date;
                }
            }

            if (doc.SelectSingleNode("//AboutMe") != null)
            {
                profile.AboutMe = doc.SelectSingleNode("//AboutMe").InnerText;
            }

            if (doc.SelectSingleNode("//PhotoURL") != null)
            {
                profile.PhotoUrl = doc.SelectSingleNode("//PhotoURL").InnerText;
            }

            if (doc.SelectSingleNode("//Company") != null)
            {
                profile.Company = doc.SelectSingleNode("//Company").InnerText;
            }

            if (doc.SelectSingleNode("//EmailAddress") != null)
            {
                profile.EmailAddress = doc.SelectSingleNode("//EmailAddress").InnerText;
            }

            if (doc.SelectSingleNode("//PhoneMain") != null)
            {
                profile.PhoneMain = doc.SelectSingleNode("//PhoneMain").InnerText;
            }

            if (doc.SelectSingleNode("//PhoneMobile") != null)
            {
                profile.PhoneMobile = doc.SelectSingleNode("//PhoneMobile").InnerText;
            }

            if (doc.SelectSingleNode("//PhoneFax") != null)
            {
                profile.PhoneFax = doc.SelectSingleNode("//PhoneFax").InnerText;
            }

            if (doc.SelectSingleNode("//IsPrivate") != null)
            {
                profile.Private = doc.SelectSingleNode("//IsPrivate").InnerText == "true";
            }
            return profile;
        }
 /// <summary>
 /// Remove AuthorProfile from database
 /// </summary>
 /// <param name="profile">An AuthorProfile.</param>
 public override void DeleteProfile(AuthorProfile profile)
 {
     using (var conn = this.CreateConnection())
     {
         if (conn.HasConnection)
         {
             using (var cmd = conn.CreateTextCommand(string.Format("DELETE FROM {0}Profiles WHERE BlogID = {1}blogid AND UserName = {1}name", this.tablePrefix, this.parmPrefix)))
             {
                 cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString()));
                 cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), profile.Id));
                 cmd.ExecuteNonQuery();
             }
         }
     }
 }
Esempio n. 58
0
        /// <summary>
        /// Retrieves a Page from the provider based on the specified id.
        /// </summary>
        /// <param name="id">The AuthorProfile id.</param>
        /// <returns>An AuthorProfile.</returns>
        public override AuthorProfile SelectProfile(string id)
        {
            var profile = new AuthorProfile(id);

            if (Blog.CurrentInstance.IsSiteAggregation)
            {
                foreach (Blog blog in Blog.Blogs)
                {
                    if (blog.IsActive && !blog.IsDeleted)
                    {
                        profile = SelectProfile(id, blog);

                        if (profile != null)
                            return profile;
                    }
                }
            }
            else
            {
                return SelectProfile(id, Blog.CurrentInstance);
            }

            return profile;
        }
 /// <summary>
 /// Persists a new Page in the current provider.
 /// </summary>
 /// <param name="profile">
 /// The profile to insert.
 /// </param>
 public static void InsertProfile(AuthorProfile profile)
 {
     Provider.InsertProfile(profile);
 }
        /// <summary>
        /// Updates AuthorProfile to database
        /// </summary>
        /// <param name="profile">
        /// An AuthorProfile.
        /// </param>
        public override void UpdateProfile(AuthorProfile profile)
        {
            // Remove Profile
            this.DeleteProfile(profile);

            // Create Profile Dictionary
            var dic = new StringDictionary();

            if (!String.IsNullOrEmpty(profile.DisplayName))
            {
                dic.Add("DisplayName", profile.DisplayName);
            }

            if (!String.IsNullOrEmpty(profile.FirstName))
            {
                dic.Add("FirstName", profile.FirstName);
            }

            if (!String.IsNullOrEmpty(profile.MiddleName))
            {
                dic.Add("MiddleName", profile.MiddleName);
            }

            if (!String.IsNullOrEmpty(profile.LastName))
            {
                dic.Add("LastName", profile.LastName);
            }

            if (!String.IsNullOrEmpty(profile.CityTown))
            {
                dic.Add("CityTown", profile.CityTown);
            }

            if (!String.IsNullOrEmpty(profile.RegionState))
            {
                dic.Add("RegionState", profile.RegionState);
            }

            if (!String.IsNullOrEmpty(profile.Country))
            {
                dic.Add("Country", profile.Country);
            }

            if (!String.IsNullOrEmpty(profile.AboutMe))
            {
                dic.Add("AboutMe", profile.AboutMe);
            }

            if (!String.IsNullOrEmpty(profile.PhotoUrl))
            {
                dic.Add("PhotoURL", profile.PhotoUrl);
            }

            if (!String.IsNullOrEmpty(profile.Company))
            {
                dic.Add("Company", profile.Company);
            }

            if (!String.IsNullOrEmpty(profile.EmailAddress))
            {
                dic.Add("EmailAddress", profile.EmailAddress);
            }

            if (!String.IsNullOrEmpty(profile.PhoneMain))
            {
                dic.Add("PhoneMain", profile.PhoneMain);
            }

            if (!String.IsNullOrEmpty(profile.PhoneMobile))
            {
                dic.Add("PhoneMobile", profile.PhoneMobile);
            }

            if (!String.IsNullOrEmpty(profile.PhoneFax))
            {
                dic.Add("PhoneFax", profile.PhoneFax);
            }

            if (profile.Birthday != DateTime.MinValue)
            {
                dic.Add("Birthday", profile.Birthday.ToString("yyyy-MM-dd"));
            }

            dic.Add("IsPrivate", profile.Private.ToString());

            // Save Profile Dictionary

            using (var conn = this.CreateConnection())
            {
                using (var cmd = conn.CreateCommand())
                {
                    foreach (string key in dic.Keys)
                    {
                        var sqlQuery = string.Format("INSERT INTO {0}Profiles (BlogID, UserName, SettingName, SettingValue) VALUES ({1}blogid, {1}user, {1}name, {1}value)", this.tablePrefix, this.parmPrefix);

                        cmd.CommandText = sqlQuery;
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString()));
                        cmd.Parameters.Add(conn.CreateParameter(FormatParamName("user"), profile.Id));
                        cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), key));
                        cmd.Parameters.Add(conn.CreateParameter(FormatParamName("value"), dic[key]));

                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }