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