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))); }