Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Hellenkamp
website
Commits
c8209fbc
Commit
c8209fbc
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Extended login and added login_required decorator
parent
56e1dfcb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
server.py
+15
-2
15 additions, 2 deletions
server.py
templates/login.html
+22
-0
22 additions, 0 deletions
templates/login.html
with
37 additions
and
2 deletions
server.py
+
15
−
2
View file @
c8209fbc
#!/bin/python
from
flask
import
*
from
flask
import
*
from
functools
import
wraps
import
sqlite3
import
sqlite3
import
os
import
os
import
re
import
re
...
@@ -109,6 +110,16 @@ def ldapget(user):
...
@@ -109,6 +110,16 @@ def ldapget(user):
else
:
else
:
return
notldap
[
user
][
2
]
return
notldap
[
user
][
2
]
def
login_required
(
func
):
@wraps
(
func
)
def
decorator
(
*
args
,
**
kwargs
):
if
not
'
user
'
in
session
:
flash
(
'
Diese Funktion ist nur für Moderatoren verfügbar!
'
)
return
redirect
(
url_for
(
'
login
'
,
ref
=
request
.
url
))
else
:
return
func
(
*
args
,
**
kwargs
)
return
decorator
@app.route
(
'
/
'
)
@app.route
(
'
/
'
)
def
index
():
def
index
():
return
render_template
(
'
index.html
'
,
latestvideos
=
query
(
'''
return
render_template
(
'
index.html
'
,
latestvideos
=
query
(
'''
...
@@ -172,8 +183,10 @@ def course():
...
@@ -172,8 +183,10 @@ def course():
else
:
else
:
return
redirect
(
url_for
(
'
index
'
))
return
redirect
(
url_for
(
'
index
'
))
@app.route
(
'
/login
'
,
methods
=
[
'
POST
'
])
@app.route
(
'
/login
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
login
():
def
login
():
if
request
.
method
==
'
GET
'
:
return
render_template
(
'
login.html
'
)
user
,
groups
=
ldapauth
(
request
.
form
.
get
(
'
user
'
),
request
.
form
.
get
(
'
password
'
))
user
,
groups
=
ldapauth
(
request
.
form
.
get
(
'
user
'
),
request
.
form
.
get
(
'
password
'
))
if
user
and
'
users
'
in
groups
:
if
user
and
'
users
'
in
groups
:
session
[
'
user
'
]
=
ldapget
(
user
)
session
[
'
user
'
]
=
ldapget
(
user
)
...
...
This diff is collapsed.
Click to expand it.
templates/login.html
0 → 100644
+
22
−
0
View file @
c8209fbc
{% extends "base.html" %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-xs-offset-1 col-xs-10"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h1
class=
"panel-title"
>
Login für Moderatoren
</h1>
</div>
<div
class=
"panel-body"
>
<form
method=
"post"
action=
"login"
>
<input
placeholder=
"User"
name=
"user"
type=
"text"
><br>
<input
placeholder=
"Password"
name=
"password"
type=
"password"
><br>
{% if 'ref' in request.values %}
<input
type=
"hidden"
name=
"ref"
value=
"{{ request.values.ref|e }}"
>
{% endif %}
<input
type=
"submit"
value=
"Login"
>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment