1
0
Fork 0

Use securesign cli hash

refactor/models
Bsian 2019-11-19 14:00:50 +00:00
parent 405d9345dd
commit a7415ce381
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
2 changed files with 16 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import nodemailer from 'nodemailer';
import { Message, PrivateChannel, Member, User } from 'eris';
import uuid from 'uuid/v4';
import moment from 'moment';
import fs from 'fs';
import { Client } from '..';
import { Command, RichEmbed } from '.';
import { ModerationInterface, AccountInterface } from '../models';
@ -195,9 +196,13 @@ export default class Util {
/**
* @param type `0` - Create
*
* `1` - Warn
*
* `2` - Lock
*
* `3` - Unlock
*
* `4` - Delete
*/
public async createModerationLog(user: string, moderator: Member|User, type: number, reason?: string, duration?: number): Promise<ModerationInterface> {
@ -251,4 +256,12 @@ export default class Util {
return Promise.resolve(log);
}
public getAcctHash(username: string) {
try {
return fs.readFileSync(`/home/${username}/.securesign/auth`).toString();
} catch (error) {
return null;
}
}
}

View File

@ -7,8 +7,9 @@ export default function checkSS(client: Client) {
try {
const accounts = await client.db.Account.find();
const hashes = accounts.filter((h) => h.hash);
for (const { hash, userID } of hashes) {
for (const { userID, username } of hashes) {
try {
const hash = client.util.getAcctHash(username);
await axios({
method: 'get',
url: 'https://api.securesign.org/account/details',
@ -17,7 +18,7 @@ export default function checkSS(client: Client) {
} catch (error) {
const { status } = error.response;
if (status === 400 || status === 401 || status === 403 || status === 404) {
await client.db.Account.updateOne({ hash }, { $set: { hash: null } });
await client.db.Account.updateOne({ userID }, { $set: { hash: false } });
client.getDMChannel(userID).then((channel) => channel.createMessage('Your SecureSign password has been reset - please reinitialize your SecureSign account')).catch();
}
}