Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail issue #151

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ exports.token = process.env.SECRET
exports.slack = process.env.SLACK_TOKEN
exports.webhookURL = process.env.INVITE_CHANNEL_WEBHOOK
exports.glitch = process.env.GLITCH_SECRET
exports.selfEmail = 'IIITV Coding Club <[email protected]>'
exports.selfEmail = '[email protected]'
exports.githubApi = 'https://api.github.com'
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"express": "^4.16.3",
"gh-account-exists": "^0.1.0",
"jquery": "^3.5.0",
"nodemailer": "^6.9.1",
"path": "^0.12.7",
"uikit": "^3.1.4",
"url-crypt": "*"
Expand Down
188 changes: 94 additions & 94 deletions public/client.js
Original file line number Diff line number Diff line change
@@ -1,175 +1,175 @@
$ ('#email').keyup (function () {
const email = $ ('#email');
if (email.val ()) {
if (!validateEmail (email.val ())) {
email.css ({
$('#email').keyup(function () {
const email = $('#email')
if (email.val()) {
if (!validateEmail(email.val())) {
email.css({
color: '#f0506e',
'border-color': '#f0506e',
});
'border-color': '#f0506e'
})
} else {
email.css ({
email.css({
color: '#32d296',
'border-color': '#32d296',
});
'border-color': '#32d296'
})
}
}
});
})

var validateEmail = function (emailValue) {
var regex = /^\w+([-]?\w+)*@\w+([-]?\w+)*(\.\w{2,3})+$/;
return regex.test (emailValue);
};
var regex = /^\w+([-]?\w+)*@\w+([-]?\w+)*(\.\w{2,3})+$/
return regex.test(emailValue)
}

$ ('#username').keyup (function () {
const username = $ ('#username');
if (username.val ()) {
const profile = `https://api.aashutosh.dev/gh/${username.val ()}`;
fetch (profile)
.then (response => response.json ())
.then (data => {
$('#username').keyup(function () {
const username = $('#username')
if (username.val()) {
const profile = `https://api.aashutosh.dev/gh/${username.val()}`
fetch(profile)
.then(response => response.json())
.then(data => {
if (data.error) {
username.css ({
username.css({
color: '#f0506e',
'border-color': '#f0506e',
});
'border-color': '#f0506e'
})
} else {
username.css ({
username.css({
color: '#32d296',
'border-color': '#32d296',
});
'border-color': '#32d296'
})
}
})
.catch (e => {
console.log (e);
});
.catch(e => {
console.log(e)
})
} else {
username.css ({
username.css({
color: '#32d296',
'border-color': '#32d296',
});
'border-color': '#32d296'
})
}
});
})

window.getStatus = function (url) {
const request = new XMLHttpRequest ();
const request = new XMLHttpRequest()
request.onreadystatechange = function () {
if (request.readyState === 2) {
return request.status;
return request.status
// this contains the status code
}
};
request.open ('GET', url, true);
request.send ();
};
}
request.open('GET', url, true)
request.send()
}

$.put = function (url, data, callback, type) {
if ($.isFunction (data)) {
type = type || callback;
callback = data;
data = {};
if ($.isFunction(data)) {
type = type || callback
callback = data
data = {}
}

return $.ajax ({
return $.ajax({
url: url,
type: 'PUT',
success: callback,
data: data,
contentType: type,
});
};
contentType: type
})
}

$ (function () {
$ ('form').submit (function (event) {
event.preventDefault ();
$(function () {
$('form').submit(function (event) {
event.preventDefault()

const username = $ ('#username').val ();
const email = $ ('#email').val ();
fetch (`https://api.github.com/users/${username}`)
.then (res => res.json ())
.then (out => {
const username = $('#username').val()
const email = $('#email').val()
fetch(`https://api.github.com/users/${username}`)
.then(res => res.json())
.then(out => {
if (out.message && out.message === 'Not Found') {
// eslint-disable-next-line
UIkit.notification ({
message: "<span class='uk-text-small' uk-icon='icon: warning'>Username not found.</span>",
message: '<span class=\'uk-text-small\' uk-icon=\'icon: warning\'>Username not found.</span>',
status: 'danger',
pos: 'top-center',
timeout: 1000,
});
timeout: 1000
})
} else {
fetch (`/sendmail/${username}/${email}`)
.then (res => {
fetch(`/sendmail/${username}/${email}`)
.then(res => {
if (res.status === 200) {
// eslint-disable-next-line
UIkit.notification ({
message: "<span class='uk-text-small' uk-icon='icon: thumbs-up'>A verification E-mail has been sent.</span>",
message: '<span class=\'uk-text-small\' uk-icon=\'icon: thumbs-up\'>A verification E-mail has been sent.</span>',
status: 'success',
pos: 'top-center',
timeout: 2000,
});
timeout: 2000
})
}
})
.catch (e => {
console.error (e);
.catch(e => {
console.error(e)
// eslint-disable-next-line
UIkit.notification ({
message: "<span class='uk-text-small' uk-icon='icon: warning'>An error occured. Please try again later.</span>",
message: '<span class=\'uk-text-small\' uk-icon=\'icon: warning\'>An error occured. Please try again later.</span>',
status: 'danger',
pos: 'top-center',
timeout: 1000,
});
});
timeout: 1000
})
})
}
})
.catch (err => {
console.error (err);
.catch(err => {
console.error(err)
// eslint-disable-next-line
UIkit.notification ({
message: "<span class='uk-text-small' uk-icon='icon: warning'>An error occured. Please try again later.</span>",
message: '<span class=\'uk-text-small\' uk-icon=\'icon: warning\'>An error occured. Please try again later.</span>',
status: 'danger',
pos: 'top-center',
timeout: 1000,
});
});
});
});
timeout: 1000
})
})
})
})

window.showToast = async function () {
const username = $ ('#username').val ();
const email = $ ('#email').val ();
const username = $('#username').val()
const email = $('#email').val()
if (username === '' && email === '') {
// eslint-disable-next-line
UIkit.notification ({
message: "<span uk-icon='icon: warning'></span> <span class='uk-text-small'>Email and Username are required fields</span>",
message: '<span uk-icon=\'icon: warning\'></span> <span class=\'uk-text-small\'>Email and Username are required fields</span>',
status: 'danger',
pos: 'top-center',
timeout: 2000,
});
timeout: 2000
})
} else if (email === '' || username === '') {
var empty = 'Email';
var empty = 'Email'
if (username.length === 0) {
empty = 'Username';
empty = 'Username'
}
// eslint-disable-next-line
UIkit.notification ({
message: `<span uk-icon='icon: warning'></span> <span class='uk-text-small'>${empty} is required field.</span>`,
status: 'danger',
pos: 'top-center',
timeout: 1500,
});
timeout: 1500
})
} else {
// eslint-disable-next-line
fetch (`https://api.github.com/users/${username}`)
.then (res => res.json ())
.then (out => {
.then(res => res.json())
.then(out => {
if (!(out.message && out.message === 'Not Found')) {
// eslint-disable-next-line
UIkit.notification ({
message: "<span uk-icon='icon: mail; ratio: 1.5'></span> <span class='uk-text-small'>Thank You, Check your inbox for the invite.</span>",
message: '<span uk-icon=\'icon: mail; ratio: 1.5\'></span> <span class=\'uk-text-small\'>Thank You, Check your inbox for the invite.</span>',
status: 'success',
pos: 'bottom-center',
timeout: 2000,
});
timeout: 2000
})
}
});
})
}
};
}
35 changes: 19 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ const createMail = require('./createmail')
const urlcrypt = require('url-crypt')(
'~{ry*I)44==yU/]9<7DPk!Hj"R#:-/Z7(hTBnlRS=4CXF'
)
const sgMail = require('@sendgrid/mail')
const nodemailer = require('nodemailer')
const {
glitch,
slack,
webhookURL,
token,
selfEmail,
githubApi
} = require('./constants')

const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: selfEmail,
pass: process.env.gmail_key
}
})

app.use(bodyParser.json())
sgMail.setApiKey(process.env.SG_TOKEN)

// Auto-update Glitch with GitHub
app.post('/git', (req, res) => {
Expand Down Expand Up @@ -65,7 +70,7 @@ app.get('/', (_req, res) => {

// Send the mail to the given email
app.get('/sendmail/:username/:id', (req) => {
const { username, id } = req.params;
const { username, id } = req.params

const base64 = urlcrypt.cryptObj({
email: id,
Expand All @@ -74,23 +79,21 @@ app.get('/sendmail/:username/:id', (req) => {

const verificationurl = `https://${req.get('host')}/verify/${base64}`

const msg = {
const mailOptions = {
from: selfEmail,
bcc: selfEmail,
to: id,
subject: 'Invitation to join IIITV OSS Team',
html: createMail.createMail(username, verificationurl)
}

sgMail
.send(msg)
.then(() => {
console.log('Email sent')
})
.catch((error) => {
console.error("Error", error);
})
});
transporter.sendMail(mailOptions)
.then((info) => {
console.log('Email Sent: ' + info.response)
})
.catch((err) => {
console.error(err)
})
})

// Verify the email id through the link, and add as member
app.get('/verify/:base64', (request, response) => {
Expand Down