Cleaning app.py
This commit is contained in:
parent
27300bb361
commit
a7c29c0d38
1 changed files with 4 additions and 113 deletions
|
|
@ -23,9 +23,6 @@ try:
|
|||
crypt_pass=True
|
||||
except:
|
||||
crypt_pass=False
|
||||
#import gettext
|
||||
|
||||
#_=pgettext(__file__)
|
||||
|
||||
login_tries=5
|
||||
|
||||
|
|
@ -46,64 +43,8 @@ if hasattr(config, 'email_address'):
|
|||
email_address=config.email_address
|
||||
|
||||
|
||||
#admin_app=Blueprint('admin_app', __name__, static_folder='static')
|
||||
|
||||
#@admin_app.before_request
|
||||
"""
|
||||
def admin_prepare():
|
||||
|
||||
g.connection=WebModel.connection()
|
||||
|
||||
if request.endpoint!='admin_app.login' and request.endpoint!='admin_app.signup' and request.endpoint!='admin_app.need_auth' and request.endpoint!='admin_app.auth_check':
|
||||
|
||||
if 'login_admin' not in session:
|
||||
|
||||
if 'remember_login_admin' in request.cookies:
|
||||
|
||||
with g.connection.query('select count(id) as count_id from useradmin where token_login=%s', [request.cookies['remember_login_admin']]) as cursor:
|
||||
|
||||
arr_count=cursor.fetchone()
|
||||
|
||||
if arr_count['count_id']==0:
|
||||
|
||||
url_redirect=config.domain_url+url_for('admin_app.login', _external=False)
|
||||
|
||||
return redirect(url_redirect)
|
||||
else:
|
||||
|
||||
session['login_admin']=True
|
||||
|
||||
else:
|
||||
|
||||
url_redirect=config.domain_url+url_for('admin_app.login', _external=False)
|
||||
|
||||
return redirect(url_redirect)
|
||||
else:
|
||||
|
||||
#print(session['verify_auth'])
|
||||
if request.endpoint!='admin_app.logout':
|
||||
|
||||
if not session.get('verify_auth', True):
|
||||
|
||||
url_redirect=config.domain_url+url_for('admin_app.need_auth', _external=False)
|
||||
|
||||
return redirect(url_redirect)
|
||||
|
||||
"""
|
||||
#home=welcome_app.route("/")(home)
|
||||
admin_prepare=admin_app.before_request(admin_prepare)
|
||||
|
||||
#@admin_app.after_request
|
||||
"""
|
||||
def admin_finished(response):
|
||||
|
||||
#print('pepe')
|
||||
|
||||
g.connection.close()
|
||||
|
||||
return response
|
||||
"""
|
||||
|
||||
admin_finished=admin_app.after_request(admin_finished)
|
||||
|
||||
# Load modules from admin
|
||||
|
|
@ -123,64 +64,20 @@ for app in config.apps:
|
|||
arr_modules_admin={}
|
||||
|
||||
for app_load in config_admin:
|
||||
|
||||
#print(app)
|
||||
|
||||
if len(app_load)==3:
|
||||
|
||||
arr_modules_admin[app_load[2]+'/']=import_module(app_load[1])
|
||||
#arr_modules_admin[app_load[2]+'/'].admin=admin_app.route(arr_modules_admin[app_load[2]+'/'])(arr_modules_admin[app_load[2]+'/'].admin)
|
||||
#print(app_load[1])
|
||||
|
||||
elif len(app_load)==4:
|
||||
|
||||
arr_modules_admin[app_load[2]+'/'+app_load[3]]=import_module(app_load[1])
|
||||
|
||||
#print(app_load[1])
|
||||
|
||||
@admin_app.route('/admin/')
|
||||
def admin():
|
||||
|
||||
return t.load_template('home.phtml', title=_('Admin'))
|
||||
|
||||
"""
|
||||
@admin_app.route('/admin/')
|
||||
@admin_app.route('/admin/<module>', methods=['GET', 'POST'])
|
||||
@admin_app.route('/admin/<module>/<submodule>', methods=['GET', 'POST'])
|
||||
def admin(module='', submodule=''):
|
||||
|
||||
if module=='':
|
||||
|
||||
return t.load_template('home.phtml', title=I18n.lang('admin', 'paramecio_admin', 'Paramecio admin'))
|
||||
|
||||
else:
|
||||
|
||||
path_module=module+'/'+submodule
|
||||
|
||||
if path_module in arr_modules_admin:
|
||||
|
||||
t_mod=copy.copy(t)
|
||||
|
||||
templates_path=path.dirname(arr_modules_admin[module+'/'+submodule].__file__).replace('/admin', '')+'/templates'
|
||||
|
||||
try:
|
||||
index_value = t_mod.env.directories.index(templates_path)
|
||||
except ValueError:
|
||||
t_mod.env.directories.insert(0, templates_path)
|
||||
|
||||
content=arr_modules_admin[path_module].admin(t=t)
|
||||
|
||||
if type(content).__name__=='str':
|
||||
|
||||
return t.load_template('content.phtml', title=I18n.lang('admin', 'paramecio_admin', 'Paramecio admin'), contents=content, path_module=path_module)
|
||||
|
||||
else:
|
||||
|
||||
return content
|
||||
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
"""
|
||||
|
||||
@admin_app.route('/admin/logout/')
|
||||
def logout():
|
||||
|
|
@ -201,7 +98,6 @@ def logout():
|
|||
@admin_app.route('/admin/login/', methods=['GET', 'POST'])
|
||||
def login():
|
||||
|
||||
#connection=WebModel.connection()
|
||||
new_crypt=False
|
||||
|
||||
user_admin=UserAdmin(g.connection)
|
||||
|
|
@ -236,12 +132,14 @@ def login():
|
|||
check_pass=user_admin.fields['password'].verify(password, arr_user['password'])
|
||||
|
||||
if not check_pass:
|
||||
#check_pass=password_ok(password, arr_user['password'])
|
||||
|
||||
try:
|
||||
check_pass=compare_hash(arr_user['password'], crypt.crypt(password, arr_user['password']))
|
||||
new_crypt=True
|
||||
except:
|
||||
|
||||
print('Warning: python developers deleting unix crypt module support, you cannot use sha512 passwords.')
|
||||
|
||||
check_pass=False
|
||||
pass
|
||||
|
||||
|
|
@ -463,13 +361,6 @@ def change_theme():
|
|||
|
||||
return {'error': error}
|
||||
|
||||
"""
|
||||
@admin_app.route('/admin/recovery_password/')
|
||||
def recovery_password():
|
||||
|
||||
return ""
|
||||
"""
|
||||
|
||||
def check_login_tries():
|
||||
|
||||
logintries=LoginTries(g.connection)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue