-
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.
Merge pull request #1 from NarayanAdithya/master
Version1
- Loading branch information
Showing
29 changed files
with
1,938 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from app import app, db | ||
from app.auth.models import User | ||
from app.models import TechStack | ||
@app.shell_context_processor | ||
def make_shell_context(): | ||
return {'db':db,'user':User,'tech':TechStack} | ||
|
||
|
||
if __name__=='__main__': | ||
app.run(debug=True) |
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,41 @@ | ||
#Import of necessary utility functions | ||
from flask import Flask, render_template, url_for | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_login import LoginManager | ||
from flask_migrate import Migrate | ||
from flask_admin import Admin | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
|
||
#Loading Env's | ||
load_dotenv() | ||
|
||
#Importing Config | ||
import config | ||
|
||
#App Declaration and configuration | ||
app = Flask(__name__) | ||
print(os.environ.get('environment')) | ||
if os.environ.get('environment')=='Development': | ||
app.config.from_object(config.Development) | ||
elif os.environ.get('environment')=='Production': | ||
app.config.from_object(config.Production) | ||
|
||
#Database Configuration | ||
db = SQLAlchemy(app) | ||
migrate = Migrate(app, db) | ||
|
||
#Login Configurations | ||
login = LoginManager(app) | ||
login.login_view='auth.loginUser' | ||
|
||
#Flask Admin Configurations | ||
admin = Admin(app, name='Portfolio', template_mode='bootstrap3') | ||
|
||
#Blueprine Registration | ||
from app.auth import auth | ||
app.register_blueprint(auth,url_prefix='/auth') | ||
|
||
from app import routes, models, administrator | ||
|
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,15 @@ | ||
from flask_admin.contrib.sqla import ModelView | ||
from app.models import TechStack | ||
from app import admin, db, login | ||
from flask_login import current_user | ||
from flask import request, redirect, url_for | ||
class PortfolioModelView(ModelView): | ||
|
||
def is_accessible(self): | ||
return current_user.is_authenticated | ||
|
||
def inaccessible_callback(self, **kwargs): | ||
# redirect to login page if user doesn't have access | ||
return redirect(url_for('login')) | ||
|
||
admin.add_view(PortfolioModelView(TechStack,db.session)) |
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,7 @@ | ||
from flask import Blueprint | ||
|
||
auth = Blueprint('auth', __name__) | ||
|
||
from . import routes, models | ||
|
||
|
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,25 @@ | ||
from enum import unique | ||
from app import db, login | ||
from flask_login import UserMixin | ||
from datetime import datetime | ||
from werkzeug.security import generate_password_hash,check_password_hash | ||
|
||
@login.user_loader | ||
def load_user(id): | ||
return User.query.get(int(id)) | ||
|
||
class User(UserMixin,db.Model): | ||
id=db.Column(db.Integer,primary_key=True) | ||
role=db.Column(db.String(20),default='Admin') | ||
password_hash_key1=db.Column(db.String(120)) | ||
password_hash_key2=db.Column(db.String(120)) | ||
password_hash_key3=db.Column(db.String(120)) | ||
def set_password(self,key1,key2,key3): | ||
self.password_hash_key1=generate_password_hash(key1) | ||
self.password_hash_key2=generate_password_hash(key2) | ||
self.password_hash_key3=generate_password_hash(key3) | ||
def check_password(self,k1,k2,k3): | ||
return check_password_hash(self.password_hash_key1,k1) and check_password_hash(self.password_hash_key2,k2) and check_password_hash(self.password_hash_key3,k3) | ||
|
||
|
||
|
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,37 @@ | ||
from app import db | ||
from flask_login import current_user,logout_user | ||
from datetime import datetime | ||
from flask import request,redirect,url_for,render_template | ||
from flask_login import login_user | ||
from . import auth | ||
from app.auth.models import User | ||
|
||
|
||
@auth.route('/logout') | ||
def logout(): | ||
current_user.last_seen=datetime.utcnow() | ||
db.session.commit() | ||
logout_user() | ||
return redirect(url_for('home')) | ||
|
||
@auth.route('/invalid') | ||
def invalid(): | ||
return render_template('invalid.html') | ||
|
||
@auth.route('/adithyalogin',methods=['GET','POST']) | ||
def loginUser(): | ||
if current_user.is_authenticated: | ||
return redirect(url_for('home')) | ||
if request.method=='POST': | ||
k1, k2, k3 = request.form['k1'], request.form['k2'], request.form['k3'] | ||
u=User.query.get(1) | ||
if u.check_password(k1,k2,k3): | ||
login_user(u) | ||
return redirect(url_for('home')) | ||
else: | ||
return redirect(url_for('auth.invalid')) | ||
return render_template('login_adithya.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,12 @@ | ||
from sqlalchemy import null | ||
from app import db | ||
|
||
|
||
|
||
class TechStack(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
image_name = db.Column(db.String(30)) | ||
name = db.Column(db.String(30), unique=True,nullable=False) | ||
description = db.Column(db.String(240),nullable=False) | ||
def __repr__(self): | ||
return f'<{self.name}>' |
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,22 @@ | ||
from app import app | ||
from flask import render_template, request, redirect, url_for | ||
from flask_login import login_required | ||
from werkzeug.utils import secure_filename | ||
import os | ||
from app.models import TechStack | ||
#Route Home / or /home | ||
@app.route('/home') | ||
@app.route('/') | ||
def home(): | ||
techstack = TechStack.query.all() | ||
return render_template('index.html',techstack=techstack) | ||
|
||
|
||
@app.route('/image_upload', methods=['GET','POST']) | ||
@login_required | ||
def image_upload(): | ||
if request.method=='POST': | ||
f=request.files['img'] | ||
f.save(os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(f.filename))) | ||
return redirect(url_for('image_upload',status='Success')) | ||
return render_template('image_upload.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,4 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap'); |
Oops, something went wrong.