Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Finish the app yay
Browse files Browse the repository at this point in the history
  • Loading branch information
sarunint committed Oct 13, 2017
1 parent bf9c791 commit 4378068
Show file tree
Hide file tree
Showing 153 changed files with 5,466 additions and 427 deletions.
11 changes: 8 additions & 3 deletions .angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
"favicons"
],
"index": "index.html",
"main": "main.ts",
Expand All @@ -19,7 +19,8 @@
"testTsconfig": "tsconfig.spec.json",
"prefix": "cusc",
"styles": [
"styles.css"
"styles.css",
"styles.scss"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
Expand Down Expand Up @@ -52,6 +53,10 @@
},
"defaults": {
"styleExt": "css",
"component": {}
"component": {
}
},
"warnings": {
"typescriptMismatch": false
}
}
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "cu-singing-contest"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# dependencies
/node_modules
/functions/node_modules

# IDEs and editors
/.idea
Expand Down
19 changes: 19 additions & 0 deletions firebase.json
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"
}
]
}
}
58 changes: 58 additions & 0 deletions functions/index.js
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);
}
}));
});
50 changes: 50 additions & 0 deletions functions/index.ts
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);
}
});
});
Loading

0 comments on commit 4378068

Please sign in to comment.