Skip to content

Commit

Permalink
Merge pull request #1 from NarayanAdithya/master
Browse files Browse the repository at this point in the history
Version1
  • Loading branch information
NarayanAdithya authored Feb 26, 2022
2 parents 4a52cf9 + a27754e commit 01a8419
Show file tree
Hide file tree
Showing 29 changed files with 1,938 additions and 0 deletions.
10 changes: 10 additions & 0 deletions adithya.py
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)
Binary file added app.db
Binary file not shown.
41 changes: 41 additions & 0 deletions app/__init__.py
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

15 changes: 15 additions & 0 deletions app/administrator.py
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))
7 changes: 7 additions & 0 deletions app/auth/__init__.py
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


25 changes: 25 additions & 0 deletions app/auth/models.py
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)



37 changes: 37 additions & 0 deletions app/auth/routes.py
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')




12 changes: 12 additions & 0 deletions app/models.py
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}>'
22 changes: 22 additions & 0 deletions app/routes.py
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')
4 changes: 4 additions & 0 deletions app/static/css/index.css
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');
Loading

0 comments on commit 01a8419

Please sign in to comment.