This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
153 changed files
with
5,466 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "cu-singing-contest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
# dependencies | ||
/node_modules | ||
/functions/node_modules | ||
|
||
# IDEs and editors | ||
/.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"database": { | ||
"rules": "database.rules.json" | ||
}, | ||
"hosting": { | ||
"public": "dist", | ||
"ignore": [ | ||
"firebase.json", | ||
"**/.*", | ||
"**/node_modules/**" | ||
], | ||
"rewrites": [ | ||
{ | ||
"source": "**", | ||
"destination": "/index.html" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const admin = require("firebase-admin"); | ||
const functions = require("firebase-functions"); | ||
const _cors = require("cors"); | ||
const axios_1 = require("axios"); | ||
const https = require("https"); | ||
const fs_1 = require("fs"); | ||
const cors = _cors({ origin: true }); | ||
const config = { | ||
credential: admin.credential.cert(JSON.parse(fs_1.readFileSync('cunet-cert.json').toString())), | ||
databaseURL: '' | ||
}; | ||
admin.initializeApp(config); | ||
exports.authenticate = functions.https.onRequest((req, resp) => { | ||
cors(req, resp, () => __awaiter(this, void 0, void 0, function* () { | ||
if (req.method.toLowerCase() !== 'post') { | ||
resp.status(405).end(); | ||
} | ||
else { | ||
const data = req.body; | ||
const username = data.username; | ||
const password = data.password; | ||
const result = axios_1.default.get('https://www.it.chula.ac.th/downloads', { | ||
auth: { | ||
username, password | ||
}, | ||
httpsAgent: new https.Agent({ | ||
rejectUnauthorized: false | ||
}) | ||
}).then((response) => { }).catch((error) => { | ||
switch (error.response.status) { | ||
case 403: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}); | ||
const out = {}; | ||
if (yield result) { | ||
out.success = true; | ||
out.token = yield admin.auth().createCustomToken(`cunet-${username}`); | ||
} | ||
else { | ||
out.success = false; | ||
} | ||
resp.status(200).send(out); | ||
} | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as admin from 'firebase-admin'; | ||
import * as functions from 'firebase-functions'; | ||
import * as _cors from 'cors'; | ||
import axios from 'axios'; | ||
import * as https from 'https'; | ||
import { readFileSync } from 'fs'; | ||
|
||
const cors = _cors({ origin: true }); | ||
|
||
const config = { | ||
credential: admin.credential.cert(JSON.parse(readFileSync('cunet-cert.json').toString())), | ||
databaseURL: '' | ||
}; | ||
|
||
admin.initializeApp(config); | ||
|
||
export const authenticate = functions.https.onRequest((req, resp) => { | ||
cors(req, resp, async () => { | ||
if (req.method.toLowerCase() !== 'post') { | ||
resp.status(405).end(); | ||
} else { | ||
const data = req.body; | ||
const username = data.username; | ||
const password = data.password; | ||
const result = axios.get('https://www.it.chula.ac.th/downloads', { | ||
auth: { | ||
username, password | ||
}, | ||
httpsAgent: new https.Agent({ | ||
rejectUnauthorized: false | ||
}) | ||
}).then((response) => { }).catch((error) => { | ||
switch (error.response.status) { | ||
case 403: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}); | ||
const out: any = {}; | ||
if (await result) { | ||
out.success = true; | ||
out.token = await admin.auth().createCustomToken(`cunet-${username}`); | ||
} else { | ||
out.success = false; | ||
} | ||
resp.status(200).send(out); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.