fucking DELETE method for account is now working and existing
This commit is contained in:
@@ -146,7 +146,8 @@ export class ChatService {
|
|||||||
const user_db = await this.getUserByName(username);
|
const user_db = await this.getUserByName(username);
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
return user_db.currentRoom;
|
if (user_db)
|
||||||
|
return user_db.currentRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRoomByName(room_name: string, fieldsToReturn: string[] = null): Promise<Chatroom>
|
async getRoomByName(room_name: string, fieldsToReturn: string[] = null): Promise<Chatroom>
|
||||||
|
|||||||
@@ -43,14 +43,14 @@ export class User {
|
|||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
secretTwoFactorAuth: string;
|
secretTwoFactorAuth: string;
|
||||||
|
|
||||||
@OneToMany(type => Friendship , (friendship) => friendship.sender)
|
@OneToMany(type => Friendship , (friendship) => friendship.sender, {onDelete: 'CASCADE'})
|
||||||
sentFriendRequest: Friendship[];
|
sentFriendRequest: Friendship[];
|
||||||
|
|
||||||
@OneToMany(type => Friendship , (friendship) => friendship.receiver)
|
@OneToMany(type => Friendship , (friendship) => friendship.receiver, {onDelete: 'CASCADE'})
|
||||||
receivedFriendRequest: Friendship[];
|
receivedFriendRequest: Friendship[];
|
||||||
|
|
||||||
@JoinColumn()
|
@JoinColumn()
|
||||||
@OneToOne(() => UserStats, { cascade: true })
|
@OneToOne(() => UserStats, { cascade: true, onDelete: 'CASCADE' })
|
||||||
stats: UserStats;
|
stats: UserStats;
|
||||||
|
|
||||||
// ROOMS :
|
// ROOMS :
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
Body, Controller, Delete, Get, NotFoundException,HttpStatus, Param, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
|
Body, Controller, Delete, Get, NotFoundException,HttpStatus, Next, Patch, Post, Query, Redirect, Req, Res, UploadedFile, UseGuards, UseInterceptors
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { FileInterceptor } from '@nestjs/platform-express';
|
import { FileInterceptor } from '@nestjs/platform-express';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
@@ -73,8 +73,14 @@ export class UsersController {
|
|||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Delete()
|
@Delete()
|
||||||
remove(@Req() req) {
|
remove(@Req() req, @Res() response, @Next() next) {
|
||||||
return this.usersService.remove(req.user.id);
|
this.usersService.remove(req.user.id);
|
||||||
|
req.logout(function(err) {
|
||||||
|
if (err) { return next(err); }
|
||||||
|
response.redirect('/');
|
||||||
|
});
|
||||||
|
req.session.cookie.maxAge = 0;
|
||||||
|
return {msg : 'Your account has been deleted'};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,23 @@
|
|||||||
avatar = await fetchAvatar(user.username);
|
avatar = await fetchAvatar(user.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteAccount = async() => {
|
||||||
|
console.log("deleting account")
|
||||||
|
await fetch(`http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}/api/v2/user`, {
|
||||||
|
method: "DELETE",
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("HTTP " + response.status);
|
||||||
|
}
|
||||||
|
console.log("account deleted")
|
||||||
|
push('/');
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("catch unable to delete: ", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
@@ -152,6 +169,7 @@
|
|||||||
</form>
|
</form>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
<Button type="primary" on:click={() => deleteAccount()}>Delete Account</Button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user