public override async Task <OperationResult <object> > GetVerifyTransaction(AuthorizedModel model, CancellationToken ct) { if (!TryReconnectChain(ct)) { return(new OperationResult <object>(new AppError(LocalizationKeys.EnableConnectToBlockchain))); } var keys = ToKeyArr(model.PostingKey); if (keys == null) { return(new OperationResult <object>(new AppError(LocalizationKeys.WrongPrivatePostingKey))); } return(await Task.Run(() => { var op = new FollowOperation(model.Login, "steepshot", DitchFollowType.Blog, model.Login); var properties = new DynamicGlobalPropertyApiObj { HeadBlockId = Hex.ToString(_operationManager.ChainId), Time = DateTime.Now, HeadBlockNumber = 0 }; var tr = _operationManager.CreateTransaction(properties, keys, ct, op); return new OperationResult <object>() { Result = tr }; }, ct)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "shortlinks")] HttpRequestMessage req, [JwtBinding("%JwtBinding:Issuer%", "%JwtBinding:Audience%")] AuthorizedModel auth ) { try { _logger.LogInformation($"Incoming request to create new short link to {req}"); var model = await req.Content.ReadAsAsync <ShortLinkCreateDto>(); var createdModel = await _service.CreateAsync(auth.Subject, model); _logger.LogWarning($"Created a new ShotLink to https://4dn.me/{createdModel.ShortCode}"); return(new CreatedResult("https://app.4dn.me", createdModel)); } catch (ShortLinkException shortLinkException) { _logger.LogWarning(shortLinkException, shortLinkException.Message); return(new ConflictObjectResult(shortLinkException.Errors)); } catch (Exception ex) { _logger.LogError(ex, "Unhandled exception occurred while trying to add a new short link"); return(new BadRequestObjectResult(ex.Message)); } }
public async Task LoginWithPostingKeyTest(KnownChains apiName) { var user = Users[apiName]; var request = new AuthorizedModel(user); var response = await Api[apiName].LoginWithPostingKey(request, CancellationToken.None); AssertResult(response); Assert.That(response.IsSuccess, Is.True); }
public async Task Login_With_Posting_Key_Wrong_Username(KnownChains apiName) { var user = Users[apiName]; user.Login += "x"; var request = new AuthorizedModel(user); var response = await Api[apiName].LoginWithPostingKey(request, CancellationToken.None); Assert.IsTrue(response.Error.Message.StartsWith("13 N5boost16exception_detail10clone_implINS0_19error_info_injectorISt12out_of_rangeEEEE: unknown key")); }
public async Task Login_With_Posting_Key_Wrong_PostingKey(KnownChains apiName) { var user = Users[apiName]; user.PostingKey += "x"; var request = new AuthorizedModel(user); var response = await Api[apiName].LoginWithPostingKey(request, CancellationToken.None); Assert.IsTrue(response.Error.Message.StartsWith(nameof(LocalizationKeys.WrongPrivatePostingKey))); }
public Task <IActionResult> GetAsync(string id) => RunProfileAsync(id, Permission.Read, async(entity) => { ProfileModel model = new ProfileModel(); MapEntityToModel(entity, model); AuthorizedModel <ProfileModel> result = new AuthorizedModel <ProfileModel>(model); result.OwnerId = entity.Id; result.OwnerName = entity.UserName; result.UserPermission = entity.Id == HttpContext.User.FindUserId() ? Permission.Write : Permission.Read; return(Ok(result)); });
public async Task <OperationResult <VoidResponse> > LoginWithPostingKey(AuthorizedModel model, CancellationToken ct) { var results = Validate(model); if (results.Any()) { return(new OperationResult <VoidResponse>(new ValidationError(results))); } var result = await _ditchClient.LoginWithPostingKey(model, ct); Trace("login-with-posting", model.Login, result.Error, string.Empty, ct);//.Wait(5000); return(result); }
private void LoginWithPostingKeyTest(StringBuilder sb, int num) { sb.Append($"{num}) LoginWithPostingKeyTest : "); StepFinished?.Invoke(sb.ToString()); var request = new AuthorizedModel(_user); var response = _api.LoginWithPostingKey(request, CancellationToken.None).Result; if (!response.IsSuccess) { sb.AppendLine($"fail. Reason:{Environment.NewLine} {response.Error.Message}"); return; } sb.AppendLine("pass."); }
public Task <IActionResult> Detail(string entryId, string imageId) => RunEntryAsync(entryId, Permission.Read, async entry => { Image entity = await dataContext.Images.FirstOrDefaultAsync(i => i.Entry.Id == entryId && i.Id == imageId); if (entity == null) { return(NotFound()); } var model = new ImageModel(); service.MapEntityToModel(entity, model, entry.UserId); var permission = model.UserId == User.FindUserId() || await shareStatus.IsEntrySharedForWriteAsync(entryId, User.FindUserId()) ? Permission.Write : Permission.Read; AuthorizedModel <ImageModel> result = new AuthorizedModel <ImageModel>(model); result.OwnerId = entry.UserId; result.OwnerName = await userNames.GetUserNameAsync(entry.UserId); result.UserPermission = permission; return(Ok(result)); });
public async Task <ActionResult <AuthorizedModel <EntryModel> > > Get(string id) { Ensure.NotNullOrEmpty(id, "id"); Entry entity = await db.Entries.FindAsync(id); if (entity == null) { return(NotFound()); } Permission permission = Permission.Write; string userId = HttpContext.User.FindUserId(); if (entity.UserId != userId) { if (!await shareStatus.IsEntrySharedForReadAsync(id, userId)) { return(Unauthorized()); } if (!await shareStatus.IsEntrySharedForWriteAsync(id, userId)) { permission = Permission.Read; } } EntryModel model = new EntryModel(); MapEntityToModel(entity, model); AuthorizedModel <EntryModel> result = new AuthorizedModel <EntryModel>(model); result.OwnerId = entity.UserId; result.OwnerName = await userNames.GetUserNameAsync(entity.UserId); result.UserPermission = permission; return(Ok(result)); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "shortlink/{id:guid}")] HttpRequest req, [JwtBinding("%JwtBinding:Issuer%", "%JwtBinding:Audience%")] AuthorizedModel auth, Guid id) { try { var details = await _service.ReadAsync(auth.Subject, id); return(new OkObjectResult(details)); } catch (ShortLinkException shortLinkException) { _logger.LogWarning(shortLinkException, shortLinkException.Message); return(new ConflictObjectResult(shortLinkException.Errors)); } catch (Exception ex) { _logger.LogError(ex, "Unhandled exception occurred while trying to add a new short link"); return(new BadRequestObjectResult(ex.Message)); } }
public Task <IActionResult> Get(string id) => RunBeingAsync(id, Permission.Read, async entity => { Permission permission = Permission.Write; string userId = HttpContext.User.FindUserId(); if (entity.UserId != userId) { if (!await shareStatus.IsBeingSharedForWriteAsync(id, userId)) { permission = Permission.Read; } } BeingModel model = new BeingModel(); MapEntityToModel(entity, model); AuthorizedModel <BeingModel> result = new AuthorizedModel <BeingModel>(model); result.OwnerId = entity.UserId; result.OwnerName = await userNames.GetUserNameAsync(entity.UserId); result.UserPermission = permission; return(Ok(result)); });
public override async Task <OperationResult <VoidResponse> > LoginWithPostingKey(AuthorizedModel model, CancellationToken ct) { return(await Task.Run(() => { if (!TryReconnectChain(ct)) { return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.EnableConnectToBlockchain)); } var keys = ToKeyArr(model.PostingKey); if (keys == null) { return new OperationResult <VoidResponse>(new AppError(LocalizationKeys.WrongPrivatePostingKey)); } var op = new FollowOperation(model.Login, "steepshot", DitchFollowType.Blog, model.Login); var resp = _operationManager.VerifyAuthority(keys, ct, op); var result = new OperationResult <VoidResponse>(); if (!resp.IsError) { result.Result = new VoidResponse(); } else { OnError(resp, result); } return result; }, ct)); }
private Task <OperationResult <VoidResponse> > SignIn(string login, string postingKey, CancellationToken ct) { var request = new AuthorizedModel(login, postingKey); return(Api.LoginWithPostingKey(request, ct)); }
public abstract Task <OperationResult <object> > GetVerifyTransaction(AuthorizedModel model, CancellationToken ct);
public abstract Task <OperationResult <VoidResponse> > LoginWithPostingKey(AuthorizedModel model, CancellationToken ct);