public static void FillPost(IDataReader dr, BSPost bsPost)
    {
        bsPost.Title        = dr["Title"].ToString();
        bsPost.PostID       = Convert.ToInt32(dr["PostID"]);
        bsPost.Code         = dr["Code"].ToString();
        bsPost.Content      = dr["Content"].ToString();
        bsPost.State        = (PostStates)Convert.ToInt16(dr["State"]);
        bsPost.AddComment   = Convert.ToBoolean(dr["AddComment"]);
        bsPost.Categories   = bsPost.GetCategoriesHtml();
        bsPost.Tags         = bsPost.GetTagsHtml();
        bsPost.CommentCount = bsPost.GetComments(CommentStates.Approved).Count;
        bsPost.ReadCount    = Convert.ToInt32(dr["ReadCount"]);
        bsPost.UserID       = Convert.ToInt32(dr["UserID"]);
        bsPost.UserName     = BSUser.GetUser(bsPost.UserID).UserName;
        bsPost.Date         = Convert.ToDateTime(dr["CreateDate"]);
        bsPost.UpdateDate   = dr["ModifyDate"] == DBNull.Value
                              ? Convert.ToDateTime(dr["CreateDate"])
                              : Convert.ToDateTime(dr["ModifyDate"]);
        bsPost.Link         = BSHelper.GetLink(bsPost);
        bsPost.Type         = (PostTypes)Convert.ToInt16(dr["Type"]);
        bsPost.Show         = (PostVisibleTypes)Convert.ToInt16(dr["Show"]);
        bsPost.ParentID     = Convert.ToInt32(dr["ParentID"]);
        bsPost.LanguageCode = Convert.ToString(dr["LanguageCode"]);

        bsPost.Metas = BSMeta.GetMetas(bsPost.PostID);
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        TextBox txtUserName = (TextBox)FindControl("txtUserName");
        TextBox txtPassword = (TextBox)FindControl("txtPassword");

        Label    lblInfo      = (Label)FindControl("lblInfo");
        CheckBox cbRememberMe = (CheckBox)FindControl("cbRememberMe");

        BSUser user = BSUser.GetUser(txtUserName.Text, BSHelper.GetMd5Hash(txtPassword.Text));

        if (user != null)
        {
            Session.Timeout   = 129600;
            Blogsa.ActiveUser = user;

            Roles.AddUserToRole(Blogsa.ActiveUser.UserName, Blogsa.ActiveUser.Role);

            user.LastLoginDate = DateTime.Now;
            user.Save();
            FormsAuthentication.RedirectFromLoginPage(Blogsa.ActiveUser.UserName, cbRememberMe.Checked);
        }
        else
        {
            lblInfo.Text = Language.Get["ErrorUserPassword"];
        }
    }
Esempio n. 3
0
    static void FillComment(IDataReader dr, BSComment bsComment)
    {
        bsComment.CommentID    = Convert.ToInt32(dr["CommentID"]);
        bsComment.Content      = dr["Comment"].ToString();
        bsComment.Date         = Convert.ToDateTime(dr["CreateDate"]);
        bsComment.Email        = dr["EMail"].ToString();
        bsComment.GravatarLink = BSHelper.GetGravatar(bsComment.Email);
        bsComment.IP           = dr["IP"].ToString();
        bsComment.PostID       = Convert.ToInt32(dr["PostID"]);
        bsComment.UserID       = Convert.ToInt32(dr["UserID"]);
        bsComment.UserName     = dr["Name"].ToString();
        bsComment.WebPage      = dr["WebPage"].ToString();
        bsComment.Approve      = Convert.ToBoolean(dr["Approve"]);

        if (bsComment.UserID != 0)
        {
            BSUser user = BSUser.GetUser(bsComment.UserID);
            if (user != null)
            {
                bsComment.UserName = user.Name;
                bsComment.WebPage  = user.WebPage;
                bsComment.Email    = user.Email;
                bsComment.IsAdmin  = user.Role.Equals("admin");
            }
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        bool bUserRemoved = false;

        for (int i = 0; i < gvUsers.Rows.Count; i++)
        {
            CheckBox cb = gvUsers.Rows[i].FindControl("cb") as CheckBox;
            if (cb.Checked)
            {
                Literal literal = gvUsers.Rows[i].FindControl("ltUserID") as Literal;
                if (literal != null)
                {
                    string UserID  = literal.Text;
                    int    iUserID = Convert.ToInt32(UserID);
                    bUserRemoved = BSUser.GetUser(iUserID).Remove();
                }
            }
        }
        if (bUserRemoved)
        {
            MessageBox1.Message = Language.Admin["UserDeleted"];
            MessageBox1.Type    = MessageBox.ShowType.Information;
            MessageBox1.Visible = true;
            gvUsers.DataBind();
        }
    }
    protected void btnSaveUser_Click(object sender, EventArgs e)
    {
        int iUserID = 0;

        int.TryParse(Request["UserID"], out iUserID);

        if (User.IsInRole("editor"))
        {
            iUserID = Blogsa.ActiveUser.UserID;
        }

        BSUser user = BSUser.GetUser(iUserID);

        if (user == null)
        {
            user          = new BSUser();
            user.UserName = txtUserName.Text;
            user.Password = BSHelper.GetMd5Hash(txtPassword.Text);
        }
        else if (!String.IsNullOrEmpty(txtPassword.Text))
        {
            user.Password = BSHelper.GetMd5Hash(txtPassword.Text);
        }

        if (Blogsa.ActiveUser.Role.Equals("admin"))
        {
            user.Role = rblRole.SelectedValue;
        }
        else
        {
            user.Role = "user";
        }

        user.UserName = txtUserName.Text;

        user.Name    = txtName.Text;
        user.Email   = txtEmail.Text;
        user.WebPage = txtWebPage.Text;

        if (user.UserID != 1)
        {
            user.Role = rblRole.SelectedValue;
        }

        if (user.Save())
        {
            MessageBox1.Message = Language.Admin["UserSaved"];
            MessageBox1.Type    = MessageBox.ShowType.Information;
        }
        else
        {
            MessageBox1.Message = "Error";
            MessageBox1.Type    = MessageBox.ShowType.Error;
        }
    }
    private void GetUser(int UserID)
    {
        BSUser user = BSUser.GetUser(UserID);

        if (user != null)
        {
            txtUserName.Text      = user.UserName;
            txtName.Text          = user.Name;
            txtEmail.Text         = user.Email;
            txtWebPage.Text       = user.WebPage;
            rblRole.SelectedValue = user.Role;
            rblRole.Enabled       = user.UserID != 1;
        }
    }
Esempio n. 7
0
 public static int GetPostCountForUserID(int iUserId)
 {
     return(BSUser.GetUser(iUserId).GetPosts().Count);
 }