Пример #1
0
        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());
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }
Пример #4
0
        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());
        }
Пример #5
0
        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)));
        }
Пример #6
0
        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());
        }
Пример #7
0
 public int Delete(object objId)
 {
     return(_databaseAccess.Delete(objId));
 }
Пример #8
0
        public async Task <IActionResult> DeleteUser([FromRoute] Guid uid)
        {
            await database.Delete <UserModel>(uid);

            return(NoContent());
        }