Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
c0633418_cmt120_cw2
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Iorns
c0633418_cmt120_cw2
Commits
4f0e570e
Commit
4f0e570e
authored
7 months ago
by
Benjamin Iorns
Browse files
Options
Downloads
Patches
Plain Diff
@login_required added to relevant routes.
parent
a09e8a64
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
portfolio/__init__.py
+1
-1
1 addition, 1 deletion
portfolio/__init__.py
portfolio/routes.py
+16
-4
16 additions, 4 deletions
portfolio/routes.py
portfolio/templates/newComment.html
+0
-2
0 additions, 2 deletions
portfolio/templates/newComment.html
portfolio/utils.py
+2
-0
2 additions, 0 deletions
portfolio/utils.py
with
19 additions
and
7 deletions
portfolio/__init__.py
+
1
−
1
View file @
4f0e570e
...
...
@@ -5,7 +5,6 @@ from dotenv import load_dotenv, dotenv_values
from
sqlalchemy.orm
import
declarative_base
from
flask_mail
import
Mail
,
Message
from
datetime
import
datetime
from
markdown
import
markdown
from
flask_bcrypt
import
Bcrypt
from
flask_login
import
LoginManager
from
flask_uuid
import
FlaskUUID
...
...
@@ -46,6 +45,7 @@ login_manager = LoginManager()
login_manager
.
init_app
(
app
)
login_manager
.
login_view
=
'
login
'
# UUID
uuid
=
FlaskUUID
(
app
)
...
...
This diff is collapsed.
Click to expand it.
portfolio/routes.py
+
16
−
4
View file @
4f0e570e
...
...
@@ -7,13 +7,13 @@ from dotenv import load_dotenv, dotenv_values
from
portfolio.forms
import
*
import
math
from
portfolio.utils
import
*
from
flask_login
import
login_user
,
current_user
from
flask_login
import
login_user
,
current_user
,
login_required
,
logout_user
import
uuid
load_dotenv
()
@login_manager.user_loader
def
load_user
(
user_id
):
return
User
DAO
.
getUser
(
db
,
user_id
)
return
User
ORM
.
query
.
get
(
user_id
)
@app.route
(
"
/
"
)
...
...
@@ -86,6 +86,7 @@ def blogpost(slug):
@app.route
(
'
/blog/new_blogpost
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@login_required
def
newBlogpost
():
form
=
Blogpost
()
if
form
.
validate_on_submit
():
...
...
@@ -105,6 +106,7 @@ def newBlogpost():
@app.route
(
'
/blog/delete_post/<id>
'
)
@login_required
def
deleteBlogpost
(
id
):
BlogpostDAO
.
deleteBlogpostByID
(
db
,
id
)
...
...
@@ -112,6 +114,7 @@ def deleteBlogpost(id):
@app.route
(
'
/blog/delete_comment/<id>
'
)
@login_required
def
deleteComment
(
id
):
CommentDAO
.
deleteCommentByID
(
db
,
id
)
...
...
@@ -119,11 +122,13 @@ def deleteComment(id):
@app.route
(
'
/blog/add_comment/<post_id>
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@login_required
def
addComment
(
post_id
):
print
(
current_user
.
username
)
form
=
Comment
()
if
form
.
validate_on_submit
():
new_comment
=
CommentORM
(
author
=
form
.
author
.
data
,
author
=
current_user
.
username
,
comment
=
form
.
comment
.
data
,
timestamp
=
int
(
round
(
datetime
.
now
().
timestamp
())),
post_id
=
post_id
...
...
@@ -143,6 +148,7 @@ def login():
if
user
:
if
bcrypt
.
check_password_hash
(
user
.
password
,
form
.
password
.
data
):
login_user
(
user
)
print
(
current_user
.
is_active
)
return
redirect
(
url_for
(
'
blog
'
))
return
render_template
(
'
login.html
'
,
form
=
form
)
...
...
@@ -242,4 +248,10 @@ def resetPassword(uuid):
@app.route
(
'
/linkExpired
'
)
def
expired
():
return
render_template
(
'
linkExpired.html
'
)
\ No newline at end of file
return
render_template
(
'
linkExpired.html
'
)
@app.route
(
"
/logout
"
)
@login_required
def
logout
():
logout_user
()
return
"
<p> You have been logged out </p>
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
portfolio/templates/newComment.html
+
0
−
2
View file @
4f0e570e
...
...
@@ -3,8 +3,6 @@
<form
id=
"comment"
method=
"post"
>
{{ form.hidden_tag() }}
<label
for=
"name"
>
Name:
</label>
{{ form.author(size=50)}}
<br>
<label
for=
"comment"
>
Comment
</label>
{{ form.comment(cols=30, rows=5)}}
...
...
This diff is collapsed.
Click to expand it.
portfolio/utils.py
+
2
−
0
View file @
4f0e570e
from
datetime
import
datetime
from
markdown
import
markdown
def
to_slug_case
(
str
):
slug
=
""
...
...
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