modify password ok
This commit is contained in:
@@ -67,6 +67,9 @@
|
||||
<RoomsetLayout back={layouts[1]} />
|
||||
|
||||
{:else if $layout === "password"}
|
||||
<PasswordLayout back={layouts[1]} />
|
||||
|
||||
{:else if $layout === "add_password"}
|
||||
<PasswordLayout back={layouts[1]} mode="add" />
|
||||
|
||||
{:else if $layout === "change_password"}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
|
||||
import { layout, current_room } from './Store_chat';
|
||||
import { change_room, send_password } from './Request_rooms';
|
||||
import { change_room, validate_password, change_password, add_password, remove_password } from './Request_rooms';
|
||||
import { FetchResponse } from './Types_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
import Warning from './Element_warning.svelte';
|
||||
|
||||
export let back = "";
|
||||
export let mode = "add";
|
||||
export let mode = "validate";
|
||||
|
||||
let password_state = "";
|
||||
if (mode === 'change')
|
||||
@@ -16,6 +16,7 @@
|
||||
password_state = "current";
|
||||
|
||||
let room_password: string;
|
||||
let room_old_password: string;
|
||||
let response: FetchResponse;
|
||||
let show_error = false;
|
||||
|
||||
@@ -31,12 +32,21 @@
|
||||
let room = {
|
||||
name: $current_room.name,
|
||||
type: $current_room.type,
|
||||
protection: true,
|
||||
password: room_password,
|
||||
};
|
||||
room.protection = true;
|
||||
if (mode === 'remove')
|
||||
room.protection = false;
|
||||
|
||||
// send password
|
||||
response = await send_password(room);
|
||||
if (mode === 'validate')
|
||||
response = await validate_password(room);
|
||||
if (mode === 'add')
|
||||
response = await add_password(room);
|
||||
if (mode === 'change')
|
||||
response = await change_password(room, room_old_password);
|
||||
if (mode === 'remove')
|
||||
response = await remove_password(room);
|
||||
|
||||
// go to room
|
||||
if (response.status >= 300 || response.error)
|
||||
@@ -72,8 +82,8 @@
|
||||
<Warning content={response.message}/>
|
||||
{/if}
|
||||
{#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>
|
||||
<label for="chat_old_pswd"><p>enter old password :</p></label>
|
||||
<input id="chat_old_pswd" bind:value={room_old_password} type="password" placeholder="minimum 8 characters" minlength="8" name="old_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>
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
remove password
|
||||
</Button>
|
||||
{:else}
|
||||
<Button new_layout="password">
|
||||
<Button new_layout="add_password">
|
||||
add password
|
||||
</Button>
|
||||
{/if}
|
||||
|
||||
@@ -60,14 +60,52 @@ console.log("room returned from change:", response.room);
|
||||
layout.set("room");
|
||||
}
|
||||
|
||||
export async function validate_password(room: Room)
|
||||
{
|
||||
console.log("in validate_password");
|
||||
|
||||
export async function send_password(room: Room)
|
||||
console.log("room sent to validate password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||
console.log("room returned from validate password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function add_password(room: Room)
|
||||
{
|
||||
console.log("in add_password");
|
||||
|
||||
console.log("room sent to add password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
||||
console.log("room returned from add password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function change_password(room: Room, old_password: string)
|
||||
{
|
||||
console.log("in send_password");
|
||||
|
||||
console.log("room sent to set password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||
console.log("room returned from set password:", response.room);
|
||||
let request_body =
|
||||
{
|
||||
room: room,
|
||||
old_password: old_password,
|
||||
}
|
||||
|
||||
console.log("room sent to change password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
||||
console.log("room returned from change password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function remove_password(room: Room)
|
||||
{
|
||||
console.log("in send_password");
|
||||
|
||||
console.log("room sent to remove password:", room);
|
||||
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
||||
console.log("room returned from remove password:", response.room);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ export enum FetchMethod
|
||||
{
|
||||
POST = 'POST',
|
||||
GET = 'GET',
|
||||
LEAVE = 'LEAVE',
|
||||
DELETE = 'DELETE',
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user