/// <summary> /// 在论坛注册一个新用户并绑定 /// </summary> private void RegisterAndBind() { if (userid > 0) { AddErrLine("当前已有用户登录,无法注册"); return; } if (config.Regstatus < 1 || cloudconfig.Allowconnectregister == 0) { AddErrLine("论坛当前禁止新的QQ会员登录"); return; } string tmpUserName = DNTRequest.GetString(config.Antispamregisterusername); string email = DNTRequest.GetString(config.Antispamregisteremail).Trim().ToLower(); string tmpBday = DNTRequest.GetString("bday").Trim(); string errorMessage = ""; if (!Users.PageValidateUserName(tmpUserName, out errorMessage) || !Users.PageValidateEmail(email, false, out errorMessage)) { AddErrLine(errorMessage); return; } //用户注册模板中,生日可以单独用一个名为bday的文本框, 也可以分别用bday_y bday_m bday_d三个文本框, 用户可不填写 if (!Utils.IsDateString(tmpBday) && !string.IsNullOrEmpty(tmpBday)) { AddErrLine("生日格式错误, 如果不想填写生日请置空"); return; } //如果用户名符合注册规则, 则判断是否已存在 if (Users.GetUserId(tmpUserName) > 0) { AddErrLine("请不要重复提交!"); return; } //读取当前用户的OPENID信息 userconnectinfo = DiscuzCloud.GetUserConnectInfo(openid); if (userconnectinfo == null || userconnectinfo.Uid > 0) { AddErrLine("Connect信息异常,登录失败,请尝试再次登录"); return; } UserBindConnectLog bindLog = DiscuzCloud.GetUserConnectBindLog(userconnectinfo.OpenId); if (cloudconfig.Maxuserbindcount != 0 && bindLog != null && (bindLog.Type != 1 && bindLog.BindCount >= cloudconfig.Maxuserbindcount)) { AddErrLine("当前QQ用户解绑次数过多,无法绑定新注册的用户"); return; } UserInfo userInfo = CreateUser(tmpUserName, email, tmpBday); userconnectinfo.Uid = userInfo.Uid; DiscuzCloud.UpdateUserConnectInfo(userconnectinfo); if (bindLog == null) { bindLog = new UserBindConnectLog(); bindLog.OpenId = userconnectinfo.OpenId; bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; bindLog.BindCount = 1; DiscuzCloud.CreateUserConnectBindLog(bindLog); } else { bindLog.BindCount++; bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; DiscuzCloud.UpdateUserConnectBindLog(bindLog); } #region 发送欢迎信息 if (config.Welcomemsg == 1) { // 收件箱 PrivateMessageInfo privatemessageinfo = new PrivateMessageInfo(); privatemessageinfo.Message = config.Welcomemsgtxt; privatemessageinfo.Subject = "欢迎您的加入! (请勿回复本信息)"; privatemessageinfo.Msgto = userInfo.Username; privatemessageinfo.Msgtoid = userInfo.Uid; privatemessageinfo.Msgfrom = PrivateMessages.SystemUserName; privatemessageinfo.Msgfromid = 0; privatemessageinfo.New = 1; privatemessageinfo.Postdatetime = Utils.GetDateTime(); privatemessageinfo.Folder = 0; PrivateMessages.CreatePrivateMessage(privatemessageinfo, 0); } #endregion //发送同步数据给应用程序 Sync.UserRegister(userInfo.Uid, userInfo.Username, userInfo.Password, ""); //如果用户选择使用QZone头像 if (cloudconfig.Allowuseqzavater == 1 && DNTRequest.GetString("use_qzone_avatar") == "1") { QZoneAvatar qz = new QZoneAvatar(); qz.AsyncGetAvatar(userconnectinfo); } SetUrl("index.aspx"); SetShowBackLink(false); //如果不是需要管理员审核的注册,页面延时刷新为2秒,否则是5秒 SetMetaRefresh(config.Regverify != 2 ? 2 : 5); Statistics.ReSetStatisticsCache(); if (config.Regverify != 2) { CreditsFacade.UpdateUserCredits(userInfo.Uid); ForumUtils.WriteUserCookie(userInfo, -1, config.Passwordkey); Utils.WriteCookie("bindconnect", "true");//将当前登录用户是否绑定QQ互联的状态设置为true OnlineUsers.UpdateAction(olid, UserAction.Register.ActionID, 0, config.Onlinetimeout); AddMsgLine("QQ登录成功,继续浏览"); } else { AddMsgLine("QQ数据绑定完成, 但需要系统管理员审核您的帐户后才可登录使用"); } notifyscript = GetNotifyScript(userconnectinfo, userInfo.Username, userInfo.Bday, userInfo.Gender, userInfo.Email, userInfo.Showemail, DNTRequest.GetInt("useqqavatar", 2), "register"); }
/// <summary> /// 绑定论坛已存在的用户 /// </summary> private void BindForumExistedUser() { if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5) { AddErrLine("您已经多次输入密码错误, 请15分钟后再登录"); return; } if (config.Emaillogin == 1 && Utils.IsValidEmail(postusername)) { DataTable dt = Users.GetUserInfoByEmail(postusername); if (dt.Rows.Count == 0) { AddErrLine("用户不存在"); return; } if (dt.Rows.Count > 1) { AddErrLine("您所使用Email不唯一,请使用用户名登陆"); return; } if (dt.Rows.Count == 1) { postusername = dt.Rows[0]["username"].ToString(); } } if (config.Emaillogin == 0) { if ((Users.GetUserId(postusername) == 0)) AddErrLine("用户不存在"); } if (string.IsNullOrEmpty(postpassword)) AddErrLine("密码不能为空"); if (IsErr()) return; ShortUserInfo userInfo = GetShortUserInfo(); if (userInfo != null) { #region 当前用户所在用户组为"禁止访问"或"等待激活"时 if ((userInfo.Groupid == 4 || userInfo.Groupid == 5) && userInfo.Groupexpiry != 0 && userInfo.Groupexpiry <= Utils.StrToInt(DateTime.Now.ToString("yyyyMMdd"), 0)) { //根据当前用户的积分获取对应积分用户组 UserGroupInfo groupInfo = CreditsFacade.GetCreditsUserGroupId(userInfo.Credits); usergroupid = groupInfo.Groupid != 0 ? groupInfo.Groupid : usergroupid; userInfo.Groupid = usergroupid; Users.UpdateUserGroup(userInfo.Uid, usergroupid); } if (userInfo.Groupid == 5)// 5-禁止访问 { AddErrLine("该用户已经被禁止访问,无法绑定"); return; } #endregion //读取当前用户的OPENID信息 userconnectinfo = DiscuzCloud.GetUserConnectInfo(openid); if (userconnectinfo == null || userconnectinfo.Uid > 0) { AddErrLine("Connect信息异常,登录失败,请尝试再次登录"); return; } if (DiscuzCloud.IsBindConnect(userInfo.Uid)) { AddErrLine("该用户已经绑定了QQ,无法再次绑定"); return; } userconnectinfo.Uid = userInfo.Uid; userconnectinfo.IsSetPassword = 1; DiscuzCloud.UpdateUserConnectInfo(userconnectinfo); UserBindConnectLog bindLog = DiscuzCloud.GetUserConnectBindLog(userconnectinfo.OpenId); if (bindLog == null) { bindLog = new UserBindConnectLog(); bindLog.OpenId = userconnectinfo.OpenId; bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; bindLog.BindCount = 1; DiscuzCloud.CreateUserConnectBindLog(bindLog); } else { bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; DiscuzCloud.UpdateUserConnectBindLog(bindLog); } if (userInfo.Groupid != 8) { LoginUser(userInfo); AddMsgLine("QQ登录成功,继续浏览"); } else { AddMsgLine("帐号绑定成功,但需要管理员审核通过才能登录"); } SetUrl("index.aspx"); SetMetaRefresh(); SetShowBackLink(false); notifyscript = GetNotifyScript(userconnectinfo, userInfo.Username, userInfo.Bday, userInfo.Gender, userInfo.Email, userInfo.Showemail, DNTRequest.GetInt("useqqavatar", 2), "registerbind"); return; } else { int errcount = LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true); if (errcount > 5) AddErrLine("您已经输入密码5次错误, 请15分钟后再试"); else AddErrLine(string.Format("密码或安全提问第{0}次错误, 您最多有5次机会重试", errcount)); } if (IsErr()) return; }
/// <summary> /// 绑定当前在线用户 /// </summary> private void BindLoginedUser() { userconnectinfo = DiscuzCloud.GetUserConnectInfo(openid); if (userconnectinfo == null || userconnectinfo.Uid > 0) { AddErrLine("Connect信息异常,登录失败,请尝试再次登录"); return; } if (DiscuzCloud.IsBindConnect(userid)) { AddErrLine("该用户已经绑定了QQ,无法再次绑定"); return; } userconnectinfo.Uid = userid; userconnectinfo.IsSetPassword = 1; DiscuzCloud.UpdateUserConnectInfo(userconnectinfo); UserBindConnectLog bindLog = DiscuzCloud.GetUserConnectBindLog(userconnectinfo.OpenId); if (bindLog == null) { bindLog = new UserBindConnectLog(); bindLog.OpenId = userconnectinfo.OpenId; bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; bindLog.BindCount = 1; DiscuzCloud.CreateUserConnectBindLog(bindLog); } else { bindLog.Uid = userconnectinfo.Uid; bindLog.Type = 1; DiscuzCloud.UpdateUserConnectBindLog(bindLog); } SetUrl("index.aspx"); SetMetaRefresh(); SetShowBackLink(false); AddMsgLine("QQ绑定成功,继续浏览"); Utils.WriteCookie("bindconnect", "true");//将当前登录用户是否绑定QQ互联的状态设置为true ShortUserInfo userInfo = Users.GetShortUserInfo(userid); notifyscript = GetNotifyScript(userconnectinfo, userInfo.Username, userInfo.Bday, userInfo.Gender, userInfo.Email, userInfo.Showemail, DNTRequest.GetInt("useqqavatar", 2), "loginbind"); }
/// <summary> /// 获取用户绑定QQ的记录 /// </summary> /// <param name="openId"></param> /// <returns></returns> public static UserBindConnectLog GetUserConnectBindLog(string openId) { IDataReader reader = DatabaseProvider.GetInstance().GetUserConnectBindLog(openId); UserBindConnectLog bindLog = null; if (reader.Read()) { bindLog = new UserBindConnectLog(); bindLog.OpenId = reader["openid"].ToString(); bindLog.Uid = TypeConverter.ObjectToInt(reader["uid"]); bindLog.Type = TypeConverter.ObjectToInt(reader["type"]); bindLog.BindCount = TypeConverter.ObjectToInt(reader["bindcount"]); reader.Close(); } return bindLog; }
/// <summary> /// 更新用户绑定QQ的记录 /// </summary> /// <param name="bindLog"></param> /// <returns></returns> public static int UpdateUserConnectBindLog(UserBindConnectLog bindLog) { return DatabaseProvider.GetInstance().UpdateUserConnectBindLog(bindLog); }
/// <summary> /// 更新用户绑定QQ的记录 /// </summary> /// <param name="bindLog"></param> /// <returns></returns> public int UpdateUserConnectBindLog(UserBindConnectLog bindLog) { DbParameter[] parms = { DbHelper.MakeInParam("@openid",(DbType)SqlDbType.Char,32,bindLog.OpenId), DbHelper.MakeInParam("@uid",(DbType)SqlDbType.Int,4,bindLog.Uid), DbHelper.MakeInParam("@type",(DbType)SqlDbType.SmallInt,4,bindLog.Type), DbHelper.MakeInParam("@bindcount",(DbType)SqlDbType.SmallInt,4,bindLog.BindCount) }; return DbHelper.ExecuteNonQuery(CommandType.StoredProcedure, string.Format("{0}updatebindlog", BaseConfigs.GetTablePrefix), parms); }