/// <summary> /// 获取临时用户登录Passport /// </summary> /// <returns></returns> protected static JObject GetTempUser() { var tempUser = CachingHelper <HttpRuntimeCaching> .Get <JObject>(KeyModel.Cache.DataCenterTempUser); if (VerifyHelper.IsEmpty(tempUser)) { var tempUserAccount = StringHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyApiTempUser)).Split('|'); if (VerifyHelper.IsEmpty(tempUserAccount)) { throw new DefaultException("数据中心TempUser配置错误"); } var data = new JObject(); data["AppId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId); data["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId); data["Version"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion); data["ip"] = BrowserHelper.GetClientIP(); data["Account"] = tempUserAccount.Length > 0 ? tempUserAccount[0] : ""; data["Password"] = tempUserAccount.Length > 1 ? tempUserAccount[1] : ""; var result = Request(DataCenterConfig.GetApiUrl(KeyModel.Config.DataCenter.KeyAccountLogin), JsonHelper.Serialize(data), resultKey: null, errorKey: null); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功) && !VerifyHelper.IsEmpty(result.Obj)) { tempUser = result.Obj; } } return(VerifyHelper.IsEmpty(tempUser) ? new JObject() : tempUser); }
public HttpResponseMessage InsertProject(RequestModel request) { var result = WebHelper.GetResult(request); if (result.Code == DoubleX.Infrastructure.Utility.EnumHelper.GetValue(EnumResultCode.操作成功)) { var projectName = JsonHelper.GetValue(request.Obj, "ProjectName"); ProjectEntity project = new ProjectEntity() { Id = Guid.NewGuid(), AccountId = Guid.Parse(WebHelper.GetContext().Member.MemberId), CreateId = Guid.Parse(WebHelper.GetContext().Member.MemberId), CreateDt = DateTime.Now, CreateIP = BrowserHelper.GetClientIP(), LastId = Guid.Parse(WebHelper.GetContext().Member.MemberId), LastDt = DateTime.Now, LastLoginIP = BrowserHelper.GetClientIP(), IsDelete = false, ProjectName = projectName, State = 0, ProjectType = (int)ProjectType.BillingOnWords, SurplusWords = 0, TranslateKey = Guid.NewGuid().ToString(), Type = 0, ValidityTime = DateTime.Now }; projectService.Insert(project); result.Message = "新增项目成功!"; } return(WebApiHelper.ToHttpResponseMessage(result)); }
/// <summary> /// 获取结果(Post方式) /// </summary> /// <returns></returns> public static ResultModel Post(string url, string post, string resultKey = null, string errorKey = null) { JObject postObj = null; if (!VerifyHelper.IsEmpty(post)) { postObj = JsonHelper.Deserialize <JObject>(post); } if (VerifyHelper.IsNull(postObj)) { postObj = new JObject(); } //公共post参数 postObj["AppId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId); postObj["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId); postObj["Version"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion); postObj["ip"] = BrowserHelper.GetClientIP(); var passport = postObj.GetValue("passport", StringComparison.InvariantCultureIgnoreCase); if (VerifyHelper.IsNull(passport)) { passport = GetTempUserPassport(); } postObj["passport"] = passport; //postObj["culture"] = CommonHelper.GetContext().Culture; //postObj["security"] = "1xxxx"; return(Request(url, JsonHelper.Serialize(postObj), resultKey: resultKey, errorKey: errorKey)); }
public HttpResponseMessage InsertTerm(RequestModel request) { var result = WebHelper.GetResult(request); if (result.Code == DoubleX.Infrastructure.Utility.EnumHelper.GetValue(EnumResultCode.操作成功)) { var projectId = JsonHelper.GetValue(request.Obj, "ProjectId"); var projectGuid = Guid.Parse(projectId); var termSrc = JsonHelper.GetValue(request.Obj, "TermSrc"); var termSrcLang = JsonHelper.GetValue(request.Obj, "TermSrcLang"); var termTgt = JsonHelper.GetValue(request.Obj, "TermTgt"); var termTgtLang = JsonHelper.GetValue(request.Obj, "TermTgtLang"); var flag = JsonHelper.GetValue(request.Obj, "UserId"); var list = termService.Query(item => item.ProjectId == projectGuid && item.TermSrc == termSrc && item.TermSrcLang == termSrcLang && item.TermTgtLang == termTgtLang); if (list != null && list.Count > 0) { result.Message = "已具有相同术语!"; } else { TermEntity term = new TermEntity() { Id = Guid.NewGuid(), ProjectId = projectGuid, CreateId = Guid.Parse(WebHelper.GetContext().Member.MemberId), CreateDt = DateTime.Now, CreateIP = BrowserHelper.GetClientIP(), LastId = Guid.Parse(WebHelper.GetContext().Member.MemberId), LastDt = DateTime.Now, LastIP = BrowserHelper.GetClientIP(), IsDelete = false, TermSrc = termSrc, TermSrcLang = termSrcLang, TermTgt = termTgt, TermTgtLang = termTgtLang, PlatformCode = 0, UserId = flag, Type = 0, Status = 0 }; termService.Insert(term); result.Message = "新增术语成功!"; } } return(WebApiHelper.ToHttpResponseMessage(result)); }
/// <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)); }
/// <summary> /// 会员登录 /// </summary> public HttpResponseMessage MemberLogin(RequestModel request) { var result = WebHelper.GetResult <string>(request); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { var model = memberService.Login(StringHelper.Get(request.Obj["account"]), StringHelper.Get(request.Obj["password"]), BrowserHelper.GetClientIP()); if (!VerifyHelper.IsEmpty(model) && !VerifyHelper.IsEmpty(model.Id)) { WebHelper.SetMember(model); result.Code = EnumHelper.GetValue(EnumResultCode.跳转地址); result.Redirect = UrlsHelper.GetRefUrl(defaultUrl: WebHelper.GetMemberUrl()); } } return(WebApiHelper.ToHttpResponseMessage(result)); }