Exemple #1
0
    protected void PupolateControls()
    {
        int userId = 0;

        if (Request.QueryString["userId"] != "" && Request.QueryString["userId"] != null)
        {
            userId = Int32.Parse(Request.QueryString["userId"]);
        }

        UserList.DataSource = UserAccess.GetAdminUserListById(userId);
        UserList.DataBind();

        OAuthList.DataSource = OAuthAccess.GetAdminOAuthList(userId);
        OAuthList.DataBind();

        UserCategoryList.DataSource = UserCategoryAccess.GetAdminUserCategoryList(userId);
        UserCategoryList.DataBind();

        ZhuanTiList.DataSource = ZhuanTiAccess.GetAdminZhuanTiList(userId);
        ZhuanTiList.DataBind();

        CardList.DataSource = CardAccess.GetAdminCardList(userId);
        CardList.DataBind();

        List.DataSource = ItemAccess.GetAdminItemListByUserId(userId);
        List.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string openId      = Request.Form["openid"].ToString();
        string accessToken = Request.Form["accesstoken"].ToString();
        string oAuthFrom   = Request.Form["oauthfrom"].ToString();
        int    userId      = Int32.Parse(Request.Form["userid"].ToString());

        OAuthEntity oAuth = new OAuthEntity();

        oAuth.OpenID      = openId;
        oAuth.AccessToken = accessToken;
        oAuth.User        = UserAccess.GetUserById(userId);
        oAuth.OAuthFrom   = oAuthFrom;
        oAuth.OAuthBound  = 1;

        string result = "{";

        bool success = false;
        int  bound   = OAuthAccess.CheckOAuthBoundByOpenId(oAuth.OpenID);

        if (bound == 2)
        {
            success = SyncHelper.SyncInsertOAuth(oAuth);
            if (success)
            {
                result += "\"result\":\"1\"";
            }
            else
            {
                result += "\"result\":\"0\"";
            }
        }
        else if (bound == 0)
        {
            oAuth.OAuthBound = 1;
            success          = SyncHelper.SyncUpdateOAuth(oAuth);
            if (success)
            {
                result += "\"result\":\"1\"";
            }
            else
            {
                result += "\"result\":\"0\"";
            }
        }
        else
        {
            result += "\"result\":\"2\"";
        }

        result += "}";

        Response.Write(result);
        Response.End();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        userId = Int32.Parse(Session["UserID"].ToString());

        isBound = OAuthAccess.CheckOAuthBound(userId);

        if (!IsPostBack)
        {
            PopulateControls();
        }
    }
    //绑定已有帐号
    protected void BoundButton_Click(object sender, EventArgs e)
    {
        string userName = this.UserNameBound.Text.Trim();

        if (!ValidHelper.CheckLength(userName, 2))
        {
            Utility.Alert(this, "用户名填写错误!");
            return;
        }

        string userPassword = this.UserPasswordBound.Text.Trim();

        if (!ValidHelper.CheckLength(userPassword, 2))
        {
            Utility.Alert(this, "密码填写错误!");
            return;
        }

        int  newUserId = 0;
        bool success   = UserAccess.CheckUserLogin(userName, userPassword, out newUserId);

        if (success)
        {
            UserEntity user = UserAccess.GetUserById(newUserId);
            success = OAuthAccess.OAuthBoundUser(userId, user.UserID);
            if (success)
            {
                Session["UserID"]       = userId = user.UserID;
                Session["UserName"]     = user.UserName;
                Session["UserNickName"] = user.UserNickName;
                Session["UserTheme"]    = user.UserTheme;
                Session["UserLevel"]    = user.UserLevel.ToString();
                Session["UserFrom"]     = user.UserFrom;
                Session["UserWorkDay"]  = user.UserWorkDay;
                Session["UserFunction"] = user.UserFunction;
                Session["CategoryRate"] = user.CategoryRate;

                Response.Cookies["ThemeCookie"].Value   = user.UserTheme;
                Response.Cookies["ThemeCookie"].Expires = DateTime.MaxValue;

                PopulateControls();
                Utility.Alert(this, "绑定成功。", "UserBoundAdmin.aspx");
            }
            else
            {
                Utility.Alert(this, "绑定失败!");
            }
        }
        else
        {
            Utility.Alert(this, "登录失败!");
        }
    }
Exemple #5
0
    protected void GetQQImageButton_Click(object sender, EventArgs e)
    {
        if (this.AppID.Text.Trim() == "" || this.AppKey.Text.Trim() == "" || this.OpenIDBox.Text.Trim() == "" || this.AccessTokenBox.Text.Trim() == "")
        {
            this.ResultLabel.Text = "{ empty. }";
            return;
        }

        int    appid       = Int32.Parse(this.AppID.Text.Trim());
        string appkey      = this.AppKey.Text.Trim();
        string server_name = "openapi.tencentyun.com";//"119.147.19.43";//
        string openid      = this.OpenIDBox.Text.Trim();
        string openkey     = this.AccessTokenBox.Text.Trim();

        OpenApiV3 sdk = new OpenApiV3(appid, appkey);

        sdk.SetServerName(server_name);
        RstArray result = new RstArray();

        result = GetUserInfo(sdk, openid, openkey, "qzone");
        //Response.Write("<br>ret = " + result.Ret + "<br>msg = " + result.Msg);
        string      qqStr = result.Msg;
        QQInfoClass qq    = JsonHelper.JsonDeserialize <QQInfoClass>(qqStr);

        string    userStr = "";
        DataTable dt      = OAuthAccess.GetOAuthByOpenId(openid);

        if (dt.Rows.Count > 0)
        {
            int        userId = Int32.Parse(dt.Rows[0]["UserID"].ToString());
            UserEntity user   = UserAccess.GetUserById(userId);
            user.UserNickName = qq.nickname;
            user.UserImage    = qq.figureurl;
            bool success = UserAccess.UpdateUser(user);
            if (success)
            {
                userStr = "{ " + user.UserImage + " }";
            }
            else
            {
                userStr = "{ error. }";
            }
        }

        this.ResultLabel.Text = userStr + "<br><br>" + qqStr;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        userId = Int32.Parse(Session["UserID"].ToString());

        bool isBound = OAuthAccess.CheckOAuthBound(userId);

        //未绑定帐号跳转
        if (!isBound)
        {
            Response.Redirect("UserBoundAdmin.aspx");
        }

        if (!IsPostBack)
        {
            PopulateControls();
        }
    }
    //解除绑定
    protected void Button3_Command(object sender, CommandEventArgs e)
    {
        string[] str = e.CommandArgument.ToString().Split(',');

        int  oauthId   = Int32.Parse(str[0]);
        int  oldUserId = Int32.Parse(str[1]);
        bool success   = OAuthAccess.OAuthBoundCancel(oauthId, oldUserId);

        if (success)
        {
            PopulateControls();
            Utility.Alert(this, "解除成功。", "UserBoundAdmin.aspx");
        }
        else
        {
            Utility.Alert(this, "解除失败!");
        }
    }
Exemple #8
0
    protected void BindData()
    {
        string u = Request.QueryString["u"];

        UserEntity user = new UserEntity();

        user.UserName     = u + Utility.GetRandomNumber(10000, 99999);
        user.UserPassword = "******";
        user.UserNickName = Request.QueryString["name"] ?? "";
        user.UserImage    = Request.QueryString["image"] == "" ? "none.gif" : Request.QueryString["image"];
        user.UserEmail    = "";
        user.UserPhone    = "";
        user.UserTheme    = "main";
        user.UserFrom     = u;
        user.UserCity     = "";

        OAuthEntity oAuth = new OAuthEntity();

        oAuth.OpenID      = Request.QueryString["openId"];
        oAuth.AccessToken = Request.QueryString["accessToken"];
        oAuth.User        = user;
        oAuth.OAuthFrom   = u;
        oAuth.OAuthBound  = 0;

        bool success = OAuthAccess.CheckOAuthLogin(oAuth.OpenID);

        if (!success)
        {
            success = OAuthAccess.InsertOAuth(oAuth);
            if (!success)
            {
                Response.Write("自动登录错误!");
                Response.End();
            }
        }

        DataTable dt     = OAuthAccess.GetOAuthByOpenId(oAuth.OpenID);
        int       userId = Int32.Parse(dt.Rows[0]["UserID"].ToString());

        UserLogin(userId);

        Response.Redirect("/Default.aspx");
    }
    //绑定新帐号
    protected void NewButton_Click(object sender, EventArgs e)
    {
        string userName = this.UserNameNew.Text.Trim();

        if (!ValidHelper.CheckLength(userName, 2))
        {
            Utility.Alert(this, "用户名填写错误!");
            return;
        }

        bool repeat = UserAccess.CheckUserRepeat(userName);

        if (repeat)
        {
            Utility.Alert(this, "用户名重复!");
            return;
        }

        string userPassword = this.UserPasswordNew.Text.Trim();

        if (!ValidHelper.CheckLength(userPassword, 2))
        {
            Utility.Alert(this, "密码填写错误!");
            return;
        }

        bool success = OAuthAccess.OAuthBoundNew(userId, userName, userPassword);

        if (success)
        {
            PopulateControls();
            Utility.Alert(this, "绑定成功。", "UserBoundAdmin.aspx");
        }
        else
        {
            Utility.Alert(this, "绑定失败!");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string openId      = Request.Form["openid"].ToString();
        string accessToken = Request.Form["accesstoken"].ToString();
        string oAuthFrom   = Request.Form["oauthfrom"].ToString();
        string nickName    = Request.Form["nickname"].ToString();
        string userImage   = Request.Form["userimage"].ToString();
        int    type        = Int32.Parse(Request.Form["type"].ToString());

        string userFrom = "";

        if (oAuthFrom.Length > 4)
        {
            userFrom  = oAuthFrom.Replace("_", "");
            userFrom  = userFrom.Insert(4, "_");
            oAuthFrom = userFrom.Substring(0, 4);
        }
        else
        {
            userFrom = oAuthFrom;
        }

        UserEntity user = new UserEntity();

        user.UserName     = oAuthFrom + Utility.GetRandomNumber(10000, 99999);
        user.UserPassword = "******";
        user.UserNickName = nickName;
        user.UserImage    = (userImage == "" ? "none.gif" : userImage);
        user.UserEmail    = "";
        user.UserPhone    = "";
        user.UserTheme    = "main";
        user.UserFrom     = userFrom;
        user.UserCity     = "";

        OAuthEntity oAuth = new OAuthEntity();

        oAuth.OpenID      = openId;
        oAuth.AccessToken = accessToken;
        oAuth.User        = user;
        oAuth.OAuthFrom   = oAuthFrom;
        oAuth.OAuthBound  = 1;

        bool success = OAuthAccess.CheckOAuthLogin(oAuth.OpenID);

        if (!success)
        {
            success = OAuthAccess.InsertOAuth(oAuth);
            if (!success)
            {
                Response.Write("{\"result\":\"userid\":\"0\"}");
                Response.End();
            }
        }

        DataTable odt    = OAuthAccess.GetOAuthByOpenId(oAuth.OpenID);
        int       userId = Int32.Parse(odt.Rows[0]["UserID"].ToString());

        string result = "{";

        if (success)
        {
            user = UserAccess.GetUserById(userId);

            result += "\"userid\":\"" + userId + "\",";
            result += "\"username\":\"" + user.UserName + "\",";
            result += "\"userpass\":\"" + user.UserPassword + "\",";
            result += "\"usernickname\":\"" + user.UserNickName + "\",";
            result += "\"useremail\":\"" + user.UserEmail + "\",";
            result += "\"userphone\":\"" + user.UserPhone + "\",";
            result += "\"userimage\":\"" + user.UserImage + "\",";
            result += "\"userworkday\":\"" + user.UserWorkDay + "\",";
            result += "\"usermoney\":\"" + user.UserMoney + "\",";

            DataTable dt = null;
            if (type == 1)
            {
                dt = SyncHelper.SyncGetItemListWebFirst(userId);
            }
            else
            {
                dt = SyncHelper.SyncGetItemListWeb(userId);
            }
            if (dt.Rows.Count > 0)
            {
                result += "\"hassync\":\"1\",";
            }
            else
            {
                result += "\"hassync\":\"0\",";
            }

            result += "\"userbound\":\"1\"";
        }
        else
        {
            result += "\"userid\":\"0\",";
            result += "\"username\":\"\",";
            result += "\"userpass\":\"\",";
            result += "\"usernickname\":\"\",";
            result += "\"useremail\":\"\",";
            result += "\"userphone\":\"\",";
            result += "\"userimage\":\"\",";
            result += "\"userworkday\":\"\",";
            result += "\"usermoney\":\"0\",";
            result += "\"categoryrate\":\"0\",";
            result += "\"hassync\":\"0\",";
            result += "\"userbound\":\"0\"";
        }

        result += "}";

        Response.Write(result);
        Response.End();
    }
 protected void PopulateControls()
 {
     this.BoundList.DataSource = OAuthAccess.GetOAuthByUserId(userId);
     this.BoundList.DataBind();
 }