/// <summary> /// 判断用户是否已经登录(解决Session超时问题) /// </summary> public bool IsUserLogin() { //如果Session为Null if (HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] != null) { return true; } else { //检查Cookies string username = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms"); //解密用户名 string password = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms"); if (username != "" && password != "") { Hoto.BLL.users bll = new Hoto.BLL.users(); Hoto.Model.users model = bll.GetModel(username, password, 0); if (model != null) { HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; return true; } } } return false; }
/// <summary> /// 判断用户是否已经登录(解决Session超时问题) /// </summary> public bool IsUserLogin() { //如果Session为Null if (HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] != null) { return(true); } else { //检查Cookies string username = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms"); //解密用户名 string password = HotoUtils.GetCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms"); if (username != "" && password != "") { Hoto.BLL.users bll = new Hoto.BLL.users(); Hoto.Model.users model = bll.GetModel(username, password, 0); if (model != null) { HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; return(true); } } } return(false); }
/// <summary> /// 返回用户头像图片地址 /// </summary> /// <param name="user_name">用户名</param> /// <returns>String</returns> protected string get_user_avatar(string user_name) { Hoto.BLL.users bll = new Hoto.BLL.users(); if (!bll.Exists(user_name)) { return(""); } return(bll.GetModel(user_name).avatar); }
/// <summary> /// 返回用户头像图片地址 /// </summary> /// <param name="user_name">用户名</param> /// <returns>String</returns> protected string get_user_avatar(string user_name) { Hoto.BLL.users bll = new Hoto.BLL.users(); if (!bll.Exists(user_name)) { return ""; } return bll.GetModel(user_name).avatar; }
/// <summary> /// 取得用户信息 /// </summary> public Hoto.Model.users GetUserInfo() { if (IsUserLogin()) { Hoto.Model.users model = HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] as Hoto.Model.users; if (model != null) { //为了能查询到最新的用户信息,必须查询最新的用户资料 model = new Hoto.BLL.users().GetModel(model.id); return model; } } return null; }
/// <summary> /// 取得用户信息 /// </summary> public Hoto.Model.users GetUserInfo() { if (IsUserLogin()) { Hoto.Model.users model = HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] as Hoto.Model.users; if (model != null) { //为了能查询到最新的用户信息,必须查询最新的用户资料 model = new Hoto.BLL.users().GetModel(model.id); return(model); } } return(null); }
/// <summary> /// OnInit事件,检查用户是否已经登录 /// </summary> void UserPage_Init(object sender, EventArgs e) { turl = HotoUtils.GetCookie(HotoKeys.COOKIE_URL_REFERRER); if (string.IsNullOrEmpty(turl) || turl == HttpContext.Current.Request.Url.ToString().ToLower()) { turl = linkurl("usercenter", "index"); } if (IsUserLogin()) { //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } //检查是否已授权 if (HttpContext.Current.Session["oauth_name"] == null || HttpContext.Current.Session["oauth_access_token"] == null || HttpContext.Current.Session["oauth_openid"] == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,用户授权已过期,请重新登录!")); return; } Hoto.Model.user_oauth oauthModel = new Hoto.BLL.user_oauth().GetModel(HttpContext.Current.Session["oauth_name"].ToString(), HttpContext.Current.Session["oauth_openid"].ToString()); if (oauthModel != null) { //检查用户是否存在 Hoto.Model.users model = new Hoto.BLL.users().GetModel(oauthModel.user_name); if (model == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,授权用户不存在或已被删除!")); return; } //记住登录状态,防止Session提前过期 HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; HttpContext.Current.Session.Timeout = 45; HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name); HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password); //更新最新的Access Token oauthModel.oauth_access_token = HttpContext.Current.Session["oauth_access_token"].ToString(); new Hoto.BLL.user_oauth().Update(oauthModel); //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } }
/// <summary> /// OnInit事件,检查用户是否已经登录 /// </summary> void UserPage_Init(object sender, EventArgs e) { turl = HotoUtils.GetCookie(HotoKeys.COOKIE_URL_REFERRER); if (string.IsNullOrEmpty(turl) || turl == HttpContext.Current.Request.Url.ToString().ToLower()) { turl = linkurl("usercenter", "index"); } if (IsUserLogin()) { //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } //检查是否已授权 if (HttpContext.Current.Session["oauth_name"] == null || HttpContext.Current.Session["oauth_access_token"] == null || HttpContext.Current.Session["oauth_openid"] == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,用户授权已过期,请重新登录!")); return; } Hoto.Model.user_oauth oauthModel = new Hoto.BLL.user_oauth().GetModel(HttpContext.Current.Session["oauth_name"].ToString(), HttpContext.Current.Session["oauth_openid"].ToString()); if (oauthModel != null) { //检查用户是否存在 Hoto.Model.users model = new Hoto.BLL.users().GetModel(oauthModel.user_name); if (model == null) { HttpContext.Current.Response.Redirect(config.webpath + "error.aspx?msg=" + HotoUtils.UrlEncode("登录失败,授权用户不存在或已被删除!")); return; } //记住登录状态,防止Session提前过期 HttpContext.Current.Session[HotoKeys.SESSION_USER_INFO] = model; HttpContext.Current.Session.Timeout = 45; HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name); HotoUtils.WriteCookie(HotoKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password); //更新最新的Access Token oauthModel.oauth_access_token = HttpContext.Current.Session["oauth_access_token"].ToString(); new Hoto.BLL.user_oauth().Update(oauthModel); //自动登录,跳转URL HttpContext.Current.Response.Redirect(turl); return; } }