Commit 3c090e7c authored by YSelf Tool's avatar YSelf Tool

Added basic files for flask project

SQLALCHEMY_DATABASE_URI = "sqlite:///test.db"
SECRET_KEY = "iesoogh9jangoocheihoig5iejeenixaingah7NuashahSeechaerohg6ouw9moojei8ahmooPaes1ie"
DEBUG = True
#!/usr/bin/env python3
from flask import Flask, g, current_up, request, render_template, session, flash, redirect, url_for, abort
from flask.ext.login import login_user, logout_user, login_required, current_user
from flask.ext.principal import Principal, Identity, AnonymousIdentity, identity_changed, identity_loaded, UserNeed, RoleNeed
from passlib.hash import pbkdf2_sha256
import config
from shared import db, login_manager
from models.forms import LoginForm
from models.database import User
app = Flask(__name__)
login_manager.login_view = "login"
login_manager.login_message_category = "alert-error"
from modules import admin
app.register_blueprint(admin.admin, url_prefix="/admin")
def index():
if not len(db.session.query(User).all()) > 0:
fullname = input("Fullname for admin user:")
username = input("Username for admin user:")
password = pbkdf2_sha256.encrypt(input("Password for admin user:"), rounds=200000, salt_size=16)
user = User(fullname, username, password, ["admin", "user"])
return render_template("index.html")
def on_identity_loaded(sender, identity):
# Set the identity user object
identity.user = current_user
# Add the UserNeed to the identity
if hasattr(current_user, "id"):
# Assuming the User Model has a list of roles, update the identity
# with the roles that the user provides
if hasattr(current_user, "roles") and current_user.roles is not None:
for role in current_user.roles:
def load_user(user_id):
return db.session.query(User).filter_by(id=user_id).first()
if __name__ == "__main__":
from flask import abort
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager
from flask.ext.principal import Permission, RoleNeed
db = SQLAlchemy()
login_manager = LoginManager()
admin_permission = Permission(RoleNeed("admin"))
user_permission = Permission(RoleNeed("user"))
roles = ["user", "admin"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment