protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NewRegisterCustomerModel newRegisterCustomer = new NewRegisterCustomerModel() { CustomerID = Request["name"].ToString().Trim(), CustomerEmail = Request["email"].ToString().Trim(), PassWordInput1 = Request["pass1"].ToString().Trim(), PassWordInput2 = Request["pass2"].ToString().Trim(), }; string msg = String.Empty; var result = CustomerHelper.RegisterNewCustomer(Context, newRegisterCustomer, out msg); if (result) { System.Web.HttpCookie myCookie = new HttpCookie("LoginInfo"); myCookie.Domain = YoeJoyConfig.SiteBaseURL; myCookie.Expires = DateTime.Now.AddYears(1);//Cookie过期时间 myCookie.Value = newRegisterCustomer.CustomerID + "," + DateTime.Now.ToString(AppConst.DateFormatLong); Response.Cookies.Add(myCookie);//添加到页面cookie中 } Response.Write(JsonContentTransfomer<object>.GetJsonContent(new {IsSuccess=result,Msg=msg})); } }
/// <summary> /// 注册新用户 /// </summary> public static bool RegisterNewCustomer(HttpContext context, NewRegisterCustomerModel customer, out string msg) { bool isSuccess = false; msg = String.Empty; string customerID = customer.CustomerID.Trim(); string password1 = customer.PassWordInput1.Trim(); string password2 = customer.PassWordInput2.Trim(); string customerEmail = customer.CustomerEmail.Trim(); if (customerID == "") { msg += "请输入用户名!<br />"; } else if (!CommonUtility.IsValidNum(customerID, "^[\u4e00-\u9fa5a-zA-Z]+$"))//原需求只允许中英文 { msg += "用户名只能包含中英文字符!<br />"; } else if (customerID.Length < 3 || customerID.Length > 20) { msg += "用户名长度必须大于等于3个字符!<br />"; } if (password1 == "") { msg += "请输入密码!<br />"; } else if (!CommonUtility.IsValidNum(password1, "[a-zA-Z0-9]+$"))//原需求只允许英文数字组合 { msg += "密码只能是英文数字组合!<br />"; } else if (password1.Length < 6 || password1.Length > 20) { msg += "密码长度必须大于等于6个字符!<br />"; } else if (password2 == "") { msg += "请输入确认密码!<br />"; } else if (password2 != password1) { msg += "请确保两次输入的密码一致!<br />"; } if (customerEmail == "") { msg += "请输入电子邮箱!<br />"; } else if (!Util.IsEmailAddress(customerEmail)) { msg += "请正确输入电子邮箱地址!"; } try { //定义一个用户对象并赋值 CustomerInfo oCustomer = new CustomerInfo(); //-----基础的三个信息,用户名,密码,邮箱---// oCustomer.CustomerID = customerID; //DESC加密用户密码 oCustomer.Pwd = DESProvider.EncryptString(password1, YoeJoyConfig.DESCEncryptKey); oCustomer.Email = customerEmail; //---其他信息---// oCustomer.EmailStatus = (int)AppEnum.EmailStatus.Origin; oCustomer.Status = (int)AppEnum.BiStatus.Valid; oCustomer.DwellAreaSysNo = AppConst.IntNull; oCustomer.ReceiveAreaSysNo = AppConst.IntNull; oCustomer.CustomerRank = (int)AppEnum.CustomerRank.Ordinary; oCustomer.IsManualRank = (int)AppEnum.YNStatus.No; oCustomer.CustomerType = (int)AppEnum.CustomerType.Personal; oCustomer.RegisterTime = DateTime.Now; oCustomer.LastLoginTime = DateTime.Now; oCustomer.LastLoginIP = context.Request.UserHostAddress; oCustomer.ValidScore = 0; oCustomer.TotalScore = 0; oCustomer.ValidFreeShipFee = 0; oCustomer.TotalFreeShipFee = 0; //注册操作 CustomerManager.GetInstance().Insert(oCustomer); IcsonSessionInfo oSession = (IcsonSessionInfo)context.Session["IcsonSessionInfo"]; if (oSession == null) { oSession = new IcsonSessionInfo(); context.Session["IcsonSessionInfo"] = oSession; } //指定当前用户为注册的用户 oSession.sCustomer = oCustomer; isSuccess = true; } catch (BizException exp) { msg = exp.Message; } catch (Exception ex) { ErrorLog.GetInstance().Write(ex.ToString()); string url = "../CustomError.aspx?msg=" + context.Server.UrlEncode("用户注册失败!"); context.Response.Redirect(url); } if (isSuccess) { //Response.Redirect("../Customer/NewCustomer.aspx?Type=success"); msg += "注册成功"; //lblErrmsg.Text = "恭喜您,注册成功!<br/>"; //lblErrmsg.Text += "<a href='../Account/AccountCenter.aspx'><span style='color:#FF298F'>请点击进入用户中心!</ span></ a>"; //Response.Redirect("../Account/AccountCenter.aspx"); } return isSuccess; }