wip change password
+ little clean in files, delete some
This commit is contained in:
@@ -203,13 +203,7 @@ export class ChatController {
|
||||
printCaller("- in ");
|
||||
|
||||
let fields = ["protection", "allowed_users"];
|
||||
//const room_db = await this.chatService.getRoomByName(room.name, fields);
|
||||
const room_db = await this.chatService.getRoomByName(room.name);
|
||||
|
||||
console.log("room.name:", room.name);
|
||||
console.log("room_db:", room_db);
|
||||
const all_rooms = await this.chatService.getAllRooms();
|
||||
console.log("all_rooms:", all_rooms);
|
||||
const room_db = await this.chatService.getRoomByName(room.name, fields);
|
||||
|
||||
if (room_db.protection === true)
|
||||
{
|
||||
@@ -231,8 +225,8 @@ export class ChatController {
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('password')
|
||||
async setPassword(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
||||
@Post('passwordauth')
|
||||
async passwordAuthentication(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
@@ -254,6 +248,21 @@ export class ChatController {
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('changepassword')
|
||||
async changePassword(@Body('room') room: roomDto, @Body('old_password') old_password: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||
await this.chatService.addPassword(req.user.username, room, socket, old_password);
|
||||
|
||||
const ret_room = this.format_room(room);
|
||||
res.status(HttpStatus.OK).json({ room: ret_room });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('invite')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
|
||||
import Layouts from './Chat_layouts.svelte';
|
||||
import { init_socket } from './Socket_init';
|
||||
import { init_socket } from './Socket_chat';
|
||||
|
||||
export let color = "transparent";
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<script lang="ts">
|
||||
|
||||
import Debug from './tmp_debug.svelte';
|
||||
|
||||
import { layout } from './Store_chat';
|
||||
import ChatBox from './Chat_box_css.svelte';
|
||||
|
||||
@@ -11,7 +9,7 @@
|
||||
import NewLayout from './Layout_new.svelte';
|
||||
import SettingsLayout from './Layout_settings.svelte';
|
||||
import RoomsetLayout from './Layout_room_set.svelte';
|
||||
import ProtectedLayout from './Layout_protected.svelte';
|
||||
import PasswordLayout from './Layout_password.svelte';
|
||||
import CreateLayout from './Layout_create.svelte';
|
||||
import MuteLayout from './Layout_mute.svelte';
|
||||
import UserLayout from './Layout_user.svelte';
|
||||
@@ -68,8 +66,14 @@
|
||||
{:else if $layout === "room_set"}
|
||||
<RoomsetLayout back={layouts[1]} />
|
||||
|
||||
{:else if $layout === "protected"}
|
||||
<ProtectedLayout back={layouts[1]} />
|
||||
{:else if $layout === "password"}
|
||||
<PasswordLayout back={layouts[1]} mode="add" />
|
||||
|
||||
{:else if $layout === "change_password"}
|
||||
<PasswordLayout back={layouts[1]} mode="change" />
|
||||
|
||||
{:else if $layout === "remove_password"}
|
||||
<PasswordLayout back={layouts[1]} mode="remove" />
|
||||
|
||||
{:else if $layout === "create"}
|
||||
<CreateLayout back={layouts[1]} />
|
||||
@@ -87,8 +91,5 @@
|
||||
|
||||
</ChatBox>
|
||||
|
||||
<!-- TMP DEBUG -->
|
||||
<Debug bind:layouts />
|
||||
|
||||
<style></style>
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
if (room.protection && !room.allowed)
|
||||
{
|
||||
await current_room.set(room);
|
||||
layout.set("protected");
|
||||
layout.set("password");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
if (updated_room.protection)
|
||||
{
|
||||
current_room.set(updated_room);
|
||||
layout.set("protected");
|
||||
layout.set("password");
|
||||
}
|
||||
else
|
||||
await change_room(updated_room);
|
||||
|
||||
@@ -7,6 +7,12 @@
|
||||
import Warning from './Element_warning.svelte';
|
||||
|
||||
export let back = "";
|
||||
export let mode = "add";
|
||||
let password_state = "";
|
||||
if (mode === 'change')
|
||||
password_state = "new";
|
||||
if (mode === 'remove')
|
||||
password_state = "current";
|
||||
|
||||
let room_password: string;
|
||||
let response: FetchResponse;
|
||||
@@ -49,7 +55,7 @@
|
||||
|
||||
<!-- room_name -->
|
||||
<Button my_class="room_name deactivate">
|
||||
<room_name>
|
||||
{$current_room.name}
|
||||
</Button>
|
||||
|
||||
<!-- close -->
|
||||
@@ -57,14 +63,18 @@
|
||||
close
|
||||
</Button>
|
||||
|
||||
<!-- panel_protected -->
|
||||
<div class="panel panel_protected __border_top">
|
||||
<!-- panel_password -->
|
||||
<div class="panel panel_password __border_top">
|
||||
<p class="title __center">this room is protected</p>
|
||||
<form on:submit|preventDefault={handleSubmit}>
|
||||
{#if show_error}
|
||||
<Warning content={response.message}/>
|
||||
{/if}
|
||||
<label for="chat_pswd"><p>enter password :</p></label>
|
||||
{#if mode === 'change'}
|
||||
<label for="chat_pswd"><p>enter old password :</p></label>
|
||||
<input id="chat_pswd" bind:value={room_password} type="password" placeholder="minimum 8 characters" minlength="8" name="password" required>
|
||||
{/if}
|
||||
<label for="chat_pswd"><p>enter {password_state} password :</p></label>
|
||||
<input id="chat_pswd" bind:value={room_password} type="password" placeholder="minimum 8 characters" minlength="8" name="password" required>
|
||||
<input type="submit" value="⮡">
|
||||
</form>
|
||||
@@ -74,17 +84,17 @@
|
||||
|
||||
<style>
|
||||
|
||||
/* grid layout "protected"
|
||||
/* grid layout "password"
|
||||
*/
|
||||
.grid_box :global(.back ) {grid-area: back;}
|
||||
.grid_box :global(.room_name ) {grid-area: room_name;}
|
||||
.grid_box :global(.close ) {grid-area: close;}
|
||||
.grid_box :global(.panel_protected) {grid-area: panel_protected;}
|
||||
.grid_box :global(.back ) {grid-area: back;}
|
||||
.grid_box :global(.room_name ) {grid-area: room_name;}
|
||||
.grid_box :global(.close ) {grid-area: close;}
|
||||
.grid_box :global(.panel_password) {grid-area: panel_password;}
|
||||
.grid_box {
|
||||
grid:
|
||||
' back room_name close ' auto
|
||||
' panel_protected panel_protected panel_protected ' 1fr
|
||||
/ auto 1fr auto ;
|
||||
' back room_name close ' auto
|
||||
' panel_password panel_password panel_password ' 1fr
|
||||
/ auto 1fr auto ;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,21 +10,6 @@
|
||||
|
||||
console.log("current_room:", $current_room);
|
||||
|
||||
function change_password()
|
||||
{
|
||||
console.log("in change_password");
|
||||
}
|
||||
|
||||
function remove_password()
|
||||
{
|
||||
console.log("in remove_password");
|
||||
}
|
||||
|
||||
function add_password()
|
||||
{
|
||||
console.log("in add_password");
|
||||
}
|
||||
|
||||
function user_profile()
|
||||
{
|
||||
console.log("in user_profile");
|
||||
@@ -68,14 +53,14 @@
|
||||
{/if}
|
||||
{#if $current_room.protection }
|
||||
<p class="__center">this room is password protected</p>
|
||||
<Button on:click={change_password}>
|
||||
<Button new_layout="change_password">
|
||||
change password
|
||||
</Button>
|
||||
<Button on:click={remove_password}>
|
||||
<Button new_layout="remove_password">
|
||||
remove password
|
||||
</Button>
|
||||
{:else}
|
||||
<Button on:click={add_password}>
|
||||
<Button new_layout="password">
|
||||
add password
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function send_password(room: Room)
|
||||
console.log("in send_password");
|
||||
|
||||
console.log("room sent to set password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('password', FetchMethod.POST, room);
|
||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||
console.log("room returned from set password:", response.room);
|
||||
|
||||
return response;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import io from 'socket.io-client';
|
||||
import { set_socket, set_user } from './Store_chat';
|
||||
import { socket_events } from './Socket_events';
|
||||
import { user, msgs } from './Store_chat';
|
||||
|
||||
const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`;
|
||||
|
||||
@@ -21,6 +21,23 @@ export async function init_socket()
|
||||
});
|
||||
set_socket(socket);
|
||||
|
||||
socket_states(socket);
|
||||
socket_events(socket);
|
||||
}
|
||||
|
||||
function socket_events(socket)
|
||||
{
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||
});
|
||||
}
|
||||
|
||||
function socket_states(socket)
|
||||
{
|
||||
socket.on('connect', function(){ console.log("socket.io connected"); });
|
||||
socket.on('disconnect', function(){ console.log("socket.io disconnected"); });
|
||||
socket.on('connect_error', function(){ console.log("socket.io connect_error"); });
|
||||
@@ -33,7 +50,5 @@ export async function init_socket()
|
||||
socket.on('reconnect_failed', function(){ console.log("socket.io reconnect_failed"); });
|
||||
socket.on('ping', function(){ console.log("socket.io ping"); });
|
||||
socket.on('pong', function(){ console.log("socket.io pong"); });
|
||||
|
||||
socket_events(socket);
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { user, msgs } from './Store_chat';
|
||||
|
||||
export function socket_events(socket)
|
||||
{
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||
});
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<script>
|
||||
|
||||
export let layout = "";
|
||||
export let layouts = [];
|
||||
|
||||
</script>
|
||||
|
||||
<div style="display: flex; flex-direction: column; font-size: 12px; position: fixed; top: 20px; left: 20px; background-color: white;">
|
||||
<p>temp, for testing :</p>
|
||||
<button on:click={function(){layout = "close" }}>close</button>
|
||||
<button on:click={function(){layout = "home" }}>home</button>
|
||||
<button on:click={function(){layout = "room" }}>room</button>
|
||||
<button on:click={function(){layout = "new" }}>new</button>
|
||||
<button on:click={function(){layout = "settings" }}>settings</button>
|
||||
<button on:click={function(){layout = "room_set" }}>room_set</button>
|
||||
<button on:click={function(){layout = "protected"}}>protected</button>
|
||||
<button on:click={function(){layout = "create" }}>create</button>
|
||||
<button on:click={function(){layout = "mute" }}>mute</button>
|
||||
<button on:click={function(){
|
||||
layouts = ["settings", "settings"];
|
||||
layout = "user";
|
||||
}}>user from settings</button>
|
||||
<button on:click={function(){
|
||||
layouts = ["room_set", "room_set"];
|
||||
layout = "user";
|
||||
}}>user from room_set</button>
|
||||
</div>
|
||||
Reference in New Issue
Block a user