/// <summary> /// 会员登陆 /// </summary> /// <param name="UserName">账号</param> /// <param name="Password">密码</param> /// <param name="CookieDay">过期时间(天)</param> /// <returns></returns> public Result UserLogin(string UserName, string Password, int CookieDay) { Result r = new Result(); UserName = UserName.TrimDbDangerousChar(); Password = Password.TrimDbDangerousChar(); if (UserName.IsNullOrEmpty()) { r.Success = false; r.Text = "账号不能为空!"; return(r); } if (Password.IsNullOrEmpty()) { r.Success = false; r.Text = "密码不能为空!"; return(r); } User _user = UserView.Find(string.Format("UserName='******'", UserName)); if (_user.ID > 0) { if (_user.UserPass == Voodoo.Security.Encrypt.Md5(Password)) { if (_user.Enable == false) { r.Success = false; r.Text = "您的帐号还没有经过审核,请耐心等待审核通过后登录"; return(r); } //成功! //写入Cookie System.Web.HttpCookie cookie = new System.Web.HttpCookie("User"); cookie.Expires = DateTime.Now.AddDays(CookieDay); cookie.Values.Add("uid", _user.ID.ToString()); cookie.Values.Add("k", Voodoo.Security.Encrypt.Md5(string.Format("{0}{1}{2}", _user.ID, _user.UserName, _user.UserPass, BasePage.SystemSetting.SiteName ))); Cookies.Cookies.SetCookie(cookie); _user.LastLoginIP = WS.GetIP(); _user.LastLoginTime = DateTime.Now; _user.LoginCount += 1; UserView.Update(_user); r.Success = true; r.Text = "登陆成功!"; return(r); } } r.Success = false; r.Text = "您输入的账号或密码错误"; return(r); }
/// <summary> /// QQ用户登录 /// </summary> protected void QQLogin() { if (Request.Params["code"] != null) { QOpenClient qzone = null; User currentUser = null; var verifier = Request.Params["code"]; string state = Session["requeststate"].ToString(); qzone = new QOpenClient(verifier, state); // currentUser = qzone.GetCurrentUser(); if (null != currentUser) { string openid = qzone.OAuthToken.OpenId; var SysUser = UserView.Find(string.Format("UserName=N'{0}'", openid)); if (SysUser.ID <= 0) { SysUser.Cent = SystemSetting.RegCent; SysUser.ChineseName = currentUser.Nickname; SysUser.Enable = true; SysUser.Group = 0; SysUser.Image = currentUser.Figureurl; SysUser.LastLoginIP = WS.GetIP(); SysUser.LastLoginTime = DateTime.UtcNow.AddHours(8); SysUser.LoginCount = 1; SysUser.PostCount = 0; SysUser.RegIP = WS.GetIP(); SysUser.RegTime = DateTime.UtcNow.AddHours(8); SysUser.StudentNo = ""; SysUser.TeachNo = ""; SysUser.Tel = ""; SysUser.Twitter = ""; SysUser.UserName = openid; SysUser.UserPass = ""; SysUser.WebSite = ""; SysUser.Weibo = ""; try { var i = qzone.GetWeiboUserInfo("", qzone.OAuthToken.OpenId); SysUser.Address = i.Data.Location; SysUser.Email = i.Data.Email; SysUser.Intro = i.Data.Introduction; SysUser.ZipCode = i.Data.City_code.ToS(); } catch { } UserView.Insert(SysUser); } else { SysUser.LoginCount++; SysUser.LastLoginIP = WS.GetIP(); SysUser.LastLoginTime = DateTime.UtcNow.AddHours(8); UserView.Update(SysUser); } //System.Web.HttpContext.Current.Session["sys_user"] = SysUser.ID; System.Web.HttpCookie cookie = new System.Web.HttpCookie("User"); cookie.Expires = DateTime.Now.AddDays(7); cookie.Values.Add("uid", SysUser.ID.ToString()); cookie.Values.Add("k", Voodoo.Security.Encrypt.Md5(string.Format("{0}{1}{2}", SysUser.ID, SysUser.UserName, SysUser.UserPass, BasePage.SystemSetting.SiteName ))); Voodoo.Cookies.Cookies.SetCookie(cookie); Response.Redirect("/"); } Session["QzoneOauth"] = qzone; } }