Skip to content

Commit

Permalink
Implement #1, move login_required to views
Browse files Browse the repository at this point in the history
  • Loading branch information
dwi purnomo committed Mar 15, 2017
1 parent 0343a79 commit 5d4ec72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
18 changes: 2 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
import datetime
from functools import wraps
from flask import jsonify, flash, url_for
from openedoo.core.libs import (render_template, redirect, request,
session, blueprint)
from openedoo.core.libs.tools import (session_encode, hashing_werkzeug,
check_werkzeug)
from openedoo_project import app, db
from .views import login_required
from .models import User
from .forms import (flash_errors, LoginForm,
EditEmployeeForm, AddEmployeeForm)
from flask import jsonify, flash, url_for


module_employee = blueprint('module_employee', __name__,
template_folder='templates',
static_folder='static')


def login_required(f):
@wraps(f)
def wrap(*args, **kwargs):
session.permanent = True
try:
if session['username'] is False:
flash('You must login first!')
return redirect(url_for('module_employee.login'))
return f(*args, **kwargs)
except KeyError:
flash('Your session is timeout!')
return redirect(url_for('module_employee.login'))
return wrap


@module_employee.route('/', methods=['GET'])
@login_required
def dashboard():
Expand Down
1 change: 1 addition & 0 deletions views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .authentication import login_required
19 changes: 19 additions & 0 deletions views/authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from functools import wraps
from flask import flash, url_for
from openedoo.core.libs import session, redirect


def login_required(f):
@wraps(f)
def wrap(*args, **kwargs):
"""Checks user is logged in or not in the session"""
session.permanent = True
try:
if session['username'] is False:
flash('You must login first!')
return redirect(url_for('module_employee.login'))
return f(*args, **kwargs)
except KeyError:
flash('Your session is timeout!')
return redirect(url_for('module_employee.login'))
return wrap

0 comments on commit 5d4ec72

Please sign in to comment.