dostosowanie do code review

This commit is contained in:
Mateusz779 2023-04-24 08:33:51 +02:00
parent ac3e7f7edf
commit d397dfa11f

17
app.py
View File

@ -27,6 +27,13 @@ def login_required(f):
return f(*args, **kwargs) return f(*args, **kwargs)
return login_function return login_function
def is_logged(auth_token):
if auth_token != "" or auth_token is not None:
if db.get_user_bytoken(auth_token) is not None:
return True
return False
@app.route('/') @app.route('/')
@login_required @login_required
def main(): def main():
@ -35,17 +42,17 @@ def main():
@app.route('/login') @app.route('/login')
@login_required
def login(): def login():
if is_logged(request.cookies.get('auth_token')) is True:
machines_all = db.get_machines()
return render_template('index.html', ssh_port=config.webssh_port, machines=machines_all.machines) return render_template('index.html', ssh_port=config.webssh_port, machines=machines_all.machines)
return render_template('login.html')
@app.route('/logout') @app.route('/logout')
def logout(): def logout():
auth_token = request.cookies.get('auth_token') if is_logged(request.cookies.get('auth_token')) is True:
if auth_token != "" or auth_token is not None: db.del_auth_token(request.cookies.get('auth_token'))
if db.get_user_bytoken(auth_token) is not None:
db.del_auth_token(auth_token)
response = make_response(redirect('/')) response = make_response(redirect('/'))
response.delete_cookie('auth_token') response.delete_cookie('auth_token')
return response return response