public async Task <IActionResult> Activate([FromServices] RemoteBillingService billing, [FromServices] Provider provider, [FromBody] ActivateByCodeRequest request) { using (var rep = new Repository <ActivationCode>(provider)) { var code = await rep.Get(x => x.Number == request.Number && x.Code == request.Code).SingleOrDefaultAsync(); if (code == null) { return(Ok(ApiResponse.Failed(ApiErrorCode.ResourceNotFound, "Активационная карта с указанными данными не найдена"))); } if (code.Activated.HasValue) { return(Ok(ApiResponse.Failed(ApiErrorCode.ResourceNotFound, "Активационная карта с указанными данными уже активирована"))); } var packetId = await billing.AddPacketAsync(code.PacketType.Code, User.Identity.Name); code.Activated = DateTime.Now; code.PacketId = packetId; await rep.UpdateAsync(code); await rep.CommitAsync(); return(Ok(ApiResponse.Success(new ActivateByCodeResponse() { PacketName = code.PacketType.Name }))); } }
public async Task <IActionResult> Post([FromBody] RegistrationRequest request, [FromServices] IAuthenticationManager authentication, [FromServices] RemoteBillingService billingService, [FromServices] IEmailConfirmationService emailConfirmationService, [FromServices] ICryptoProviderService cryptoProvider) { try { var value = Convert.FromBase64String(request.InitCms); var xml = new UTF8Encoding(false).GetString(value); var encrypted = XmlSerializationHelper.DeserializeFromXml <string>(xml); var decrypted = AesHelper.Decrypt(encrypted); var isValid = await cryptoProvider.VerifyCMSAsync(xml, request.SignedCms); if (!isValid) { return(Json(ApiResponse.Failed(ApiErrorCode.ValidationError, "Сертификат не прошел проверку"))); } var signUpDateTime = new DateTime(Convert.ToInt64(decrypted)); if ((DateTime.Now - signUpDateTime).Hours > 0) { return(Json(ApiResponse.Failed(ApiErrorCode.AuthenticationFailed, "С момента начала авторизации прошло больше часа"))); } } catch { return(Json(ApiResponse.Failed(ApiErrorCode.AuthenticationFailed, "Сбой дешифрации сообщения"))); } await authentication.RegisterAsync(request, billingService); string code; long userId; if (!request.InvitedUser) { using (var repository = new Repository <User>(_provider)) { var user = repository.Get(x => x.UserName == request.UserAccount.Email).Single(); code = emailConfirmationService.GenerateEmailConfirmationToken(user); repository.Update(user); repository.Commit(); userId = user.Id; } var callbackUrl = Url.Action( "ConfirmEmail", "Registration", new { userId = userId, code = code }, protocol: HttpContext.Request.Scheme); callbackUrl = callbackUrl.Replace("api/Registration/ConfirmEmail", "auth/confirmemail"); emailConfirmationService.SendConfirmationUrl(request.UserAccount.Email, callbackUrl); } return(Json(ApiResponse.Success(true))); }
public async Task <IActionResult> Complete( [FromServices] QazKomAckquiringService qazKom, [FromServices] RemoteBillingService billing, [FromQuery] string orderId, string response) { Log.Information("{EventId} query with {orderId}, {response}", "QAZKOM", orderId, response); var transaction = await qazKom.TryUpdateTransactionByOrderIdAsync(orderId); await billing.AddPacketAsync(transaction.ProductCode, transaction.Employee); await qazKom.CompleteTransaction(transaction); Log.Information("{EventId} transaction completed {orderId}", "QAZKOM", orderId); return(Ok(0)); }
public async Task <IActionResult> History([FromServices] RemoteBillingService billing, DataSourceLoadOptionsImpl options) { return(Ok(await billing.GetPacketsHistoryAsync(User.Identity.Name, options))); }