feat: made accounts deleteable, other changes
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
c20c5c9343
commit
8f38879294
10 changed files with 116 additions and 35 deletions
|
@ -31,7 +31,7 @@ public static class CommentsRepository
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<CommentData> getCommentByGETAsync(string board, int get)
|
public static async Task<CommentData> getCommentByGETAsync(string board, int get)
|
||||||
{
|
{
|
||||||
await using var db = new AppDBContext();
|
await using var db = new AppDBContext();
|
||||||
return await db.Comments
|
return await db.Comments
|
||||||
|
@ -44,16 +44,14 @@ public static class CommentsRepository
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static async Task<PostData> getPostByIdAsync(int postId)
|
public static async Task deleteCommentFromUser(UserData u)
|
||||||
{
|
{
|
||||||
await using var db = new AppDBContext();
|
await using var db = new AppDBContext();
|
||||||
return await db.Posts
|
var l = db.Users
|
||||||
.Where(post => post.PostID == postId)
|
.Where(x => x.UserID == u.UserID);
|
||||||
.Include(post => post.Image)
|
foreach (var e in l)
|
||||||
.Include(post => post.Comments)
|
db.Remove(e);
|
||||||
.FirstOrDefaultAsync();
|
}
|
||||||
//return await db.Posts.FirstOrDefaultAsync(post => post.PostID == postId);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static async Task<int> createCommentAsync(CommentData commentData)
|
public static async Task<int> createCommentAsync(CommentData commentData)
|
||||||
{
|
{
|
||||||
|
@ -64,6 +62,7 @@ public static class CommentsRepository
|
||||||
Console.WriteLine($"Created comment with ID: {commentData.PostID}");
|
Console.WriteLine($"Created comment with ID: {commentData.PostID}");
|
||||||
return commentData.PostID;
|
return commentData.PostID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,9 +55,19 @@ public static class PostsRepository
|
||||||
Console.WriteLine($"Created post with ID: {postToCreate.PostID}");
|
Console.WriteLine($"Created post with ID: {postToCreate.PostID}");
|
||||||
return postToCreate.PostID;
|
return postToCreate.PostID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task deletePostsFromUser(UserData u)
|
||||||
|
{
|
||||||
|
await using var db = new AppDBContext();
|
||||||
|
var l = db.Posts
|
||||||
|
.Where(x => x.UserID == u.UserID);
|
||||||
|
foreach (var e in l)
|
||||||
|
db.Remove(e);
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<bool> updatePostAsync(PostData postToUpdate)
|
public static async Task<bool> updatePostAsync(PostData postToUpdate)
|
||||||
{
|
{
|
||||||
await using var db = new AppDBContext();
|
await using var db = new AppDBContext();
|
||||||
|
|
57
ImageBoardServerApp/Pages/Accounts/DeleteAccount.razor
Normal file
57
ImageBoardServerApp/Pages/Accounts/DeleteAccount.razor
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
@page "/sys/delacc"
|
||||||
|
@using ImageBoardServerApp.Data.Repository
|
||||||
|
@using ImageBoardServerApp.Auth
|
||||||
|
@inject IJSRuntime js
|
||||||
|
@inject AuthenticationStateProvider authStateProvider
|
||||||
|
@inject NavigationManager navManager
|
||||||
|
|
||||||
|
<PageTitle>Delete your account - BulletBoards</PageTitle>
|
||||||
|
<h3 class="headLogin">Delete your account</h3>
|
||||||
|
<div class="login">
|
||||||
|
<form>
|
||||||
|
<RadzenFormField Text="Email" Variant="Variant.Outlined">
|
||||||
|
<RadzenTextBox @bind-Value="@Email"/>
|
||||||
|
</RadzenFormField>
|
||||||
|
<br/>
|
||||||
|
<RadzenFormField Text="Password" Variant="Variant.Outlined">
|
||||||
|
<RadzenPassword @bind-Value="@Password"/>
|
||||||
|
</RadzenFormField>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<RadzenButton Click=@del Text="delete account" ButtonStyle="ButtonStyle.Secondary"/>
|
||||||
|
<br/>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private bool verified;
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
private async void del()
|
||||||
|
{
|
||||||
|
var user = await UsersRepository.getUserByEmailAsync(Email);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await js.InvokeVoidAsync("alert", "User does not exist");
|
||||||
|
verified = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Console.WriteLine("loggin you in...");
|
||||||
|
verified = BCrypt.Net.BCrypt.Verify(Password, user.Password);
|
||||||
|
if (verified)
|
||||||
|
{
|
||||||
|
await CommentsRepository.deleteCommentFromUser(user);
|
||||||
|
await PostsRepository.deletePostsFromUser(user);
|
||||||
|
|
||||||
|
await UsersRepository.deleteUserAsync(user.UserID);
|
||||||
|
var customAuthStateProvider = (CustomAuthenticationStateProvider)authStateProvider;
|
||||||
|
await customAuthStateProvider.UpdateAuthenticationStateAsync(null);
|
||||||
|
navManager.NavigateTo("/", true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await js.InvokeVoidAsync("alert", $"Wrong Password");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
@inject AuthenticationStateProvider authStateProvider
|
@inject AuthenticationStateProvider authStateProvider
|
||||||
@inject NavigationManager navManager
|
@inject NavigationManager navManager
|
||||||
|
|
||||||
<PageTitle>Login - Bulletboards</PageTitle>
|
<PageTitle>Login - BulletBoards</PageTitle>
|
||||||
<h3 class="headLogin">Login to Bulletboards</h3>
|
<h3 class="headLogin">Login to Bulletboards</h3>
|
||||||
<div class="login">
|
<div class="login">
|
||||||
<form>
|
<form>
|
||||||
|
@ -25,8 +25,6 @@
|
||||||
<a href="/sys/resetpw">Reset Password</a>
|
<a href="/sys/resetpw">Reset Password</a>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private Variant vari = Variant.Outlined;
|
|
||||||
|
|
||||||
private bool verified;
|
private bool verified;
|
||||||
|
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<a href="/sys/logout">[Logout]</a>
|
<a href="/sys/logout">[Logout]</a>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<a href="/sys/delacc">[Delete Account]</a>
|
||||||
|
|
||||||
</Authorized>
|
</Authorized>
|
||||||
<NotAuthorized>
|
<NotAuthorized>
|
||||||
|
|
|
@ -39,6 +39,7 @@ else
|
||||||
|
|
||||||
private List<PostData> posts;
|
private List<PostData> posts;
|
||||||
|
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
|
@ -78,6 +78,12 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
postUsername = foundusr.LastUsedName;
|
postUsername = foundusr.LastUsedName;
|
||||||
|
if (!foundusr.ConfirmedEmail)
|
||||||
|
{
|
||||||
|
hasErr = true;
|
||||||
|
postErr = "You cannot post without an verified email.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
await base.OnAfterRenderAsync(firstRender);
|
await base.OnAfterRenderAsync(firstRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,12 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
postUsername = foundusr.LastUsedName;
|
postUsername = foundusr.LastUsedName;
|
||||||
|
if (!foundusr.ConfirmedEmail)
|
||||||
|
{
|
||||||
|
hasErr = true;
|
||||||
|
postErr = "You cannot post without an verified email.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
await base.OnAfterRenderAsync(firstRender);
|
await base.OnAfterRenderAsync(firstRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ namespace ImageBoardServerApp.Util;
|
||||||
|
|
||||||
public class TheManager
|
public class TheManager
|
||||||
{
|
{
|
||||||
|
|
||||||
private static long getDiff(PostData post)
|
private static long getDiff(PostData post)
|
||||||
{
|
{
|
||||||
return (DateTimeOffset.Now.ToUnixTimeMilliseconds() - post.CreatedAt);
|
return (DateTimeOffset.Now.ToUnixTimeMilliseconds() - post.CreatedAt);
|
||||||
|
@ -24,7 +23,9 @@ public class TheManager
|
||||||
|
|
||||||
public static long getBumpValue(PostData post)
|
public static long getBumpValue(PostData post)
|
||||||
{
|
{
|
||||||
return (post.IsSticky ? 999999999999999999 + getDiff(post) : 10 * 60000 - getDiff(post) + ( 60000 * (post.Comments.Count + 1))) ;
|
return (post.IsSticky
|
||||||
|
? 999999999999999999 + getDiff(post)
|
||||||
|
: 10 * 60000 - getDiff(post) + (60000 * (post.Comments.Count + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<PostData>> getPostList(string boardTag)
|
public static async Task<List<PostData>> getPostList(string boardTag)
|
||||||
|
@ -49,15 +50,15 @@ public class TheManager
|
||||||
|
|
||||||
public static async Task deleteThread(PostData post)
|
public static async Task deleteThread(PostData post)
|
||||||
{
|
{
|
||||||
foreach(var c in post.Comments)
|
foreach (var c in post.Comments)
|
||||||
{
|
{
|
||||||
if (c.Image != null)
|
if (c.Image != null)
|
||||||
{
|
{
|
||||||
deleteImage(c.Image);
|
await deleteImage(c.Image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteImage(post.Image);
|
await deleteImage(post.Image);
|
||||||
|
|
||||||
await PostsRepository.deletePostAsync(post.PostID);
|
await PostsRepository.deletePostAsync(post.PostID);
|
||||||
}
|
}
|
||||||
|
@ -66,16 +67,16 @@ public class TheManager
|
||||||
{
|
{
|
||||||
if (comment.Image != null)
|
if (comment.Image != null)
|
||||||
{
|
{
|
||||||
deleteImage(comment.Image);
|
await deleteImage(comment.Image);
|
||||||
}
|
}
|
||||||
|
|
||||||
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
await CommentsRepository.deleteCommentAsync(comment.CommentID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteImage(ImageData imageData)
|
public static async Task deleteImage(ImageData imageData)
|
||||||
{
|
{
|
||||||
string path = $"./wwwroot{imageData.ImageLocation}";
|
string path = $"./wwwroot{imageData.ImageLocation}";
|
||||||
|
Console.WriteLine(path);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(path);
|
File.Delete(path);
|
||||||
|
|
Loading…
Reference in a new issue