Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect views users #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codeeve/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
SITE_ID = 1
ACCOUNT_LOGIN_REDIRECT_URL = '/projects'
ACCOUNT_LOGOUT_ON_GET = True
LOGIN_URL = '/accounts/github/login/?process=login'


# Static files (CSS, JavaScript, Images)
Expand Down
2 changes: 2 additions & 0 deletions projects/templates/projects/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<div class="content-section-a">

<div class="container">
{% if view.request.user.is_authenticated %}
<a href="create/">Create a project</a>
{% endif %}
{% for project in object_list %}
<div class="row">
<div class="col-lg-5 col-sm-6">
Expand Down
13 changes: 11 additions & 2 deletions projects/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
Expand All @@ -8,10 +10,17 @@

class ProjectCreate(CreateView):
model = Project
fields = ['title', 'description', 'max_members', 'difficulty',
'image', 'participants', 'coach', 'owner']
fields = ['title', 'description', 'max_members', 'difficulty', 'image']
success_url = reverse_lazy('project_list')

@method_decorator(login_required)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these method doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making sure all the post/get methods will be require login first, otherwise it will fail with 401 I think

def dispatch(self, *args, **kwargs):
return super(ProjectCreate, self).dispatch(*args, **kwargs)

def form_valid(self, form):
form.instance.owner = self.request.user
return super(ProjectCreate, self).form_valid(form)


class ProjectUpdate(UpdateView):
model = Project
Expand Down