Passphrase validation and message send updated
This commit is contained in:
parent
ff43977f93
commit
b236b87e5d
@ -126,4 +126,9 @@ export class ChatModel implements Subject<ChatMessageViewModel> {
|
||||
|
||||
return cVMs;
|
||||
}
|
||||
|
||||
public async isPassphraseValid(passphrase: string, userName: string): Promise<boolean> {
|
||||
let valid = await this._chatModelHelper.isPassphraseValid(passphrase, userName);
|
||||
return valid;
|
||||
}
|
||||
}
|
@ -12,26 +12,37 @@ export class ChatModelHelper {
|
||||
private readonly _notificationService: NotificationService;
|
||||
|
||||
|
||||
constructor(encryptionService: EncryptionService, notificationService: NotificationService) {
|
||||
constructor(encryptionService: EncryptionService, notificationService: NotificationService) {
|
||||
this._encryptionService = encryptionService;
|
||||
this._notificationService = notificationService;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async getMessages(userName: string, passphrase: string, page: number | null, lastMessageTime: string | null, op: string): Promise<ChatMessageViewModel[]> {
|
||||
switch (lastMessageTime) {
|
||||
case null: {
|
||||
const data: ChatMessageDTO[] = await this._getPaginatedMessagesAjax(userName, page!);
|
||||
const cVMs = Promise.all(data.map(vm => this._toChatMessageVMAsync(vm, passphrase)).reverse());
|
||||
return cVMs;
|
||||
const data: ChatMessageDTO[] = await this._getPaginatedMessagesAjax(userName, page!);
|
||||
const cVMs = Promise.all(data.map(vm => this._toChatMessageVMAsync(vm, passphrase)).reverse());
|
||||
return cVMs;
|
||||
}
|
||||
default: {
|
||||
const data: ChatMessageDTO[] = await this._getNewMessagesAjax(userName, lastMessageTime);
|
||||
const data: ChatMessageDTO[] = await this._getNewMessagesAjax(userName, lastMessageTime!);
|
||||
return data.map(vm => this._toChatMessageVM(vm, passphrase));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async isPassphraseValid(passphrase: string, userName: string): Promise<boolean> {
|
||||
const messages: ChatMessageDTO[] = await this._getPaginatedMessagesAjax(userName, 0);
|
||||
if(messages.length === 0) return true;
|
||||
try {
|
||||
this._encryptionService.decrypt(passphrase, messages[0].messageCipher)
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private async _toChatMessageVMAsync(chatMessageDTO: ChatMessageDTO, passphrase: string): Promise<ChatMessageViewModel> {
|
||||
const vm = new ChatMessageViewModel();
|
||||
vm.fromUser = chatMessageDTO.fromUser;
|
||||
|
@ -30,7 +30,7 @@ export class AlertifyNotificationService implements NotificationService {
|
||||
}
|
||||
passphrasePrompt(vm: ActiveUserViewModel, vms: ActiveUserViewModel[], cb1: (contactName: string, passphrase: string,
|
||||
lastMessageTime: string | null, op: string) => void,
|
||||
cb2: () => any): void {
|
||||
cb2: () => any, cb3: (...x: any) => any): void {
|
||||
|
||||
// alertify.myprompt || alertify.dialog('myprompt', function () {
|
||||
|
||||
@ -91,9 +91,15 @@ export class AlertifyNotificationService implements NotificationService {
|
||||
bootbox.prompt({
|
||||
title: "Please enter the passphrase",
|
||||
inputType: 'password',
|
||||
callback: function (result) {
|
||||
callback: async function (result) {
|
||||
if (result) {
|
||||
log.debug(result);
|
||||
const valid = await cb3(result, vm.userName);
|
||||
if (!valid) {
|
||||
bootbox.alert("Some error occured. Please check your password");
|
||||
log.error("invalid password");
|
||||
return;
|
||||
}
|
||||
cb1(vm.userName!, result, null, "new");
|
||||
vm.unlocked = true
|
||||
vms.filter(v => v.userName == vm.userName).map(v => { v.passphrase = result; v.unlocked = true })
|
||||
|
@ -6,5 +6,8 @@ export interface NotificationService {
|
||||
errorWithDelay(message: string, delay: number): void;
|
||||
warning(message: string): void;
|
||||
message(message: string): void;
|
||||
passphrasePrompt(vm: ActiveUserViewModel, vms: ActiveUserViewModel[], cb1: (...x: any) => any, cb2: (...x: any) => any): void;
|
||||
passphrasePrompt(vm: ActiveUserViewModel, vms: ActiveUserViewModel[],
|
||||
cb1: (...x: any) => any,
|
||||
cb2: (...x: any) => any,
|
||||
cb3: (...x: any) => any): void;
|
||||
}
|
@ -138,6 +138,7 @@ export class ChatView implements Observer<ChatMessageViewModel> {
|
||||
|
||||
const chatInput = document.getElementById('chatInput') as HTMLInputElement;
|
||||
const passphraseInput = document.getElementById('passphrase') as HTMLInputElement;
|
||||
const passphrase = this._userModel.activeUsersList.find(u => u.userName == JsonAPI.contactName)?.passphrase
|
||||
|
||||
if (chatInput.value == '' || chatInput.value == null) {
|
||||
this._notificationService.error("Please enter a message");
|
||||
@ -145,11 +146,11 @@ export class ChatView implements Observer<ChatMessageViewModel> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (passphraseInput.value == '' || passphraseInput.value == null) {
|
||||
this._notificationService.error("Please enter a passphrase");
|
||||
log.error("Passphrase is null.");
|
||||
return;
|
||||
}
|
||||
// if (passphraseInput.value == '' || passphraseInput.value == null) {
|
||||
// this._notificationService.error("Please enter a passphrase");
|
||||
// log.error("Passphrase is null.");
|
||||
// return;
|
||||
// }
|
||||
|
||||
const messageContent = chatInput.value;
|
||||
const msgTime = new Date();
|
||||
@ -162,7 +163,7 @@ export class ChatView implements Observer<ChatMessageViewModel> {
|
||||
|
||||
this.update({data: new Array(context), op: "new"})
|
||||
|
||||
let messageCipher: MessageCipherDTO = this._encryptionService.encrypt(passphraseInput.value, messageContent)
|
||||
let messageCipher: MessageCipherDTO = this._encryptionService.encrypt(passphrase!, messageContent)
|
||||
let chatMessageDTO = {
|
||||
"fromUser": JsonAPI.principleName || "",
|
||||
"toUser": contactName,
|
||||
|
@ -69,19 +69,19 @@ export class UserView implements Observer<ActiveUserViewModel> {
|
||||
|
||||
let passphrase: string = '';
|
||||
if (current.length > 0) {
|
||||
let passphraseInput = document.getElementById('passphrase') as any;
|
||||
// let passphraseInput = document.getElementById('passphrase') as any;
|
||||
|
||||
if (passphraseInput == null) {
|
||||
log.error('passphraseInput element reference is null');
|
||||
return;
|
||||
}
|
||||
passphrase = passphraseInput.value
|
||||
if (passphrase == '' || passphrase == null) {
|
||||
// alert('Please input passphrase')
|
||||
// alertify.error('Please enter a passphrase');
|
||||
log.error('passphrase is empty or null');
|
||||
return;
|
||||
}
|
||||
// if (passphraseInput == null) {
|
||||
// log.error('passphraseInput element reference is null');
|
||||
// return;
|
||||
// }
|
||||
// passphrase = passphraseInput.value
|
||||
// if (passphrase == '' || passphrase == null) {
|
||||
// // alert('Please input passphrase')
|
||||
// // alertify.error('Please enter a passphrase');
|
||||
// log.error('passphrase is empty or null');
|
||||
// return;
|
||||
// }
|
||||
current[0].className = current[0].className.replace(" active", "");
|
||||
|
||||
}
|
||||
@ -92,13 +92,13 @@ export class UserView implements Observer<ActiveUserViewModel> {
|
||||
log.error('passphraseInput element reference is null');
|
||||
return;
|
||||
}
|
||||
passphrase = elem.value;
|
||||
if (passphrase == '' || passphrase == null) {
|
||||
// // alert('Please input passphrase')
|
||||
// // alertify.error('Please enter a passphrase');
|
||||
log.error('passphrase is empty or null');
|
||||
return;
|
||||
}
|
||||
// passphrase = elem.value;
|
||||
// if (passphrase == '' || passphrase == null) {
|
||||
// // // alert('Please input passphrase')
|
||||
// // // alertify.error('Please enter a passphrase');
|
||||
// log.error('passphrase is empty or null');
|
||||
// return;
|
||||
// }
|
||||
// @ts-ignore: Object is possibly 'null'.
|
||||
document.getElementById('no-user-selected').hidden = true;
|
||||
// @ts-ignore: Object is possibly 'null'.
|
||||
@ -119,7 +119,7 @@ export class UserView implements Observer<ActiveUserViewModel> {
|
||||
}
|
||||
this._notificationService.passphrasePrompt(vm, this._model.activeUsersList,
|
||||
this._chatModel.getMessages.bind(this._chatModel),
|
||||
this._promptHandler.bind(this));
|
||||
this._promptHandler.bind(this), this._chatModel.isPassphraseValid.bind(this._chatModel));
|
||||
// this._chatModel.getMessages(userName, vm.passphrase, null, "new");
|
||||
el.className += " active";
|
||||
}
|
||||
|
@ -290,6 +290,10 @@ html {
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
|
||||
.modal-dialog {
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
@media(max-width: 576px) {
|
||||
.contacts_card {
|
||||
margin-bottom: 15px !important;
|
||||
|
@ -152,7 +152,7 @@
|
||||
<div class="input-group-append">
|
||||
<span class="input-group-text attach_btn"><i class="fas fa-paperclip"></i></span>
|
||||
</div>
|
||||
<input class="form-control type_msg" size="10" type="password" id="passphrase" placeholder="Passphrase " required>
|
||||
<!-- <input class="form-control type_msg" size="10" type="password" id="passphrase" placeholder="Passphrase " required> -->
|
||||
<textarea name="" id="chatInput" class="form-control type_msg" placeholder="Type your message..." required></textarea>
|
||||
<div class="input-group-append">
|
||||
<button class="input-group-text send_btn"><i class="fas fa-location-arrow"></i></button>
|
||||
|
Loading…
Reference in New Issue
Block a user