private void user_oauth_register(HttpContext context) { //检查URL参数 if (context.Session["oauth_name"] == null) { context.Response.Write("{\"status\": 0, \"msg\": \"错误提示:授权参数不正确!\"}"); return; } //获取授权信息 string result = Utils.UrlExecute(siteConfig.webpath + "api/oauth/" + context.Session["oauth_name"].ToString() + "/result_json.aspx"); if (result.Contains("error")) { context.Response.Write("{\"status\": 0, \"msg\": \"错误提示:请检查URL是否正确!\"}"); return; } string password = DTRequest.GetFormString("txtPassword").Trim(); string email = Utils.ToHtml(DTRequest.GetFormString("txtEmail").Trim()); string mobile = Utils.ToHtml(DTRequest.GetFormString("txtMobile").Trim()); string userip = DTRequest.GetIP(); //反序列化JSON Dictionary<string, object> dic = JsonHelper.DataRowFromJSON(result); if (dic["ret"].ToString() != "0") { context.Response.Write("{\"status\": 0, \"msg\": \"错误代码:" + dic["ret"] + "," + dic["msg"] + "\"}"); return; } BLL.users bll = new BLL.users(); Model.users model = new Model.users(); //如果开启手机登录要验证手机 if (userConfig.mobilelogin == 1 && !string.IsNullOrEmpty(mobile)) { if (bll.ExistsMobile(mobile)) { context.Response.Write("{\"status\":0, \"msg\":\"对不起,该手机号码已被使用!\"}"); return; } } //如果开启邮箱登录要验证邮箱 if (userConfig.emaillogin == 1 && !string.IsNullOrEmpty(email)) { if (bll.ExistsEmail(email)) { context.Response.Write("{\"status\":0, \"msg\":\"对不起,该电子邮箱已被使用!\"}"); return; } } //检查默认组别是否存在 Model.user_groups modelGroup = new BLL.user_groups().GetDefault(); if (modelGroup == null) { context.Response.Write("{\"status\":0, \"msg\":\"用户尚未分组,请联系管理员!\"}"); return; } //保存注册信息 model.group_id = modelGroup.id; model.user_name = bll.GetRandomName(10); //随机用户名 model.salt = Utils.GetCheckCode(6); //获得6位的salt加密字符串 model.password = DESEncrypt.Encrypt(password, model.salt); model.email = email; model.mobile = mobile; if (!string.IsNullOrEmpty(dic["nick"].ToString())) { model.nick_name = dic["nick"].ToString(); } if (dic["avatar"].ToString().StartsWith("http://")) { model.avatar = dic["avatar"].ToString(); } if (!string.IsNullOrEmpty(dic["sex"].ToString())) { model.sex = dic["sex"].ToString(); } if (!string.IsNullOrEmpty(dic["birthday"].ToString())) { model.birthday = Utils.StrToDateTime(dic["birthday"].ToString()); } model.reg_ip = userip; model.reg_time = DateTime.Now; model.status = 0; //设置为正常状态 model.id = bll.Add(model); //保存数据 if (model.id < 1) { context.Response.Write("{\"status\":0, \"msg\":\"注册失败,请联系网站管理员!\"}"); return; } //赠送积分金额 if (modelGroup.point > 0) { new BLL.user_point_log().Add(model.id, model.user_name, modelGroup.point, "注册赠送积分", false); } if (modelGroup.amount > 0) { new BLL.user_amount_log().Add(model.id, model.user_name, modelGroup.amount, "注册赠送金额"); } //判断是否发送欢迎消息 if (userConfig.regmsgstatus == 1) //站内短消息 { new BLL.user_message().Add(1, "", model.user_name, "欢迎您成为本站会员", userConfig.regmsgtxt); } else if (userConfig.regmsgstatus == 2) //发送邮件 { //取得邮件模板内容 Model.mail_template mailModel = new BLL.mail_template().GetModel("welcomemsg"); if (mailModel != null) { //替换标签 string mailTitle = mailModel.maill_title; mailTitle = mailTitle.Replace("{username}", model.user_name); string mailContent = mailModel.content; mailContent = mailContent.Replace("{webname}", siteConfig.webname); mailContent = mailContent.Replace("{weburl}", siteConfig.weburl); mailContent = mailContent.Replace("{webtel}", siteConfig.webtel); mailContent = mailContent.Replace("{username}", model.user_name); //发送邮件 DTMail.sendMail(siteConfig.emailsmtp, siteConfig.emailssl, siteConfig.emailusername, siteConfig.emailpassword, siteConfig.emailnickname, siteConfig.emailfrom, model.email, mailTitle, mailContent); } } else if (userConfig.regmsgstatus == 3 && mobile != "") //发送短信 { Model.sms_template smsModel = new BLL.sms_template().GetModel("welcomemsg"); //取得短信内容 if (smsModel != null) { //替换标签 string msgContent = smsModel.content; msgContent = msgContent.Replace("{webname}", siteConfig.webname); msgContent = msgContent.Replace("{weburl}", siteConfig.weburl); msgContent = msgContent.Replace("{webtel}", siteConfig.webtel); msgContent = msgContent.Replace("{username}", model.user_name); //发送短信 string tipMsg = string.Empty; new BLL.sms_message().Send(model.mobile, msgContent, 2, out tipMsg); } } //绑定到对应的授权类型 Model.user_oauth oauthModel = new Model.user_oauth(); oauthModel.oauth_name = dic["oauth_name"].ToString(); oauthModel.user_id = model.id; oauthModel.user_name = model.user_name; oauthModel.oauth_access_token = dic["oauth_access_token"].ToString(); oauthModel.oauth_openid = dic["oauth_openid"].ToString(); new BLL.user_oauth().Add(oauthModel); context.Session[DTKeys.SESSION_USER_INFO] = model; context.Session.Timeout = 45; //记住登录状态,防止Session提前过期 Utils.WriteCookie(DTKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name); Utils.WriteCookie(DTKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password); //写入登录日志 new BLL.user_login_log().Add(model.id, model.user_name, "会员登录"); //返回URL context.Response.Write("{\"status\":1, \"msg\":\"会员登录成功!\"}"); return; }
private void user_oauth_register(HttpContext context) { //检查URL参数 if (context.Session["oauth_name"] == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"错误提示:授权参数不正确!\"}"); return; } //获取授权信息 string result = Utils.UrlExecute(siteConfig.webpath + "api/oauth/" + context.Session["oauth_name"].ToString() + "/result_json.aspx"); if (result.Contains("error")) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"错误提示:请检查URL是否正确!\"}"); return; } //反序列化JSON Dictionary<string, object> dic = JsonMapper.ToObject<Dictionary<string, object>>(result); if (dic["ret"].ToString() != "0") { context.Response.Write("{\"msg\": 0, \"msgbox\": \"错误代码:" + dic["ret"] + "," + dic["msg"] + "\"}"); return; } string password = DTRequest.GetFormString("txtPassword").Trim(); string email = DTRequest.GetFormString("txtEmail").Trim(); string userip = DTRequest.GetIP(); //检查用户名 BLL.users bll = new BLL.users(); Model.users model = new Model.users(); //检查默认组别是否存在 Model.user_groups modelGroup = new BLL.user_groups().GetDefault(); if (modelGroup == null) { context.Response.Write("{\"msg\":0, \"msgbox\":\"系统尚未分组,请联系管理员设置会员分组!\"}"); return; } //保存注册信息 model.group_id = modelGroup.id; model.user_name = bll.GetRandomName(10); model.password = DESEncrypt.Encrypt(password); model.email = email; if (!string.IsNullOrEmpty(dic["nick"].ToString())) { model.nick_name = dic["nick"].ToString(); } if (dic["avatar"].ToString().StartsWith("http://")) { model.avatar = dic["avatar"].ToString(); } if (!string.IsNullOrEmpty(dic["sex"].ToString())) { model.sex = dic["sex"].ToString(); } if (!string.IsNullOrEmpty(dic["birthday"].ToString())) { model.birthday = DateTime.Parse(dic["birthday"].ToString()); } model.reg_ip = userip; model.reg_time = DateTime.Now; model.is_lock = 0; //设置为对应状态 int newId = bll.Add(model); if (newId < 1) { context.Response.Write("{\"msg\":0, \"msgbox\":\"系统故障,注册失败,请联系网站管理员!\"}"); return; } model = bll.GetModel(newId); //赠送积分金额 if (modelGroup.point > 0) { new BLL.point_log().Add(model.id, model.user_name, modelGroup.point, "注册赠送积分"); } if (modelGroup.amount > 0) { new BLL.amount_log().Add(model.id, model.user_name, DTEnums.AmountTypeEnum.SysGive.ToString(), modelGroup.amount, "注册赠送金额", 1); } //判断是否发送站内短消息 if (userConfig.regmsgstatus == 1) { new BLL.user_message().Add(1, "", model.user_name, "欢迎您成为本站会员", userConfig.regmsgtxt); } //绑定到对应的授权类型 Model.user_oauth oauthModel = new Model.user_oauth(); oauthModel.oauth_name = dic["oauth_name"].ToString(); oauthModel.user_id = model.id; oauthModel.user_name = model.user_name; oauthModel.oauth_access_token = dic["oauth_access_token"].ToString(); oauthModel.oauth_openid = dic["oauth_openid"].ToString(); new BLL.user_oauth().Add(oauthModel); context.Session[DTKeys.SESSION_USER_INFO] = model; context.Session.Timeout = 45; //记住登录状态,防止Session提前过期 Utils.WriteCookie(DTKeys.COOKIE_USER_NAME_REMEMBER, "DTcms", model.user_name); Utils.WriteCookie(DTKeys.COOKIE_USER_PWD_REMEMBER, "DTcms", model.password); //写入登录日志 new BLL.user_login_log().Add(model.id, model.user_name, "会员登录", DTRequest.GetIP()); //返回URL context.Response.Write("{\"msg\":1, \"msgbox\":\"会员登录成功!\"}"); return; }
private void user_oauth_register(HttpContext context) { //检查URL参数 if (context.Session["oauth_name"] == null) { context.Response.Write("{\"status\": 0, \"msg\": \"错误提示:授权参数不正确!\"}"); return; } //获取授权信息 string result = Vincent._DTcms.Utils.UrlExecute(siteConfig.webpath + "api/oauth/" + context.Session["oauth_name"].ToString() + "/result_json.aspx"); if (result.Contains("error")) { context.Response.Write("{\"status\": 0, \"msg\": \"错误提示:请检查URL是否正确!\"}"); return; } //反序列化JSON Dictionary <string, object> dic = JsonMapper.ToObject <Dictionary <string, object> >(result); if (dic["ret"].ToString() != "0") { context.Response.Write("{\"status\": 0, \"msg\": \"错误代码:" + dic["ret"] + "," + dic["msg"] + "\"}"); return; } string password = Vincent._DTcms.DTRequest.GetFormString("txtPassword").Trim(); string email = Vincent._DTcms.Utils.ToHtml(Vincent._DTcms.DTRequest.GetFormString("txtEmail").Trim()); string mobile = Vincent._DTcms.Utils.ToHtml(Vincent._DTcms.DTRequest.GetFormString("txtMobile").Trim()); string userip = Vincent._DTcms.DTRequest.GetIP(); BLL.users bll = new BLL.users(); Model.users model = new Model.users(); //检查默认组别是否存在 Model.user_groups modelGroup = new BLL.user_groups().GetDefault(); if (modelGroup == null) { context.Response.Write("{\"status\":0, \"msg\":\"用户尚未分组,请联系管理员!\"}"); return; } //保存注册信息 model.group_id = modelGroup.id; model.user_name = bll.GetRandomName(10); //随机用户名 model.salt = Vincent._DTcms.Utils.GetCheckCode(6); //获得6位的salt加密字符串 model.password = _DESEncrypt.Encrypt(password, model.salt); model.email = email; model.mobile = mobile; if (!string.IsNullOrEmpty(dic["nick"].ToString())) { model.nick_name = dic["nick"].ToString(); } if (dic["avatar"].ToString().StartsWith("http://")) { model.avatar = dic["avatar"].ToString(); } if (!string.IsNullOrEmpty(dic["sex"].ToString())) { model.sex = dic["sex"].ToString(); } if (!string.IsNullOrEmpty(dic["birthday"].ToString())) { model.birthday = Vincent._DTcms.Utils.StrToDateTime(dic["birthday"].ToString()); } model.reg_ip = userip; model.reg_time = DateTime.Now; model.status = 0; //设置为正常状态 int newId = bll.Add(model); if (newId < 1) { context.Response.Write("{\"status\":0, \"msg\":\"注册失败,请联系网站管理员!\"}"); return; } model = bll.GetModel(newId); //赠送积分金额 if (modelGroup.point > 0) { new BLL.user_point_log().Add(model.id, model.user_name, modelGroup.point, "注册赠送积分", false); } if (modelGroup.amount > 0) { new BLL.user_amount_log().Add(model.id, model.user_name, Vincent._DTcms.DTEnums.AmountTypeEnum.SysGive.ToString(), modelGroup.amount, "注册赠送金额", 1); } //判断是否发送欢迎消息 if (userConfig.regmsgstatus == 1) //站内短消息 { new BLL.user_message().Add(1, "", model.user_name, "欢迎您成为本站会员", userConfig.regmsgtxt); } else if (userConfig.regmsgstatus == 2) //发送邮件 { //取得邮件模板内容 Model.mail_template mailModel = new BLL.mail_template().GetModel("welcomemsg"); if (mailModel != null) { //替换标签 string mailTitle = mailModel.maill_title; mailTitle = mailTitle.Replace("{username}", model.user_name); string mailContent = mailModel.content; mailContent = mailContent.Replace("{webname}", siteConfig.webname); mailContent = mailContent.Replace("{weburl}", siteConfig.weburl); mailContent = mailContent.Replace("{webtel}", siteConfig.webtel); mailContent = mailContent.Replace("{username}", model.user_name); //发送邮件 _Email.SendMail(siteConfig.emailsmtp, siteConfig.emailusername, siteConfig.emailpassword, siteConfig.emailnickname, siteConfig.emailfrom, model.email, mailTitle, mailContent); } } else if (userConfig.regmsgstatus == 3 && mobile != "") //发送短信 { Model.sms_template smsModel = new BLL.sms_template().GetModel("welcomemsg"); //取得短信内容 if (smsModel != null) { //替换标签 string msgContent = smsModel.content; msgContent = msgContent.Replace("{webname}", siteConfig.webname); msgContent = msgContent.Replace("{weburl}", siteConfig.weburl); msgContent = msgContent.Replace("{webtel}", siteConfig.webtel); msgContent = msgContent.Replace("{username}", model.user_name); //发送短信 string tipMsg = string.Empty; new BLL.sms_message().Send(model.mobile, msgContent, 2, out tipMsg); } } //绑定到对应的授权类型 Model.user_oauth oauthModel = new Model.user_oauth(); oauthModel.oauth_name = dic["oauth_name"].ToString(); oauthModel.user_id = model.id; oauthModel.user_name = model.user_name; oauthModel.oauth_access_token = dic["oauth_access_token"].ToString(); oauthModel.oauth_openid = dic["oauth_openid"].ToString(); new BLL.user_oauth().Add(oauthModel); context.Session[Vincent._DTcms.DTKeys.SESSION_USER_INFO] = model; context.Session.Timeout = 45; //记住登录状态,防止Session提前过期 Vincent._DTcms.Utils.WriteCookie(Vincent._DTcms.DTKeys.COOKIE_USER_NAME_REMEMBER, "BuysingooShop", model.user_name); Vincent._DTcms.Utils.WriteCookie(Vincent._DTcms.DTKeys.COOKIE_USER_PWD_REMEMBER, "BuysingooShop", model.password); //写入登录日志 new BLL.user_login_log().Add(model.id, model.user_name, "会员登录"); //返回URL context.Response.Write("{\"status\":1, \"msg\":\"会员登录成功!\"}"); return; }