From cf465b01c8f440cecf256c976b5fa14ea0914836 Mon Sep 17 00:00:00 2001 From: Matthew R Date: Sat, 28 Mar 2020 04:57:08 -0400 Subject: [PATCH] add account utilities class and rework of util class --- src/class/AccountUtil.ts | 73 ++++++++++++++++++++++++++++++++++++++++ src/class/Util.ts | 8 +++-- src/class/index.ts | 1 + 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 src/class/AccountUtil.ts diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts new file mode 100644 index 0000000..cac764a --- /dev/null +++ b/src/class/AccountUtil.ts @@ -0,0 +1,73 @@ +import { AccountInterface } from '../models'; +import { Client } from '..'; + +export default class AccountUtil { + public client: Client; + + constructor(client: Client) { + this.client = client; + } + + /** + * This function creates a new user account. + * @param data Data/information on the new user account to create. + * @param data.userID The Discord ID for the user. + * @param data.username The username for the new user, this will also be their username on the machine. + * @param data.emailAddress The user's email address. + * @param moderator The Discord user ID for the Staff member that created the account. + */ + public async createAccount(data: { userID: string, username: string, emailAddress: string }, moderator: string): Promise<{ account: AccountInterface, tempPass: string }> { + const moderatorMember = this.client.guilds.get('446067825673633794').members.get(moderator); + const tempPass = this.client.util.randomPassword(); + let passHash = await this.client.util.createHash(tempPass); passHash = passHash.replace(/[$]/g, '\\$').replace('\n', ''); + const acctName = this.client.users.get(data.userID).username.replace(/[!@#$%^&*(),.?":{}|<>]/g, '-').replace(/\s/g, '-'); + const etcPasswd = `${acctName},${data.userID},,`; + + const accountInterface = await this.client.util.createAccount(passHash, etcPasswd, data.username, data.userID, data.emailAddress, moderator); + await this.client.util.createModerationLog(data.userID, moderatorMember, 0); + + this.client.util.transport.sendMail({ + to: data.emailAddress, + from: 'Library of Code sp-us | Cloud Services ', + subject: 'Your account has been created', + html: ` + + +

Library of Code | Cloud Services

+

Your Cloud Account has been created, welcome! Please see below for some details regarding your account and our services

+

Username: ${data.username}

+

SSH Login:

ssh ${data.username}@cloud.libraryofcode.org
+

Useful information

+

How to log in:

+
    +
  1. Open your desired terminal application - we recommend using Bash, but you can use your computer's default
  2. +
  3. Type in your SSH Login as above
  4. +
  5. When prompted, enter your password Please note that inputs will be blank, so be careful not to type in your password incorrectly
  6. +
+

If you fail to authenticate yourself too many times, you will be IP banned and will fail to connect. If this is the case, feel free to DM Ramirez with your public IPv4 address. + +

Channels and Links

+ +

Want to support us?

+

You can support us on Patreon! Head to our Patreon page and feel free to donate as much or as little as you want!
Donating $5 or more will grant you Tier 3, which means we will manage your account at your request, longer certificates, increased Tier limits as well as some roles in the server!

+ Library of Code sp-us | Support Team + + `, + }); + + const dmChannel = await this.client.getDMChannel(data.userID).catch(); + dmChannel.createMessage('<:loc:607695848612167700> **Thank you for creating an account with us!** <:loc:607695848612167700>\n' + + `Please log into your account by running \`ssh ${data.username}@cloud.libraryofcode.org\` in your terminal, then use the password \`${tempPass}\` to log in.\n` + + `You will be asked to change your password, \`(current) UNIX password\` is \`${tempPass}\`, then create a password that is at least 12 characters long, with at least one number, special character, and an uppercase letter\n` + + 'Bear in mind that when you enter your password, it will be blank, so be careful not to type in your password incorrectly.\n' + + 'You may now return to Modmail, and continue setting up your account from there.\n\n' + + 'An email containing some useful information has also been sent').catch(); + return { account: accountInterface, tempPass }; + } +} diff --git a/src/class/Util.ts b/src/class/Util.ts index 3dc58f6..19ed57f 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -6,14 +6,15 @@ import { Message, PrivateChannel, GroupChannel, Member, User } from 'eris'; import uuid from 'uuid/v4'; import moment from 'moment'; import fs from 'fs'; -import os from 'os'; import { Client } from '..'; -import { Command, RichEmbed } from '.'; -import { ModerationInterface, AccountInterface } from '../models'; +import { AccountUtil, Command, RichEmbed } from '.'; +import { ModerationInterface, AccountInterface, Account } from '../models'; export default class Util { public client: Client; + public accounts: AccountUtil; + public transport: nodemailer.Transporter; constructor(client: Client) { @@ -22,6 +23,7 @@ export default class Util { host: 'staff.libraryofcode.org', auth: { user: 'support', pass: this.client.config.emailPass }, }); + this.accounts = new AccountUtil(client); } /** diff --git a/src/class/index.ts b/src/class/index.ts index a85412e..a2744c7 100644 --- a/src/class/index.ts +++ b/src/class/index.ts @@ -1,3 +1,4 @@ +export { default as AccountUtil } from './AccountUtil'; export { default as Command } from './Command'; export { default as RichEmbed } from './RichEmbed'; export { default as Util } from './Util';