public override void OnActionExecuting(HttpActionContext actionContext) { var isAuth = actionContext.RequestContext.Principal.Identity.IsAuthenticated; if (!isAuth) { return; } var identity = (WebIdentity)actionContext.RequestContext.Principal.Identity; WebContext context = identity.WebContext; var accountId = context.Id; var account = new MerchantAccountComponent().GetById(accountId); if (account == null) { throw new ApplicationException(Resources.SystemError); } var country = new CountryComponent().GetById(account.CountryId); if (country == null || !country.Status.HasFlag(CountryStatus.Enable)) { throw new CommonException(ReasonCode.COUNTRY_FORBBIDEN_REQUEST, Resources.SystemError); } }
public ServiceResult <string> Create(OrderCreateModel model) { var result = new ServiceResult <string>(); if (!ModelState.IsValid) { result.Code = ReasonCode.MISSING_REQUIRED_FIELDS; foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))) { result.Message += error + Environment.NewLine; } return(result); } var orderComponent = new OrderComponent(); var merchantAccountId = this.GetMerchantAccountId(); //兼容之前版本,没传入法币,则取商家设置的法币 if (string.IsNullOrEmpty(model.FiatCurrency)) { var merchant = new MerchantAccountComponent().GetById(merchantAccountId); model.FiatCurrency = merchant.FiatCurrency; } var orderNo = orderComponent.CreateOrder(merchantAccountId, model.FiatCurrency, model.CryptoId, model.Amount, model.PaymentType, model.UserToken, this.GetClientIPAddress()); result.Data = orderNo; return(result); }
public ServiceResult <string> Upload(UploadImageModel model) { var account = new MerchantAccountComponent().GetById(this.GetMerchantAccountId()); return(new ServiceResult <string> { Data = new ImageComponent().UploadWithRegion(model.FileName, model.Base64Content, account.CountryId) }); }
public ServiceResult <SignonDTO> Signon(SignonModel model) { ServiceResult <SignonDTO> result = new ServiceResult <SignonDTO>(); if (!ModelState.IsValid) { result.Code = ReasonCode.MISSING_REQUIRED_FIELDS; foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))) { result.Message += error + Environment.NewLine; } return(result); } MerchantAccountComponent cpt = new MerchantAccountComponent(); result.Data = cpt.Signon(model.POSSN, model.MerchantId, model.PIN); return(result); }
public ServiceResult <MechantSimpleInfoDTO> MerchantSimpleInfoBySn(string sn) { var result = new ServiceResult <MechantSimpleInfoDTO>(); if (!ModelState.IsValid) { result.Code = ReasonCode.MISSING_REQUIRED_FIELDS; foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))) { result.Message += error + Environment.NewLine; } return(result); } var cpt = new MerchantAccountComponent(); result.Data = cpt.GetMerchantSimpleInfoBySn(sn); return(result); }
public HttpResponseMessage Download(string id) { if (string.IsNullOrWhiteSpace(id) || id == "null") { return(new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest)); } var account = new MerchantAccountComponent().GetById(this.GetMerchantAccountId()); var bytes = new ImageComponent().DownloadWithRegion(id, account.CountryId); if (bytes == null || bytes.Length == 0) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } var resp = new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ByteArrayContent(bytes) }; resp.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); return(resp); }
public ServiceResult SendBindingSMS(SendBindingSMSModel model) { ServiceResult result = new ServiceResult(); if (!ModelState.IsValid) { result.Code = ReasonCode.MISSING_REQUIRED_FIELDS; foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage))) { result.Message += error + Environment.NewLine; } return(result); } MerchantAccountComponent accountComponent = new MerchantAccountComponent(); accountComponent.SendBindingSMS(model.Cellphone, model.CountryId, model.MerchantAccount, model.POSSN); return(result); }
/// <summary>Asynchronously authenticates the request.</summary> /// <returns>The task that completes the authentication.</returns> /// <param name="context">The authentication context.</param> /// <param name="cancellationToken">The cancellation token.</param> public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { if (context == null) { throw new ArgumentNullException(nameof(context)); } HttpRequestMessage request = context.Request; if (request == null) { throw new InvalidOperationException("Request must not be null"); } if (context.ActionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().Count > 0) { return(Task.FromResult(0)); } if (context.Request.Headers.Authorization == null) { return(Unauthorized(context)); } try { var authHeader = request.Headers.Authorization.Parameter; var accessToken = AccessTokenGenerator.DecryptToken <MerchantAccessToken>(authHeader); if (string.IsNullOrWhiteSpace(accessToken.Identity)) { var merchant = new MerchantAccountComponent().GetMerchantAccountBySN(accessToken.POSSN); if (merchant == null) { return(Unauthorized(context)); } accessToken.Identity = merchant.Username; } var cacheKey = $"{RedisKeys.FiiiPOS_APP_MerchantId}:{accessToken.Identity}"; var cacheToken = RedisHelper.StringGet(Constant.REDIS_TOKEN_DBINDEX, cacheKey); if (authHeader != cacheToken) { return(Unauthorized(context)); } var bc = new MerchantAccountComponent(); var account = bc.GetByPosSn(accessToken.POSSN, accessToken.Identity); if (account == null) { return(Unauthorized(context)); } bc.ChangeLanguage(account.Id, context.Request.Headers.AcceptLanguage.FirstOrDefault()?.Value); var webContext = new WebContext { Id = account.Id, CountrtId = account.CountryId, Name = account.MerchantName }; context.Principal = new WebPrincipal(new WebIdentity(webContext)); return(Task.FromResult(0)); } catch (CommonException ex) { return(CommonErrorResult(context, ex)); } catch (Exception) { return(Unauthorized(context)); } }