Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
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
Martin Mareš
Odevzdávací Systém MO
Commits
38eccaef
"README.md" did not exist on "61bbd5072aa63eb1b7b533485c7dc8a0fb0ae924"
Commit
38eccaef
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Velmi hrubá implementace převtělování
parent
48361e6a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/web/main.py
+26
-7
26 additions, 7 deletions
mo/web/main.py
with
26 additions
and
7 deletions
mo/web/main.py
+
26
−
7
View file @
38eccaef
...
...
@@ -2,9 +2,11 @@ import datetime
from
flask
import
render_template
,
request
,
g
,
redirect
,
url_for
,
session
from
flask_wtf
import
FlaskForm
import
werkzeug.exceptions
import
wtforms
import
wtforms.validators
as
validators
from
sqlalchemy.orm
import
joinedload
from
typing
import
Optional
import
mo.util
import
mo.db
as
db
...
...
@@ -21,6 +23,15 @@ class LoginForm(FlaskForm):
reset
=
wtforms
.
SubmitField
(
'
Obnovit heslo
'
)
def
after_login
(
user
:
db
.
User
,
url
:
Optional
[
str
]
=
None
):
if
not
url
:
if
user
.
is_admin
or
user
.
is_org
:
url
=
url_for
(
'
org_index
'
)
else
:
url
=
url_for
(
'
index
'
)
return
redirect
(
url
)
@app.route
(
'
/auth/login
'
,
methods
=
(
'
GET
'
,
'
POST
'
))
def
login
():
form
=
LoginForm
()
...
...
@@ -57,13 +68,7 @@ def login():
mo
.
users
.
login
(
user
)
db
.
get_session
().
commit
()
session
[
'
uid
'
]
=
user
.
user_id
url
=
form
.
next
.
data
if
not
url
:
if
user
.
is_admin
or
user
.
is_org
:
url
=
url_for
(
'
org_index
'
)
else
:
url
=
url_for
(
'
index
'
)
return
redirect
(
url
)
return
after_login
(
user
,
form
.
next
.
data
)
return
render_template
(
'
login.html
'
,
form
=
form
,
error
=
error
)
...
...
@@ -75,6 +80,20 @@ def logout():
return
redirect
(
url_for
(
'
index
'
))
@app.route
(
'
/auth/incarnate/<int:id>
'
)
def
incarnate
(
id
):
if
not
g
.
user
.
is_admin
:
raise
werkzeug
.
exceptions
.
Forbidden
()
new_user
=
db
.
get_session
().
query
(
db
.
User
).
get
(
id
)
if
not
new_user
:
raise
werkzeug
.
exceptions
.
NotFound
()
app
.
logger
.
info
(
'
Login: Uživatel #%s se převtělil na #%s
'
,
g
.
user
.
user_id
,
new_user
.
user_id
)
session
[
'
uid
'
]
=
new_user
.
user_id
return
after_login
(
new_user
)
@app.route
(
'
/user/settings
'
)
def
user_settings
():
sess
=
db
.
get_session
()
...
...
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