static DiscuzSessionHelper() { apikey = "9b65fc74182558a20ba076407dd928d9"; secret = "85a7c5dfd12364ffcda8b24f3f8ee713"; url = "http://localhost/"; ds = new DiscuzSession(apikey, secret, url); }
private void VerfyUser() { if (Session["DS"] != null) { ds = (DiscuzSession)Session["DS"]; } else { ds = new DiscuzSession(api, secret, url); } if (Request.QueryString["auth_token"] != null && Request.QueryString["auth_token"].ToString() != "") { //登录,成功后自动返回 try { //if (ds.GetUserInfo(ds.GetLoggedInUser().UId).GroupId != 1) //{ // lblResult.Text = "您不是管理员或管理组成员!"; // return; //} ds.session_info = ds.GetSessionFromToken(Request.QueryString["auth_token"].ToString()); Session["DS"] = ds; } catch { } //告诉用户登录成功 //Page.RegisterStartupScript("script", "<script>alert('登录成功');</script>"); } }
public static DiscuzSession GetMainSiteSession() { if (mainSiteDs == null) { mainSiteDs = new DiscuzSession(mainSiteInfo.Apikey, mainSiteInfo.Security, mainSiteInfo.WebsiteUrl); } return mainSiteDs; }
public void Login(string loginid, string password, bool isMD5Password, int expires, string cookieDomain) { DiscuzSession ds = new DiscuzSession(api, secret, url); int uid = ds.GetUserID(loginid); if (uid > 0) { ds.Login(uid, password, isMD5Password, expires, "www.92acg.cn"); } }
public void EditPassword(string username, string newMD5Password) { DiscuzSession ds = new DiscuzSession(api, secret, url); int uid = ds.GetUserID(username); if (uid > 0) { UserForEditing ufe = new UserForEditing(); ufe.Password = newMD5Password; ds.SetUserInfo(uid, ufe); } }
private void VerfyUser() { if (Session["DS"] != null) { ds = (DiscuzSession)Session["DS"]; } else { ds = new DiscuzSession(api, secret, url); } if (Request.QueryString["auth_token"] != null && Request.QueryString["auth_token"].ToString() != "") { //登录,成功后自动返回 try { ds.session_info = ds.GetSessionFromToken(Request.QueryString["auth_token"].ToString()); Session["DS"] = ds; } catch { } } if (ds.session_info == null) { if (Request.QueryString["user_status"] != null && Request.QueryString["user_status"].ToString() == "1") { //登录,成功后自动返回 Response.Redirect(ds.CreateToken().ToString()); return; } //提示用户登录、 //Page.RegisterStartupScript("script","<script>alert('请先登录');</script>"); Response.Redirect(url + "services/status.aspx?api_key=" + api); return; } if (ds.GetLoggedInUser().UId < 1) { ds.session_info = null; Response.Redirect(url + "services/status.aspx?api_key=" + api); needlogin = true; return; } }
//验证当前的AuthToken是否可用 public bool ValidateAuthToken(DiscuzSession ds, ref int Errorcode) { try { ds.session_info = ds.GetSessionFromToken(new HttpContextSession("AuthToken").GetSession().ToString()); Errorcode = 0; return true; } catch (DiscuzException d) { Errorcode = d.ErrorCode; return false; } catch (NullReferenceException) { Errorcode = 0; return false; } }
private void VerfyUser() { if (Session["DS"] != null) { ds = (DiscuzSession)Session["DS"]; } else { ds = new DiscuzSession(api, secret, url); } if (Request.QueryString["auth_token"] != null && Request.QueryString["auth_token"].ToString() != "") { //登录,成功后自动返回 try { //if (ds.GetUserInfo(ds.GetLoggedInUser().UId).GroupId != 1) //{ // lblResult.Text = "您不是管理员或管理组成员!"; // return; //} ds.session_info = ds.GetSessionFromToken(Request.QueryString["auth_token"].ToString()); Session["DS"] = ds; } catch { } //告诉用户登录成功 //Page.RegisterStartupScript("script", "<script>alert('登录成功');</script>"); } if (ds.session_info == null) { if (Request.QueryString["user_status"] != null && Request.QueryString["user_status"].ToString() == "1") { //登录,成功后自动返回 Response.Redirect(ds.CreateToken().ToString()); return; } //提示用户登录、 if (Util.GetQueryString("user_status") == "" ||Util.GetQueryString("user_status") == "0") { needlogin = true; return; } //提示用户登录、 //Page.RegisterStartupScript("script","<script>alert('请先登录');</script>"); Response.Redirect(url + "services/status.aspx?api_key=" + api); return; } if (ds.GetLoggedInUser().UId < 1) { ds.session_info = null; Response.Redirect(url + "services/status.aspx?api_key=" + api); needlogin = true; return; } if (ds.GetUserInfo(ds.GetLoggedInUser().UId).Adminid != 1) { ds.session_info = null; lblResult.Text = "<font color='red'><b>很抱歉,你没有使用此功能的权限!</b></font>"; return; } }
public Friend(long UId, DiscuzSession session) { this.UId = UId; this.Session = session; }
public void Register(string username, string password, string email, bool isMD5Password) { DiscuzSession ds = new DiscuzSession(api, secret, url); ds.Register(username, password, email, isMD5Password); }
public void Logout(string cookieDomain) { DiscuzSession ds = new DiscuzSession(api, secret, url); ds.Logout("92acg.cn"); }
public Me(long uid, DiscuzSession session) : base(uid, session) { }
public int IsUserExits(string loginid) { DiscuzSession ds = new DiscuzSession(api, secret, url); return ds.GetUserID(loginid); }
//验证当前的AuthToken是否可用 public bool ValidateAuthToken(DiscuzSession ds, ref int Errorcode) { try { if (Request.Cookies["dnt"] != null) { ds.session_info = ds.GetSessionFromToken(Session["AuthToken"].ToString()); } else { needlogin = true; } Errorcode = 0; return true; } catch (DiscuzException d) { Errorcode = d.ErrorCode; return false; } catch (NullReferenceException) { Errorcode = 0; return false; } }
public SendTopic() { string api = "bd944d19dd425d7b842a6e7820b29fa1"; string secret = "ed2cd183020c8b54a5148e46b4c1a9cc"; string url = "http://localhost/"; DataSet dataset; TopicCreateResponse tcr = null; string title = "", message = ""; string sLine = ""; string cur_date = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); string str_path = HttpContext.Current.Server.MapPath("~/plugin/Spinder/Spinder_WEB/Users.txt"); //AppDomain.CurrentDomain.BaseDirectory + "Users.txt"; StreamReader reader = new StreamReader(str_path);//fds,rd,fdfd,hj-用户名|131-fid\r\n sLine = reader.ReadToEnd().Trim(); DiscuzSession ds = new DiscuzSession(api, secret, url); if (sLine.Length == 0) { dataset = new DataSet(); string path = HttpContext.Current.Server.MapPath("~/plugin/Spinder/Spinder_WEB/"+ cur_date +"/" + cur_date +"XmlData.xml");//AppDomain.CurrentDomain.BaseDirectory +"XmlData.xml"; dataset.ReadXml(path); for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { title = dataset.Tables[0].Rows[i]["title"].ToString().Trim(); message = dataset.Tables[0].Rows[i]["content"].ToString().Trim(); if (title.Length > 60) { title = title.Substring(0, 58); } tcr = ds.CreateTopic(1, title, 162, message, 0, ""); } } if (sLine.EndsWith("\r\n")) { sLine = sLine.Substring(sLine.Length - 4, sLine.Length).Trim(); } string[] one_group = sLine.Split('|'); int fid = Convert.ToInt32(one_group[1]) ; for (int j = 0; j < one_group.Length; j++) { int random; string users = one_group[j].ToString().Split('|')[0]; //int fid = Convert.ToInt32(one_group[j].ToString().Split('|')[1]); Random r = new Random(); dataset = new DataSet(); string path = HttpContext.Current.Server.MapPath("~/plugin/Spinder/Spinder_WEB/"+ cur_date +"/"+ cur_date +"XmlData.xml");//AppDomain.CurrentDomain.BaseDirectory +"XmlData.xml"; dataset.ReadXml(path); for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { random = r.Next(0, users.Split(',').Length); title = dataset.Tables[0].Rows[i]["title"].ToString().Trim(); message = dataset.Tables[0].Rows[i]["content"].ToString().Trim(); if (title.Length > 60) { title = title.Substring(0, 58); } int curuid = ds.GetUserID(users.Split(',')[random].ToString()); if (curuid < 1) { continue; } tcr = ds.CreateTopic(curuid, title, fid, message, 0, ""); } } }
private void VerfyUser() { DiscuzSession ds = new DiscuzSession(api, secret, url); try { ds.GetSessionFromToken(Request.QueryString["auth_token"]); } catch (DiscuzException de) { if (de.ErrorCode == 102) { Uri uri = ds.CreateToken(); Response.Redirect(uri.ToString()); } else { throw de; } } User user = ds.GetUserInfo(ds.GetLoggedInUser().UId); if (user.GroupId != 1)//不是管理员 { Response.Redirect("UrlConfig.aspx"); } }
//获取AuthToken public void GetAuthToken(string n, DiscuzSession ds) { Response.Redirect(ds.CreateToken().ToString() + "&next=" + n); }
private void UserAuthrity() { ds = new DiscuzSession(api_key, secret, url); int errorcode = 0; string next = ""; try { if (Request["tid"] != null && Request["pageindex"] != null) next = Request["tid"] + "," + Request["pageindex"]; Session["AuthToken"] = Request.QueryString["auth_token"].ToString(); } catch { } if (!ValidateAuthToken(ds, ref errorcode)) { GetAuthToken(next, ds); } }