public async Task <ActionResult> Delete([FromRoute] Guid id) { var link = await database.GetById <LinkModel>(id); if (link == null) { return(NotFound()); } if (!Can(Permissions.DELETE_LINKS, link)) { return(NotFound()); } var accesses = await database.GetWhere <AccessModel>(a => a.Link.Guid == id).ToArrayAsync(); database.DeleteRange(accesses); database.Delete(link); await database.Commit(); await cache.Remove <LinkModel>(link.Ident); return(NoContent()); }
public async Task <IActionResult> Logout() { if (!HttpContext.Request.ExtractAccessToken(out var accessToken) || !accessTokenHandler.ValidateAndRestore <AuthClaims>(accessToken, out var identity)) { return(Unauthorized(Constants.INVALID_ACCESS_TOKEN)); } var refreshToken = await database.GetRefreshTokenByUserUid(identity.UserUid); if (refreshToken != null) { await database.Delete <RefreshTokenModel>(refreshToken.Uid); } var cookieOptions = new CookieOptions { Expires = DateTime.Now, HttpOnly = true, }; Response.Cookies.Append(Constants.REFRESH_TOKEN_COOKIE, "", cookieOptions); return(NoContent()); }
public async Task <ActionResult> Delete([FromRoute] Guid id) { var user = await database.GetById <UserModel>(id); if (user == null) { return(NotFound()); } var userLinks = await database.GetWhere <LinkModel>(l => l.Creator.Guid == id).ToArrayAsync(); foreach (var link in userLinks) { var accesses = await database.GetWhere <AccessModel>(a => a.Link.Guid == link.Guid).ToArrayAsync(); database.DeleteRange(accesses); } database.DeleteRange(userLinks); database.Delete(user); await database.Commit(); return(NoContent()); }
public async Task <ActionResult> Delete([FromRoute] Guid uid) { var tag = await database.Get <TagModel>(uid); if (tag == null) { return(NotFound()); } await database.Delete <TagModel>(uid); return(NoContent()); }
public async Task <ActionResult <ApiKeyCreatedViewModel> > CreateApiKey() { var apiKey = await GetMyApiKey(); if (apiKey != null) { database.Delete(apiKey); } var key = RandomUtil.GetString(Constants.RandomApiKeyLength, Constants.RandomApiKeyChars); var keyModel = new ApiKeyModel() { User = AuthorizedUser, KeyHash = await hasher.GetEncodedHash(key), }; database.Create(keyModel); await database.Commit(); return(Created( $"/api/apikey/{keyModel.Guid}", new ApiKeyCreatedViewModel(keyModel, key))); }
public async Task <ActionResult <ImageModel> > DeleteImage([FromRoute] Guid uid) { var image = await database.Get <ImageModel>(uid); if (image == null || (image.OwnerUid != authClaims.UserUid && !authClaims.User.IsAdmin.Equals(true))) { return(NotFound()); } await database.Delete <ImageModel>(uid); await storage.Delete(image.Bucket, image.BlobName); return(NoContent()); }
public int Delete(object objId) { return(_databaseAccess.Delete(objId)); }
public async Task <IActionResult> DeleteUser([FromRoute] Guid uid) { await database.Delete <UserModel>(uid); return(NoContent()); }