Skip to content

Commit

Permalink
fix the commit
Browse files Browse the repository at this point in the history
fix the commit
  • Loading branch information
arch-linux committed Apr 17, 2024
1 parent ee427d6 commit 07a8a3a
Show file tree
Hide file tree
Showing 45 changed files with 5,674 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
API_KEYS.txt
apple_auth.p8
.DS_Store
12 changes: 12 additions & 0 deletions .vscode/sftp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "boundless aircraft maintenance",
"host": "10.6.0.1",
"protocol": "sftp",
"port": 22,
"username": "root",
"privateKeyPath": "C:\\Users\\archl\\Desktop\\se300key",
"remotePath": "/opt/SE300/oAuth-Staging/",
"uploadOnSave": true,
"useTempFile": false,
"openSsh": false
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Team BoundlessFlight

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.
Binary file added PyOCR/__pycache__/ocr_compgen.cpython-311.pyc
Binary file not shown.
Binary file added PyOCR/__pycache__/ocr_handwritten.cpython-311.pyc
Binary file not shown.
30 changes: 30 additions & 0 deletions PyOCR/flask_ocr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import Flask
from flask import request
from ocr_handwritten import *
from ocr_compgen import *
app = Flask(__name__)



@app.route('/ocr/handwritten/', methods = ['POST'])
def upload_handwritten():
if request.method == 'POST':
content = request.json
imgBlob = content['blob']
return (runOcr(imgBlob))
else:
return("This endpoint only accepts POST requests")

@app.route('/ocr/compgen/', methods = ['POST'])
def upload_compgen():
if request.method == 'POST':
content = request.json
imgBlob = content['blob']
return (run_ocr_compgen(imgBlob))
else:
return("This endpoint only accepts POST requests")




app.run()
14 changes: 14 additions & 0 deletions PyOCR/ocr_compgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytesseract
from pytesseract import Output
from PIL import Image
import cv2
from io import BytesIO
import base64

def run_ocr_compgen(blobData):
image = Image.open(BytesIO(base64.b64decode(blobData))).convert("RGB")
#image = Image.open(BytesIO(blobData)).convert("RGB")
text = pytesseract.image_to_string(image,lang='eng')
return(text)


28 changes: 28 additions & 0 deletions PyOCR/ocr_handwritten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
import requests
from IPython.display import display
from PIL import Image
from io import BytesIO
import base64

def runOcr(blobData):
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")

# load image from the IAM dataset
#url = "https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg"
#image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
#data = base64String
image = Image.open(BytesIO(base64.b64decode(blobData))).convert("RGB")
#image = Image.open(BytesIO(blobData)).convert("RGB")

pixel_values = processor(image, return_tensors="pt").pixel_values
generated_ids = model.generate(pixel_values, max_new_tokens = 255)

generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]

return(generated_text)




15 changes: 15 additions & 0 deletions PyOCR/requestOcrFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const fetch = require("fetch").fetchUrl;


async function getFromOcrEndpointCompgen(b64String) {

}

async function getFromOcrEndpointHandwritten(b64String) {

}

module.exports = {
getFromOcrEndpointCompgen: getFromOcrEndpointCompgen,
getFromOcrEndpointHandwritten: getFromOcrEndpointHandwritten
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SE300-backend


[![Node.js CI](https://github.com/vinnysaj/SE300-backend/actions/workflows/node.js.yml/badge.svg)](https://github.com/vinnysaj/SE300-backend/actions/workflows/node.js.yml)
103 changes: 103 additions & 0 deletions auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const passport = require('passport');
const Users = require(__dirname + "/models/users.model.js").Users;
const login_logs = require(__dirname + "/models/login_logs.model.js").login_logs;
const jwt = require('jsonwebtoken');
//var request = require('request').defaults({ encoding: null });

function generateAccessToken(username) {
return jwt.sign(username, process.env.TOKEN_HASH, { expiresIn: '7 days' });
}
const GoogleStrategy = require('passport-google-oauth2').Strategy;

const GOOGLE_CLIENT_ID = process.env.google_oauth_key;
const GOOGLE_CLIENT_SECRET = process.env.google_secret;




var MicrosoftStrategy = require('passport-microsoft').Strategy;
passport.use(new MicrosoftStrategy({
// Standard OAuth2 options
clientID: 'eb170940-8f95-41b4-9a92-f6d6fe433f4a',
clientSecret: '5d7d46fd-2808-4469-9788-83f8a270f21a',
callbackURL: "https://auth.boundlessflight.net/microsoft/callback",
scope: ['user.read'],

// Microsoft specific options

// [Optional] The tenant for the application. Defaults to 'common'.
// Used to construct the authorizationURL and tokenURL
tenant: 'common',

// [Optional] The authorization URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/authorize`
authorizationURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',

// [Optional] The token URL. Defaults to `https://login.microsoftonline.com/${tenant}/oauth2/v2.0/token`
tokenURL: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate({ userId: profile.id }, function (err, user) {
return done(err, user);
});
}
));



passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "https://auth.boundlessflight.net/google/callback",
passReqToCallback : true,
cookie: { secure: false },
proxy: true
},
async function(request, accessToken, refreshToken, profile, done) {
const selectUser = await Users.findOne({
where: {
email : profile.email,
user_id : profile.id,
}
})
if(selectUser == null){
//new user
Users.create({
user_id: profile.id,
email: profile.email,
name: profile.given_name,
is_new_user: true,
profile_image: profile.picture
})
userDidLogin(profile.id,request.headers['x-forwarded-for']);
profile.token = generateAccessToken( { username: profile} );
} else {
//current user
//lets log this
userDidLogin(profile.id,request.headers['x-forwarded-for']);
profile.token = generateAccessToken( { username: profile } );
console.log(profile.token);
}

return done(null, profile);
}
));

async function userDidLogin(userid,ip_address){
const done = await login_logs.create({
user_id: userid,
ip_address: ip_address,
})
}

passport.serializeUser(function(user,done){
done(null,user);
});


passport.deserializeUser(function(user,done){
done(null,user);
});

module.export = {
Users: Users
}
5 changes: 5 additions & 0 deletions default_b64.js

Large diffs are not rendered by default.

Binary file added docs/Sprint 2 API Docs.pdf
Binary file not shown.
47 changes: 47 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Boundless Aircraft Maintenance Managment
oAuth2 Implement Module
Author: Christopher Allen
Creation: 1/18/2024
Last Modified: 1/27/2024 - Christopher Allen
Changes:
- added session tracking
- added sequelize for ORM in auth.js
- created seperate files for internal and external routes
- added user ID to login page for debug only
Start with npm start
*/
try {
const express = require('express');
const session = require('express-session');
const passport = require('passport');
const internalDBRoutes = require(__dirname + "/routes/internalDBroutes.js");
const externalRoutes = require(__dirname + '/routes/externalRoutes.js');
require("./auth");
const app = express();
const app2 = express();
app.use(session({ secret: 'SE300!!', resave: false, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.enable("trust proxy", true);
app.use(express.urlencoded({ extended: true, limit: '50mb' }));
app.use(express.json());
app2.use(express.json());
app2.set('view engine', 'pug');
app2.set('views', './internal_routes');
app2.use(express.urlencoded({ extended: true, limit: '50mb' }));
app.set('view engine', 'pug');
app.set('views', './login_routes');
internalDBRoutes.startInternal(app2);
externalRoutes.startExternalRoutes(app,passport);
app.listen(8001, ()=>{ console.log("Oauth Running on Port 8001 for NGINX");})
app.listen(8000, ()=>{ console.log("Oauth Running on Port 8000 for NGINX");})
app2.listen(6969, ()=>{ console.log("Internal Query Server running on Port 6969");})
} catch (error) {
console.log(error);
}
Loading

0 comments on commit 07a8a3a

Please sign in to comment.