/// <summary> /// 获取访问客户端标识 /// </summary> public static Guid GetVisitId() { //访问标识读取顺序: cookie->querystring(_VisitId)->post(_VisitId); Guid visitId = GuidHelper.Get(CookieHelper.Get(KeyModel.Cookie.VisitTag)); if (VerifyHelper.IsEmpty(visitId)) { visitId = GuidHelper.Get(UrlsHelper.GetQueryValue("_VisitId")); } //post暂不考虑 return(visitId); }
/// <summary> /// 职员登录 /// </summary> public HttpResponseMessage EmployeeLogin(RequestModel request) { var result = WebHelper.GetResult <string>(request); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { var model = employeeService.Login(StringHelper.Get(request.Obj["account"]), StringHelper.Get(request.Obj["password"])); if (!VerifyHelper.IsEmpty(model) && !VerifyHelper.IsEmpty(model.Id)) { WebHelper.SetEmployee(model); result.Code = EnumHelper.GetValue(EnumResultCode.跳转地址); result.Redirect = UrlsHelper.GetRefUrl(defaultUrl: WebHelper.GetManageUrl()); } } return(WebApiHelper.ToHttpResponseMessage(result)); }
/// <summary> /// 全局执行前过滤 /// </summary> public override void OnActionExecuting(ActionExecutingContext filterContext) { try { base.OnActionExecuting(filterContext); var routePath = StringHelper.FormatDefault(MvcHelper.GetRoutePath(filterContext)); var managePath = StringHelper.FormatDefault(WebHelper.GetManagePath(isRouteFormat: true)); var memberPath = StringHelper.FormatDefault(WebHelper.GetMemberPath(isRouteFormat: true)); //管理中心登录判断 if (routePath.Contains(managePath)) { var loginUrls = new List <string>() { string.Format("{0}|account|login", managePath), string.Format("{0}|account|signin", managePath) }; if (!WebHelper.GetContext().IsEmployeeLogin&& !loginUrls.Contains(routePath)) { filterContext.HttpContext.Response.Clear(); filterContext.Result = new RedirectResult(WebHelper.GetManageUrl(string.Format("/account/login?_ref={0}", UrlsHelper.GetUrl()))); } } //会员中心登录判断 if (routePath.Contains(memberPath)) { var loginUrls = new List <string>() { string.Format("{0}|account|login", memberPath), string.Format("{0}|account|regist", memberPath), string.Format("{0}|account|agreement", memberPath), string.Format("{0}|account|forgetpwd", memberPath) }; if (!WebHelper.GetContext().IsMemberLogin&& !loginUrls.Contains(routePath)) { filterContext.HttpContext.Response.Clear(); filterContext.Result = new RedirectResult(WebHelper.GetMemberUrl(string.Format("/account/login?_ref={0}", UrlsHelper.GetUrl()))); } } } catch (Exception ex) { throw new DefaultException(EnumResultCode.未知异常, ex); } }
/// <summary> /// 找回密码 /// </summary> public HttpResponseMessage MemberForgetPwd(RequestModel request) { var result = WebHelper.GetResult <string>(request); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { string receiver = "", mobile = JsonHelper.GetValue(request.Obj, "Mobile"), email = JsonHelper.GetValue(request.Obj, "Email"), code = JsonHelper.GetValue(request.Obj, "Code"), pwd = JsonHelper.GetValue(request.Obj, "Pwd"), sendType = JsonHelper.GetValue(request.Obj, "SendType"); Guid taskId = GuidHelper.Get(JsonHelper.GetValue(request.Obj, "TaskId")); #region 入信息判断 if (VerifyHelper.IsEmpty(sendType) || (sendType != KeyModel.Config.Template.KeyForgetPwdMobile && sendType != KeyModel.Config.Template.KeyForgetPwdEmail)) { throw new MessageException(EnumMessageCode.信息错误); } if ((VerifyHelper.IsEmpty(mobile) && VerifyHelper.IsEmpty(email)) || VerifyHelper.IsEmpty(taskId)) { throw new MessageException(EnumMessageCode.信息错误); } if (sendType == KeyModel.Config.Template.KeyForgetPwdMobile && VerifyHelper.IsEmpty(mobile)) { throw new MessageException(EnumMessageCode.请输入手机号码); } if (sendType == KeyModel.Config.Template.KeyForgetPwdEmail && VerifyHelper.IsEmpty(email)) { throw new MessageException(EnumMessageCode.请输入邮箱地址); } if (VerifyHelper.IsEmpty(pwd)) { throw new MessageException(EnumMessageCode.请输入密码); } if (VerifyHelper.IsEmpty(code)) { throw new MessageException(EnumMessageCode.请输入验证码); } #endregion receiver = sendType == KeyModel.Config.Template.KeyForgetPwdMobile ? mobile : email; //验证码效验 bool isSuccess = notificationService.ConfirmVerifyCode(taskId, receiver, code, request.CurrentContext.VisitId); if (!isSuccess) { throw new MessageException(EnumMessageCode.验证码错误); } //找回密码修改 var entity = memberService.MemberForgetPwd(email, mobile, pwd, BrowserHelper.GetClientIP()); if (VerifyHelper.IsEmpty(entity)) { throw new MessageException(EnumMessageCode.找回密码失败); } //返回 if (!VerifyHelper.IsEmpty(entity) && !VerifyHelper.IsEmpty(entity.Id)) { notificationService.ExpireVerifyCode(taskId); WebHelper.SetMember(entity); result.Code = EnumHelper.GetValue(EnumResultCode.跳转地址); result.Redirect = UrlsHelper.GetRefUrl(defaultUrl: WebHelper.GetMemberUrl()); } } return(WebApiHelper.ToHttpResponseMessage(result)); }
/// <summary> /// 会员注册 /// </summary> public HttpResponseMessage MemberRegist(RequestModel request) { var result = WebHelper.GetResult <string>(request); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { string receiver = "", mobile = JsonHelper.GetValue(request.Obj, "Mobile"), email = JsonHelper.GetValue(request.Obj, "Email"), code = JsonHelper.GetValue(request.Obj, "Code"), pwd = JsonHelper.GetValue(request.Obj, "Pwd"), nameTag = JsonHelper.GetValue(request.Obj, "NameTag"), sendType = JsonHelper.GetValue(request.Obj, "SendType"); Guid taskId = GuidHelper.Get(JsonHelper.GetValue(request.Obj, "TaskId")); #region 入信息判断 if (VerifyHelper.IsEmpty(sendType) || (sendType != KeyModel.Config.Template.KeyRegistMobile && sendType != KeyModel.Config.Template.KeyRegistEmail)) { throw new MessageException(EnumMessageCode.信息错误); } if ((VerifyHelper.IsEmpty(mobile) && VerifyHelper.IsEmpty(email)) || VerifyHelper.IsEmpty(taskId)) { throw new MessageException(EnumMessageCode.信息错误); } if (sendType == KeyModel.Config.Template.KeyRegistMobile && VerifyHelper.IsEmpty(mobile)) { throw new MessageException(EnumMessageCode.请输入手机号码); } if (sendType == KeyModel.Config.Template.KeyRegistEmail && VerifyHelper.IsEmpty(email)) { throw new MessageException(EnumMessageCode.请输入邮箱地址); } if (VerifyHelper.IsEmpty(pwd)) { throw new MessageException(EnumMessageCode.请输入密码); } if (VerifyHelper.IsEmpty(code)) { throw new MessageException(EnumMessageCode.请输入验证码); } #endregion receiver = sendType == KeyModel.Config.Template.KeyRegistMobile ? mobile : email; //验证码效验 bool isSuccess = notificationService.ConfirmVerifyCode(taskId, receiver, code, request.CurrentContext.VisitId); if (!isSuccess) { throw new MessageException(EnumMessageCode.验证码错误); } //注册 var entity = memberService.Regist(receiver, email, mobile, pwd, nameTag, BrowserHelper.GetClientIP()); if (VerifyHelper.IsEmpty(entity)) { throw new MessageException(EnumMessageCode.注册失败); } //首次注册,送100元, 添加充值记录信息 rechargeRecordService.Insert(new RechargeRecordEntity { AccountId = entity.Id, MoneyValue = 100, Descript = "注册赠送", CreateId = entity.Id, CreateDt = DateTime.Now, LastId = entity.Id, LastDt = DateTime.Now }); //返回 if (!VerifyHelper.IsEmpty(entity) && !VerifyHelper.IsEmpty(entity.Id)) { notificationService.ExpireVerifyCode(taskId); WebHelper.SetMember(entity); result.Code = EnumHelper.GetValue(EnumResultCode.跳转地址); result.Redirect = UrlsHelper.GetRefUrl(defaultUrl: WebHelper.GetMemberUrl()); } } return(WebApiHelper.ToHttpResponseMessage(result)); }