Skip to content
Snippets Groups Projects
Commit 7a8fb831 authored by Sang Won Lee's avatar Sang Won Lee
Browse files

CAS login and HTTPS redirection completed

parent 8509c59c
No related branches found
No related tags found
No related merge requests found
Showing
with 104 additions and 1580 deletions
require('dotenv').config();
const fs = require('fs');
const https = require('https');
const express = require('express');
const session = require('express-session');
const CASAuthentication = require('cas-authentication');
const axios = require('axios');
const cors = require('cors');
const mongoose = require('mongoose');
const xml2js = require('xml2js');
const app = express();
app.use(cors());
const corsOptions = {
origin: 'https://crescendo.cs.vt.edu:3000',
optionsSuccessStatus: 200,
credentials: true
};
app.use(cors(corsOptions));
app.use(express.json());
app.use(session({
secret: 'your_secret_key',
resave: false,
saveUninitialized: true
}));
const cas = new CASAuthentication({
cas_url: 'https://login.vt.edu/profile/cas',
service_url: 'http://cs.vt.edu:8080', // 서비스 URL
cas_version: '2.0',
renew: false,
is_dev_mode: false
});
secret: 'your_secret_key',
resave: false,
saveUninitialized: true
}));
app.use(cas.bounce);
const CAS_SERVICE_URL = 'https://crescendo.cs.vt.edu/Dashboard';
const CAS_VALIDATE_URL = 'https://login.vt.edu/profile/cas/serviceValidate';
const PORT = process.env.PORT || 8080;
const HTTP_PORT = 80;
const httpsOptions = {
key: fs.readFileSync('/home/sangwonlee/cert/key.pem'),
cert: fs.readFileSync('/home/sangwonlee/cert/crescendo.cs.vt.edu.crt')
};
const redirectToHTTPS = (req, res, next) => {
if (!req.secure) {
return res.redirect('https://' + req.headers.host + req.url);
}
next();
};
app.use(redirectToHTTPS);
https.createServer(httpsOptions, app).listen(PORT, () => {
console.log(`Server started on https://localhost:${PORT}`);
});
const schemaData = mongoose.Schema({
title: String,
message: String,
title: String,
message: String,
}, {
timestamps: true
timestamps: true
});
const feedbackModel = mongoose.model("feedbacks", schemaData);
console.log('MongoDB URI:', process.env.MONGO_URI);
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("Connected to db")
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on port ${PORT}`);
});
})
.catch((err) => console.log(err))
.then(() => {
console.log("Connected to db");
})
.catch((err) => console.log(err));
app.get('/FeedbackForm', async (req, res) => {
const { ticket } = req.query;
if (!ticket) {
return res.redirect(CAS_SERVICE_URL);
}
app.post("/saveFeedback", async (req, res) => {
try {
console.log(req.body);
try {
const response = await axios.get(CAS_VALIDATE_URL, {
params: {
ticket,
service: CAS_SERVICE_URL
}
});
const parser = new xml2js.Parser();
parser.parseString(response.data, (err, result) => {
if (err) {
console.error('XML parsing error:', err);
return res.status(500).send('CAS ticket validation failed');
}
if (!req.body.title || !req.body.message) {
return res.status(400).json({ success: false, message: "Title and message are required fields" });
}
const user = result['cas:serviceResponse']['cas:authenticationSuccess'][0];
req.session.user = {
username: user['cas:user'][0],
attributes: user['cas:attributes'][0]
};
res.redirect('/Dashboard');
});
} catch (error) {
console.error('CAS 티켓 검증 실패:', error);
res.status(500).send('CAS 티켓 검증 실패');
}
});
const data = new feedbackModel(req.body);
await data.save();
app.get('/Dashboard', (req, res) => {
if (!req.session.user) {
return res.redirect(CAS_SERVICE_URL);
}
res.status(200).json({ success: true, message: "Data save successful" });
} catch (error) {
console.error(error);
res.status(500).json({ success: false, message: "Internal server error" });
res.send('Dashboard');
});
app.post("/saveFeedback", async (req, res) => {
try {
console.log('Received request:', req.body);
if (!req.body.title || !req.body.message) {
console.error('Validation error: Missing title or message');
return res.status(400).json({ success: false, message: "Title and message are required fields" });
}
const data = new feedbackModel(req.body);
await data.save();
res.status(200).json({ success: true, message: "Feedback sent successfully" });
} catch (error) {
console.error('Error processing request:', error);
res.status(500).json({ success: false, message: "Internal server error" });
}
});
app.get("/getFeedback", async (req, res) => {
try {
const data = await feedbackModel.find({}, { title: 1, message: 1 });
res.status(200).json(data);
} catch (error) {
console.error(error);
res.status(500).json({ success: false, message: "Internal server error" });
}
});
\ No newline at end of file
try {
const data = await feedbackModel.find({}, { title: 1, message: 1 });
res.status(200).json(data);
} catch (error) {
console.error(error);
res.status(500).json({ success: false, message: "Internal server error" });
}
});
../loose-envify/cli.js
\ No newline at end of file
../mime/cli.js
\ No newline at end of file
../nodemon/bin/nodemon.js
\ No newline at end of file
../touch/bin/nodetouch.js
\ No newline at end of file
../semver/bin/semver.js
\ No newline at end of file
This diff is collapsed.
Copyright (c) 2014 Dmitry Tsvettsikh
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
import mod from "./node.js";
export default mod;
export const saslprep = mod.saslprep;
declare const saslprep: (args_0: string, args_1?: {
allowUnassigned?: boolean | undefined;
} | undefined) => string;
export = saslprep;
//# sourceMappingURL=browser.d.ts.map
\ No newline at end of file
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,QAAQ;;wBAAmC,CAAC;AAIlD,SAAS,QAAQ,CAAC"}
\ No newline at end of file
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const index_1 = __importDefault(require("./index"));
const memory_code_points_1 = require("./memory-code-points");
const code_points_data_browser_1 = __importDefault(require("./code-points-data-browser"));
const codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_browser_1.default);
const saslprep = index_1.default.bind(null, codePoints);
Object.assign(saslprep, { saslprep, default: saslprep });
module.exports = saslprep;
//# sourceMappingURL=browser.js.map
\ No newline at end of file
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";;;;AAAA,oDAAgC;AAChC,6DAA8D;AAC9D,0FAA8C;AAE9C,MAAM,UAAU,GAAG,IAAA,2CAAsB,EAAC,kCAAI,CAAC,CAAC;AAEhD,MAAM,QAAQ,GAAG,eAAS,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEzD,iBAAS,QAAQ,CAAC"}
\ No newline at end of file
/// <reference types="node" />
declare const data: Buffer;
export default data;
//# sourceMappingURL=code-points-data-browser.d.ts.map
\ No newline at end of file
{"version":3,"file":"code-points-data-browser.d.ts","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":";AAAA,QAAA,MAAM,IAAI,QAGT,CAAC;AACF,eAAe,IAAI,CAAC"}
\ No newline at end of file
{"version":3,"file":"code-points-data-browser.js","sourceRoot":"","sources":["../src/code-points-data-browser.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CACtB,8sliBAA8sliB,EAC9sliB,QAAQ,CACT,CAAC;AACF,kBAAe,IAAI,CAAC"}
\ No newline at end of file
/// <reference types="node" />
declare const _default: Buffer;
export default _default;
//# sourceMappingURL=code-points-data.d.ts.map
\ No newline at end of file
{"version":3,"file":"code-points-data.d.ts","sourceRoot":"","sources":["../src/code-points-data.ts"],"names":[],"mappings":";;AAEA,wBAKE"}
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const zlib_1 = require("zlib");
exports.default = (0, zlib_1.gunzipSync)(Buffer.from('H4sIAAAAAAACA+3dTYgcaRkA4LemO9Mhxm0FITnE9Cwr4jHgwgZ22B6YywqCJ0HQg5CL4sGTuOjCtGSF4CkHEW856MlTQHD3EJnWkU0Owh5VxE3LHlYQdNxd2U6mU59UV/d09fw4M2EySSXPAzNdP1/9fX/99bzVNZEN4jisRDulVFnQmLxm1aXF9Id/2/xMxNJ4XZlg576yuYlGt9gupV6xoFf8jhu9YvulVrFlp5XSx+lfvYhORGPXvqIRWSxERKtIm8bKFd10WNfKDS5Fo9jJWrq2+M2IlW+8uHgl/+BsROfPF4v5L7148Ur68Sha6dqZpYiVVy8tvLCWXo80Sf/lS89dGX2wHGvpzoXVn75/YWH5wmqe8uika82ViJXTy83Ve2k5Urozm38wm4/ls6t5uT6yfsTSJ7J3T0VKt8c5ExEXI8aFkH729c3eT+7EC6ca8cVULZUiYacX0R5PNWNxlh9L1y90q5kyzrpyy+9WcvOV6URntqw7La9sNVstXyczWVaWYbaaTYqzOHpr7pyiNT3/YzKuT63Z/FqKZlFTiuXtFM2vVOtIq7jiyKJbWZaOWD0euz0yoV2Z7kY0xq2x0YhfzVpmM5px9nTEH7JZ0ot5u39p0ma75Z472/s/H+2yr2inYyuq7fMvJivH2rM72N/Z3lyL31F2b1ya1P0zn816k2KP6JU9UzseucdQH5YqVeH/lFajSN2udg+TLJ9rksNxlvV2lki19rXKI43TPLejFu4ov7k3nMbhyhfY3Xb37f8BAGCf0eMTOH5szf154KmnNgKcnLb+Fzi2AfXktbN7fJelwTAiO/W5uQ2KINXRYu+znqo/WTAdLadURHmy3qciazd3bra4T3w16/f7t7Ms9U5gfJu10955sx1r3vmhBAAAAAAAgId20J1iZbDowNvIjuH427Gr5l/eiC+8OplZON8sVjx/qr9y+Pj+YRItT+NqAM+kkZs3AAAAAID6yfx1FwCAI97/dCh1/ub6SA0AAAAAAAAAgNoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAA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KlfvS1msllt7JEJm9XOJqXR+Fkfo1H66uy5H1v3Xx5+uJmGLw9jro2u7Loj4PnuR6+f+e3d261+eazNhzrL7X83MohoHpS4PddV8ki1it61//pw1g7z6p1U/26Nm2llST57B5rUvuG0XqSU/rPd7jYrqWcbd+beJQ77BgPMDwn37/8BAGCf0eMTOH4cPlufv9VGgJOzqf8Fjm1APXkd7B7f5dF57GPMaWy/MTvjvNvtXj6h8W2+GXvnzXaseeeHEgAAAAAAAB7aQXeKlcGiadBoEOeLb2dtpGOL2MyOtf391a3P/zD96c3JzIP3t4oV797vrh8+vn+YRL5bBuj/AQAAAABqJvfHXQAAHkX82zfXAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACeAgkAAAAAAAAAqLuRLAAAAAAAAACA2hv9D1iu/VAYaAYA', 'base64'));
//# sourceMappingURL=code-points-data.js.map
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment