public VerificationResponse VerificationOTP(VerificationRequest verificationRequest, string authorization) { var token = getTokenFromAuthorization(authorization); var tokenContent = readTokenVerifyCode(token); var otpFromUser = verificationRequest.OtpCode; var otpFromToken = tokenContent.otpCode; if (otpFromUser == otpFromToken && !isExpired(tokenContent.expire)) { Console.WriteLine(tokenContent.ToString()); var user = GetByID(tokenContent.userId); if (user.WorkerProfile == null) { user.WorkerProfile = new WorkerProfile(); } user.WorkerProfile.Active = true; context.WorkerAccount.Update(user); context.SaveChanges(); user = updateLastLogin(tokenContent.userId, DateTime.Now).Result; var authToken = generateJwtTokeAuthResponse(user); return(new VerificationResponse(user, authToken)); } return(null); }
public void ShouldBeActiveIfConfirmed() { var code = VerificationCode.Generate(); var failedRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Confirmed, DateTime.MaxValue, code, 2); failedRequest.IsActive().Should().BeTrue(); }
/// <summary> /// On user token activation /// </summary> /// <param name="model"></param> public async Task <VerificationResponse> UserVerification(VerificationRequest model) { Users user = null; Organizations org = null; using (var a = contextFactory.CreateDbContext()) { // Get user by invite token and check if he's already activated user = await a.Users.Include(x => x.UserInvites).Where(x => x.UserInvites.InviteToken == model.InviteToken && x.Activated == false).FirstOrDefaultAsync(); if (user == null) { throw new ArgumentException("There is no invite pending for this token"); } user.Activated = true; user.HashedPassword = BC.HashPassword(model.Password); org = await a.Organizations.Where(x => x.Id == user.OrganizationId).FirstOrDefaultAsync(); await a.SaveChangesAsync(); } var token = generateJwtToken(user); return(new VerificationResponse(user, token, org)); }
public void ShouldBeActiveIfPendingAndExpiryGreaterThanNow() { var code = VerificationCode.Generate(); var failedRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Pending, DateTime.UtcNow.AddMinutes(1), code, 2); failedRequest.IsActive().Should().BeTrue(); }
public IActionResult VerifyCode(VerificationRequest verificationRequest) { string authorization = AuthorizationString(); var verificationResponse = userService.VerificationOTP(verificationRequest, authorization); return(Ok(verificationResponse)); }
public override async Task VerifyQuality( VerificationRequest request, IServerStreamWriter <VerificationResponse> responseStream, ServerCallContext context) { try { _msg.InfoFormat("Starting verification request from {0}", request.UserName); _msg.DebugFormat("Request details: {0}", request); if (Checkout3DAnalyst) { // It must be re-checked out (but somehow it's enough to do it // on the calling thread-pool thread!?) Ensure3dAnalyst(); } Func <ITrackCancel, ServiceCallStatus> func = trackCancel => VerifyQualityCore(request, responseStream, trackCancel); ServiceCallStatus result = await GrpcServerUtils.ExecuteServiceCall( func, context, _singleStaThreadScheduler); _msg.InfoFormat("Verification {0}", result); } catch (Exception e) { _msg.Error($"Error verifying quality for request {request}", e); SendFatalException(e, responseStream); SetUnhealthy(); } }
public override async Task VerifyQuality( VerificationRequest request, IServerStreamWriter <VerificationResponse> responseStream, ServerCallContext context) { try { await StartRequest(request); Func <ITrackCancel, ServiceCallStatus> func = trackCancel => VerifyQualityCore(request, responseStream, trackCancel); ServiceCallStatus result = await GrpcServerUtils.ExecuteServiceCall( func, context, _staThreadScheduler); _msg.InfoFormat("Verification {0}", result); } catch (Exception e) { _msg.Error($"Error verifying quality for request {request}", e); SendFatalException(e, responseStream); SetUnhealthy(); } finally { EndRequest(); } }
public async Task <IActionResult> VerificationRequest([FromForm] VerificationRequest request) { var user = UserService.Get(long.Parse(User.Identity.Name)); if (user == null) { return(NotFound(new ResponseModel { Success = false, Message = "Пользователь не найден" })); } var verificationRequest = UserVerificationRequestService.GetVerificationRequest(user); if (verificationRequest != null) { return(BadRequest(new ResponseModel { Success = false, Message = "Вы уже отправили запрос на верификацию" })); } var document = await FileService.SaveFileForm(request.Document); var selfie = await FileService.SaveFileForm(request.Selfie); UserVerificationRequestService.CreateVerificationRequest(user, document, selfie); return(Ok(new ResponseModel())); }
public async Task StoreNewVerificationRequest(VerificationRequest verificationRequest) { var entity = new VerificationRequestEntity(verificationRequest); var table = await this.GetTableAsync(); await table.ExecuteAsync(TableOperation.InsertOrReplace(entity)); }
private ServiceCallStatus VerifyQualityCore( VerificationRequest request, IServerStreamWriter <VerificationResponse> responseStream, ITrackCancel trackCancel) { SetupUserNameProvider(request); void SendResponse(VerificationResponse r) => responseStream.WriteAsync(r); BackgroundVerificationService qaService = null; List <GdbObjRefMsg> deletableAllowedErrorRefs = new List <GdbObjRefMsg>(); QualityVerification verification = null; var issueCollection = new ConcurrentBag <IssueMsg>(); string cancellationMessage = null; try { // TODO: Separate long-lived objects, such as datasetLookup, domainTransactions (add to this class) from // short-term objects (request) -> add to background verification inputs IBackgroundVerificationInputs backgroundVerificationInputs = _verificationInputsFactoryMethod(request); qaService = CreateVerificationService(backgroundVerificationInputs, issueCollection, SendResponse, trackCancel); int maxParallelRequested = request.MaxParallelProcessing; if (backgroundVerificationInputs.WorkerClient != null && maxParallelRequested > 1) { // allow directly adding issues found by client processes: qaService.DistributedTestRunner = new DistributedTestRunner( backgroundVerificationInputs.WorkerClient, request, issueCollection); } verification = qaService.Verify(backgroundVerificationInputs, trackCancel); deletableAllowedErrorRefs.AddRange( GetDeletableAllowedErrorRefs(request.Parameters, qaService)); } catch (Exception e) { _msg.Error($"Error checking quality for request {request}", e); cancellationMessage = $"Server error: {e.Message}"; if (!EnvironmentUtils.GetBooleanEnvironmentVariableValue( "PROSUITE_QA_SERVER_KEEP_SERVING_ON_ERROR")) { SetUnhealthy(); } } ServiceCallStatus result = SendFinalResponse( verification, cancellationMessage ?? qaService.CancellationMessage, issueCollection, deletableAllowedErrorRefs, qaService?.VerifiedPerimeter, SendResponse); return(result); }
public VerificationRequestEntity(VerificationRequest src) { this.PartitionKey = src.UserId; this.RowKey = src.VerificationType.ToString(); this.Code = src.Code.ToString(); this.ExpirationDate = src.ExpiryDate; this.Status = (int)src.Status; this.Attempts = src.Attempts; }
public void ShouldRejectExpiredCodes() { var code = VerificationCode.Generate(); var expiredRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Pending, DateTime.MinValue, code, 0); var validatedRequest = expiredRequest.ValidateCode(code); validatedRequest.Status.Should().Be(VerificationRequestStatus.Expired); }
public void ShouldFailCodeAfterThreeAttempts() { var code = VerificationCode.Generate(); var failedRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Pending, DateTime.MaxValue, code, 2); var validatedRequest = failedRequest.ValidateCode(VerificationCode.Generate()); validatedRequest.Status.Should().Be(VerificationRequestStatus.Failed); }
public void ShouldAcceptCodeOnLastAttempt() { var code = VerificationCode.Generate(); var failedRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Pending, DateTime.MaxValue, code, 2); var validatedRequest = failedRequest.ValidateCode(code); validatedRequest.Status.Should().Be(VerificationRequestStatus.Confirmed); }
public void ShouldRejectFailedCode() { var code = VerificationCode.Generate(); var failedRequest = new VerificationRequest("userId", VerificationType.SMS, VerificationRequestStatus.Failed, DateTime.MinValue, code, 3); var validatedRequest = failedRequest.ValidateCode(code); validatedRequest.Status.Should().Be(VerificationRequestStatus.Failed); }
public async Task <ActionResult <CheckMrzStatusResponse> > VerifyIdentity(VerificationRequest request) { var model = _mapper.Map <VerificationRequestModel>(request); var result = await _kycService.VerifyIdentityAsync(model); var response = _mapper.Map <VerificationResponse>(result); return(Ok(response)); }
public void CanCreateValidVerificationRequest() { var request = VerificationRequest.GenerateNewVerificationRequest("userId", VerificationType.Email, VerificationCode.Generate()); request.Should().NotBeNull(); request.Attempts.Should().Be(0); request.Status.Should().Be(VerificationRequestStatus.Pending); request.ExpiryDate.Should().BeAfter(DateTime.UtcNow); }
public override async Task VerifyDataQuality( IAsyncStreamReader <DataVerificationRequest> requestStream, IServerStreamWriter <DataVerificationResponse> responseStream, ServerCallContext context) { VerificationRequest request = null; try { Assert.True(await requestStream.MoveNext(), "No request"); //while (await requestStream.MoveNext()) DataVerificationRequest initialrequest = Assert.NotNull(requestStream.Current, "No request"); request = initialrequest.Request; _msg.InfoFormat("Starting verification request from {0}", request); _msg.DebugFormat("Request details: {0}", request); if (Checkout3DAnalyst) { // It must be re-checked out (but somehow it's enough to do it // on the calling thread-pool thread!?) Ensure3dAnalyst(); } Func <DataVerificationResponse, DataVerificationRequest> moreDataRequest = delegate(DataVerificationResponse r) { return(Task.Run(async() => await RequestMoreDataAsync( requestStream, responseStream, context, r) .ConfigureAwait(false)) .Result); }; Func <ITrackCancel, ServiceCallStatus> func = trackCancel => VerifyDataQualityCore(initialrequest, moreDataRequest, responseStream, trackCancel); ServiceCallStatus result = await GrpcServerUtils.ExecuteServiceCall( func, context, _singleStaThreadScheduler); _msg.InfoFormat("Verification {0}", result); } catch (Exception e) { _msg.Error($"Error verifying quality for request {request}", e); SendFatalException(e, responseStream); SetUnhealthy(); } }
public IActionResult Verification(VerificationRequest model) { var response = _AccountManagementService.Verification(model); if (response.id == null) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> UserVerification([FromBody] VerificationRequest model) { try { var response = await accountService.UserVerification(model); return(Ok(response)); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public override async Task VerifyDataQuality( IAsyncStreamReader <DataVerificationRequest> requestStream, IServerStreamWriter <DataVerificationResponse> responseStream, ServerCallContext context) { VerificationRequest request = null; try { Assert.True(await requestStream.MoveNext(), "No request"); DataVerificationRequest initialRequest = Assert.NotNull(requestStream.Current, "No request"); request = initialRequest.Request; await StartRequest(request); Func <DataVerificationResponse, DataVerificationRequest> moreDataRequest = delegate(DataVerificationResponse r) { return(Task.Run(async() => await RequestMoreDataAsync( requestStream, responseStream, context, r) .ConfigureAwait(false)) .Result); }; Func <ITrackCancel, ServiceCallStatus> func = trackCancel => VerifyDataQualityCore(initialRequest, moreDataRequest, responseStream, trackCancel); ServiceCallStatus result = await GrpcServerUtils.ExecuteServiceCall( func, context, _staThreadScheduler); _msg.InfoFormat("Verification {0}", result); } catch (Exception e) { _msg.Error($"Error verifying quality for request {request}", e); SendFatalException(e, responseStream); SetUnhealthy(); } finally { EndRequest(); } }
public async Task <IActionResult> VerifyVoter([FromBody] VerificationRequest payload) { //var decryptedData = await new EncryptionConfig<VerificationRequest>().DecryptPayload(payload); var bytes = Convert.FromBase64String(payload.Photo); var result = await _voterService.VerifyVoterIdentity(payload.VoterId, bytes); if (result == null) { return(BadRequest()); } return(Ok(result)); }
public DistributedTestRunner( [NotNull] QualityVerificationGrpc.QualityVerificationGrpcClient qaClient, [NotNull] VerificationRequest originalRequest, [CanBeNull] ConcurrentBag <IssueMsg> issueCollection) { Assert.NotNull(qaClient, nameof(qaClient)); Assert.NotNull(originalRequest, nameof(originalRequest)); Assert.ArgumentCondition(originalRequest.MaxParallelProcessing > 1, "maxParallelDesired must be greater 1"); _qaClient = qaClient; _originalRequest = originalRequest; _issueCollection = issueCollection; }
public override async Task <VerificationReply> SendMessage(VerificationRequest request, ServerCallContext context) { var task = Task.Run(() => { _verificationService.AddVerification(new VerificationDTO() { Code = request.Code, BizCode = BizCode.Register, To = request.To }); }); await task; return(new VerificationReply() { Ok = true }); }
public static string ToJson(this VerificationRequest request) { var model = new { merchant_id = request.MerchantId, amount = request.Amount, authority = request.Authority }; var setting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; return(JsonConvert.SerializeObject(model, setting)); }
public async Task UpdateAttemptedRequest(VerificationRequest storedCodeRequest) { var table = await this.GetTableAsync(); var existingEntry = await table.ExecuteAsync(TableOperation.Retrieve(storedCodeRequest.UserId, storedCodeRequest.VerificationType.ToString())); if (existingEntry == null) { throw new EntityNotFoundException(); } var entity = new VerificationRequestEntity(storedCodeRequest) { ETag = existingEntry.Etag, }; await table.ExecuteAsync(TableOperation.Replace(entity)); }
public async Task <IHttpActionResult> VerifyEmail([FromBody] VerificationRequest request) { try { var response = await _accountService.VerifyEmail(request.Username, request.Token); if (response.Succeeded) { return(Ok(response.ResponseBody)); } return(BadRequest(response.ErrorMessage)); } catch (Exception e) { return(InternalServerError(e)); } }
private async Task <bool> VerifyAsync( [NotNull] QualityVerificationGrpc.QualityVerificationGrpcClient rpcClient, [NotNull] VerificationRequest request, [NotNull] SubResponse subResponse, CancellationTokenSource cancellationSource) { using (var call = rpcClient.VerifyQuality(request)) { while (await call.ResponseStream.MoveNext(cancellationSource.Token)) { VerificationResponse responseMsg = call.ResponseStream.Current; HandleResponseMsg(responseMsg, subResponse); } } return(true); }
public BackgroundVerificationRun( [NotNull] VerificationRequest verificationRequest, [NotNull] IDomainTransactionManager domainTransactions, [NotNull] IQualityVerificationRepository qualityVerificationRepository, [NotNull] IQualityConditionRepository qualityConditionRepository, CancellationTokenSource cancellationTokenSource) { VerificationRequest = verificationRequest; _domainTransactions = domainTransactions; _qualityVerificationRepository = qualityVerificationRepository; _qualityConditionRepository = qualityConditionRepository; _cancellationTokenSource = cancellationTokenSource; Progress = new QualityVerificationProgressTracker { CancellationTokenSource = cancellationTokenSource }; }
public async Task <IActionResult> Verification([FromBody] VerificationRequest request) { try { //Generates or checks the verification code. var response = await _authService.Verification(request.Name, request.Code); return(StatusCode(response.Code ?? 200, response)); } catch (Exception) { return(BadRequest(new GenericResponse { Code = (int)HttpStatusCode.BadRequest, Status = (int)Model.Transient.StatusCode.UnknowException, Message = "Generic error in request." })); } }