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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Hellenkamp
website
Commits
726fda6f
Commit
726fda6f
authored
8 years ago
by
Andreas Valder
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of git.fsmpi.rwth-aachen.de:julianundandyfrickelnkram/videoagwebsite
parents
25297e65
1ce40ec8
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
+34
-2
34 additions, 2 deletions
server.py
templates/base.html
+3
-2
3 additions, 2 deletions
templates/base.html
with
37 additions
and
4 deletions
server.py
+
34
−
2
View file @
726fda6f
#!/bin/python
from
flask
import
Flask
,
render_template
,
g
,
request
,
url_for
,
redirect
,
session
import
mysql.connector
import
sqlite3
import
os
#import ldap3
import
re
app
=
Flask
(
__name__
)
...
...
@@ -43,6 +41,7 @@ def dict_factory(cursor, row):
def
query
(
operation
,
*
params
):
if
config
[
'
DB_ENGINE
'
]
==
'
mysql
'
:
import
mysql.connector
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
g
.
db
=
mysql
.
connector
.
connect
(
user
=
config
[
'
MYSQL_USER
'
],
password
=
config
[
'
MYSQL_PASSWD
'
],
host
=
config
[
'
MYSQL_HOST
'
],
database
=
config
[
'
MYSQL_DB
'
])
cur
=
g
.
db
.
cursor
(
dictionary
=
True
)
...
...
@@ -78,6 +77,7 @@ def ldapauth(user, password):
notldap
=
{
'
videoag
'
:(
'
videoag
'
,
[
'
users
'
,
'
videoag
'
]),
'
gustav
'
:(
'
passwort
'
,
[
'
users
'
])}
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
if
'
LDAP_HOST
'
in
config
:
import
ldap3
try
:
conn
=
ldap3
.
Connection
(
config
[
'
LDAP_HOST
'
],
'
uid=%s,ou=users,dc=fsmpi,dc=rwth-aachen,dc=de
'
%
user
,
password
,
auto_bind
=
True
)
if
conn
.
search
(
"
ou=groups,dc=fsmpi,dc=rwth-aachen,dc=de
"
,
"
(&(cn=*)(memberUid=%s))
"
%
user
,
attributes
=
[
'
cn
'
]):
...
...
@@ -90,6 +90,20 @@ def ldapauth(user, password):
return
user
,
notldap
[
user
][
1
]
return
None
,
[]
def
ldapget
(
user
):
notldap
=
{
'
videoag
'
:
{
'
uid
'
:
'
videoag
'
,
'
givenName
'
:
'
Video
'
,
'
sn
'
:
'
Geier
'
},
'
gustav
'
:
{
'
uid
'
:
'
gustav
'
,
'
givenName
'
:
'
Gustav
'
,
'
sn
'
:
'
Geier
'
}}
user
=
LDAP_USERRE
.
sub
(
r
''
,
user
.
lower
())
if
'
LDAP_HOST
'
in
config
:
import
ldap3
conn
=
ldap3
.
Connection
(
'
ldaps://rumo.fsmpi.rwth-aachen.de
'
,
auto_bind
=
True
)
conn
.
search
(
"
ou=users,dc=fsmpi,dc=rwth-aachen,dc=de
"
,
"
(uid=%s)
"
%
user
,
attributes
=
ldap3
.
ALL_ATTRIBUTES
)
e
=
conn
.
entries
[
0
]
return
{
'
uid
'
:
user
,
'
givenName
'
:
e
.
givenName
.
value
,
'
sn
'
:
e
.
sn
.
value
}
else
:
return
notldap
[
user
]
@app.route
(
'
/
'
)
def
index
():
return
render_template
(
'
index.html
'
,
latestvideos
=
query
(
'''
...
...
@@ -153,5 +167,23 @@ def course():
else
:
return
redirect
(
url_for
(
'
index
'
))
@app.route
(
'
/login
'
,
methods
=
[
'
POST
'
])
def
login
():
user
,
groups
=
ldapauth
(
request
.
form
.
get
(
'
user
'
),
request
.
form
.
get
(
'
password
'
))
if
user
and
'
users
'
in
groups
:
session
[
'
user
'
]
=
ldapget
(
user
)
if
'
ref
'
in
request
.
values
:
return
redirect
(
request
.
values
[
'
ref
'
])
else
:
return
redirect
(
url_for
(
'
index
'
))
@app.route
(
'
/logout
'
)
def
logout
():
session
.
pop
(
'
user
'
)
if
'
ref
'
in
request
.
values
:
return
redirect
(
request
.
values
[
'
ref
'
])
else
:
return
redirect
(
url_for
(
'
index
'
))
if
__name__
==
'
__main__
'
:
app
.
run
()
This diff is collapsed.
Click to expand it.
templates/base.html
+
3
−
2
View file @
726fda6f
...
...
@@ -56,7 +56,7 @@
</li>
{% endfor %}
<li
class=
"navbar-right"
>
{% if not session.user
id
is defined %}
{% if not session.user is defined %}
<a
id=
"loginpopover"
data-container=
"body"
data-toggle=
"popover"
data-placement=
"bottom"
>
<span
class=
"glyphicon glyphicon-log-in"
></span>
</a>
...
...
@@ -70,7 +70,8 @@
)
</script>
{% else %}
<a
herf=
"/logout"
>
<a
href=
"/logout?ref={{ request.url|urlencode }}"
>
{{ session.user.givenName }}
<span
class=
"glyphicon glyphicon-log-out"
></span>
</a>
{% endif %}
...
...
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