Rohan Sircar
4 years ago
6 changed files with 129 additions and 48 deletions
-
2.gitignore
-
4src/main/frontend/admin/main.ts
-
67src/main/frontend/admin/pages/user/ChangePassphrase.ts
-
2src/main/frontend/chat/model/ChatModel.ts
-
82src/main/frontend/common/ajax/messages.ts
-
20src/main/frontend/common/ajax/passphrase.ts
@ -1,10 +1,12 @@ |
|||
import { changePassphrase } from "./pages/user/ChangePassphrase"; |
|||
import { EncryptionServiceFactory } from "../common/service/EncryptionServiceFactory"; |
|||
import log from "loglevel"; |
|||
import { AlertifyNotificationService } from "../common/service/AlertifyNotificationService"; |
|||
|
|||
log.setLevel("TRACE"); |
|||
const es = EncryptionServiceFactory.getEncryptionService(); |
|||
const ns = new AlertifyNotificationService(); |
|||
$("#changePassphraseForm").on("submit", (event) => { |
|||
event.preventDefault(); |
|||
changePassphrase(es); |
|||
changePassphrase(es, ns); |
|||
}); |
@ -0,0 +1,82 @@ |
|||
import { Sprintf } from "../global/Sprintf"; |
|||
import { Routes } from "../routes/Routes"; |
|||
import { ReencryptionDTO } from "../dto/ReencryptionDTO"; |
|||
import { ChatMessageDTO } from "../dto/ChatMessageDTO"; |
|||
import { JsonAPI } from "../../chat/singleton/JsonAPI"; |
|||
import * as log from "loglevel"; |
|||
|
|||
export async function getAllMessages(user: string, authToken: string) { |
|||
let headers = new Headers(); |
|||
// headers.append('Accept','application/json')
|
|||
// headers.append('Content-Type', 'application/json');
|
|||
headers.append("X-AUTH-TOKEN", authToken); |
|||
let response = await fetch(`${Routes.Admin.getAllMessagesURL}${user}`, { |
|||
method: "GET", |
|||
headers: headers, |
|||
}); |
|||
return response.json() as Promise<ReencryptionDTO[]>; |
|||
} |
|||
|
|||
async function getAllRegularUsers(authToken: string) { |
|||
let headers = new Headers(); |
|||
// headers.append('Accept','application/json')
|
|||
// headers.append('Content-Type', 'application/json');
|
|||
headers.append("X-AUTH-TOKEN", authToken); |
|||
let response = await fetch(`${Routes.Admin.getAllRegularUsersURL}`, { |
|||
method: "GET", |
|||
headers: headers, |
|||
}); |
|||
let data = (await response.json()) as string[]; |
|||
return data; |
|||
} |
|||
|
|||
export async function sendReencryptedMessages( |
|||
rencryptionDTOs: ReencryptionDTO[], |
|||
authToken: string |
|||
) { |
|||
let headers = new Headers(); |
|||
// console.log("Token = " + btoa("hmm" + ":" + "hmm"))
|
|||
|
|||
// headers.append('Accept','application/json')
|
|||
headers.append("Content-Type", "application/json"); |
|||
headers.append("X-AUTH-TOKEN", authToken); |
|||
fetch(Routes.Admin.reencryptURL, { |
|||
method: "POST", |
|||
headers: headers, |
|||
body: JSON.stringify(rencryptionDTOs), |
|||
}).then((response) => console.log(response)); |
|||
} |
|||
|
|||
export async function getOneMessage( |
|||
toUser: string, |
|||
page: number |
|||
): Promise<ChatMessageDTO[]> { |
|||
const headers = new Headers(); |
|||
if (JsonAPI.authToken == null) { |
|||
log.error("authToken null"); |
|||
return []; |
|||
} |
|||
headers.append("X-AUTH-TOKEN", JsonAPI.authToken); |
|||
const url = Sprintf(JsonAPI.CHAT_MESSAGE_PAGE_GET, toUser, page, 1); |
|||
log.debug(url); |
|||
const response = await fetch(url, { |
|||
method: "GET", |
|||
headers: headers, |
|||
}); |
|||
log.debug(response.clone()); |
|||
// if (fetchErrorHandler(response.clone(), this._notificationService)) {
|
|||
// return null;
|
|||
// }
|
|||
const data: Promise<any> = await response.json(); |
|||
function func(data: any) { |
|||
const d1 = data.map((d: any) => { |
|||
if (d.messageTime == null) return null; |
|||
|
|||
d.messageTime = new Date(d.messageTime); |
|||
return d; |
|||
}); |
|||
return d1; |
|||
} |
|||
const data2 = func(data); |
|||
return data2; |
|||
} |
@ -0,0 +1,20 @@ |
|||
import { EncryptionService } from "../service/EncryptionService"; |
|||
import { ChatMessageDTO } from "../dto/ChatMessageDTO"; |
|||
import * as log from "loglevel"; |
|||
import { getOneMessage } from "./messages"; |
|||
|
|||
export async function isPassphraseValid( |
|||
passphrase: string, |
|||
userName: string, |
|||
es: EncryptionService |
|||
): Promise<boolean> { |
|||
const messages: ChatMessageDTO[] = await getOneMessage(userName, 0); |
|||
if (messages.length === 0) return true; |
|||
try { |
|||
es.decrypt(passphrase, messages[0].messageCipher); |
|||
} catch (error) { |
|||
log.debug("here"); |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue