Rohan Sircar
4 years ago
11 changed files with 330 additions and 57 deletions
-
2chatto/src/main/javascript/ts/src/dto/ChatMessageDTO.ts
-
8chatto/src/main/javascript/ts/src/main.ts
-
12chatto/src/main/javascript/ts/src/model/ChatModel.ts
-
7chatto/src/main/javascript/ts/src/model/ChatModelHelper.ts
-
6chatto/src/main/javascript/ts/src/service/EncryptionService.ts
-
11chatto/src/main/javascript/ts/src/service/SJCLEncryptionService.ts
-
4chatto/src/main/javascript/ts/src/singleton/JsonAPI.ts
-
118chatto/src/main/javascript/ts/src/view/ChatView.ts
-
33chatto/src/main/javascript/ts/src/view/FetchHandler.ts
-
182chatto/src/main/resources/static/js/bundle.js
-
4chatto/src/main/resources/templates/chat.html
@ -1,4 +1,6 @@ |
|||
import { MessageCipherDTO } from "../dto/MessageCipherDTO"; |
|||
|
|||
export interface EncryptionService { |
|||
encrypt(passphrase: string, plainText: string): Object, |
|||
decrypt(passphrase: string, cipher: Object): Object |
|||
encrypt(passphrase: string, plainText: string): any, |
|||
decrypt(passphrase: string, cipher: MessageCipherDTO): string |
|||
} |
@ -1,14 +1,15 @@ |
|||
import { EncryptionService } from "./EncryptionService"; |
|||
import * as sjcl from "sjcl"; |
|||
import { MessageCipherDTO } from "../dto/MessageCipherDTO"; |
|||
|
|||
export class SJCLEncryptionService implements EncryptionService { |
|||
private readonly params: any = { mode: "gcm", ts: 128, adata: "", iter: 10000} |
|||
public encrypt(passphrase: string, plainText: string): Object { |
|||
return sjcl.encrypt(passphrase, plainText, this.params); |
|||
private readonly params = { mode: "gcm", ts: 128, adata: "", iter: 10000} |
|||
public encrypt(passphrase: string, plainText: string): MessageCipherDTO { |
|||
// @ts-ignore
|
|||
return JSON.parse(sjcl.encrypt(passphrase, plainText, this.params) as string) as MessageCipherDTO; |
|||
} |
|||
|
|||
public decrypt(passphrase: string, cipher: Object): Object { |
|||
// return sjcl.decrypt(passphrase, cipher as sjcl.SjclCipherEncrypted, undefined, undefined);
|
|||
public decrypt(passphrase: string, cipher: MessageCipherDTO): string { |
|||
return sjcl.decrypt(passphrase, JSON.stringify(cipher), undefined, undefined); |
|||
} |
|||
} |
@ -1,8 +1,10 @@ |
|||
export namespace JsonAPI { |
|||
// @ts-ignore: Cannot find name 'hostAddress'.
|
|||
export let userName: string | null = localStorage.getItem('userName'); |
|||
export let principleName: string | null = localStorage.getItem('username'); |
|||
export let contactName: string | null; |
|||
export let authToken: string | null = localStorage.getItem('authToken'); |
|||
export const ACTIVE_USERS_GET = `/api/chat/get/active-users`; |
|||
export const CHAT_MESSAGES_GET = `/api/chat/get/messages`; |
|||
export const MESSAGE_POST = '/api/chat/post/message'; |
|||
|
|||
} |
@ -0,0 +1,33 @@ |
|||
import { sprintf } from "sprintf-js"; |
|||
|
|||
export function fetchHandler(response: any) { |
|||
if (response.ok) { |
|||
return response.json().then((json: any) => { |
|||
// the status was ok and there is a json body
|
|||
// return Promise.resolve({ json: json, response: response });
|
|||
// alertify.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
|||
}).catch((err: any) => { |
|||
// the status was ok but there is no json body
|
|||
// return Promise.resolve({ response: response });
|
|||
// alertify.success('Message sent succesfully' + sprintf(" (http code %d)", response.status));
|
|||
}); |
|||
|
|||
} else { |
|||
return response.json().catch((err: any) => { |
|||
// the status was not ok and there is no json body
|
|||
// throw new Error(response.statusText);
|
|||
// alertify.error('Some error occured. Please try again.');
|
|||
}).then((json: any) => { |
|||
// the status was not ok but there is a json body
|
|||
// throw new Error(json.error.message); // example error message returned by a REST
|
|||
// let delay = alertify.get('notifier', 'delay');
|
|||
// alertify.set('notifier', 'delay', 30);
|
|||
let errorMessage = ""; |
|||
json.errors.forEach(function(data: any) { |
|||
errorMessage += sprintf("Field Name: %s \n Rejected value: %s \n Reason: %s \n", data.field_name, data.rejected_value, data.error_message); |
|||
}); |
|||
// alertify.error(sprintf('There were errors in your message - %s', errorMessage));
|
|||
// alertify.set('notifier', 'delay', delay);
|
|||
}); |
|||
} |
|||
} |
182
chatto/src/main/resources/static/js/bundle.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue