Skip to content

Commit

Permalink
Merge pull request #191 from ponder-lab/user-registration
Browse files Browse the repository at this point in the history
adding new user registration form
  • Loading branch information
y3pio authored Feb 7, 2025
2 parents 79a8f19 + e58cb21 commit fb87177
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,3 @@ To build the Docker image:
## User Roles

The app has a complex relationship between different kinds of users. The roles are described in our [wiki](https://github.com/ponder-lab/Imperative-DL-Study-Web-App/wiki/Roles).

## Admin Account

Field | Value
-- | --
Username | admin
Password | umjawaRZ7GY5C7Q

You can use this to register for accounts in the web app that is deployed on Heroku.
1 change: 1 addition & 0 deletions mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
'default': dj_database_url.config(conn_max_age=600)
}

# Custom DB config.
# DATABASES = {
# # 'default': {
# # 'ENGINE': 'django.db.backends.mysql',
Expand Down
14 changes: 14 additions & 0 deletions ponder/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
from ponder.models import Categorization, ProblemCategory, ProblemCause, ProblemFix, ProblemSymptom, Categorizer


class UserRegistrationForm(forms.ModelForm):
password = forms.CharField(label='Password', widget=forms.PasswordInput)
password2 = forms.CharField(label='Repeat password', widget=forms.PasswordInput)

class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email')

def clean_password2(self):
cd = self.cleaned_data
if cd['password'] != cd['password2']:
raise forms.ValidationError('Passwords don\'t match.')
return cd['password2']

class UserForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput())
class Meta():
Expand Down
1 change: 1 addition & 0 deletions ponder/templates/ponder/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<li><a class="navbar-link" href="{% url 'ponder:user_login' %}">Login</a></li>
<li><a class="navbar-link" href="{% url 'ponder:register' %}">Register</a></li>
{% endif %}
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions ponder/templates/ponder/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ <h1>Login here :</h1>
<input type="password" name="password" placeholder="Password"><input type="submit" name="" value="Login">
</form>
</div>
<h1>Or Register <a href="/register">here</a></h1>
</div>
{% endblock %}
10 changes: 10 additions & 0 deletions ponder/templates/ponder/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'ponder/base.html' %}

{% block body_block %}
<h2>Register</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Register</button>
</form>
{% endblock %}
1 change: 1 addition & 0 deletions ponder/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
path('success_categorization/<str:pk>', views.success_categorization, name='success_categorization'),
path('forbidden/', views.permission_denied, name='permission_denied'),
path('categorizers/new', views.AddCategorizer, name='categorizers_add'),
path('register/', views.register, name='register'),
]
17 changes: 15 additions & 2 deletions ponder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from django_filters import FilterSet
from django_filters.views import FilterView
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.urls import reverse
from django.utils.html import format_html
from django_tables2 import SingleTableView, SingleTableMixin

from ponder.forms import CategorizationForm, CategorizerForm
from ponder.forms import CategorizationForm, CategorizerForm, UserRegistrationForm
from .models import Categorization, User, BugFix, Categorizer, CommitDetail, Commit, ProblemCategory, ProblemCause, \
ProblemFix, ProblemSymptom
from .tables import Categorizations_FilterTable, BugFixes_FilterTable, BugFixesTable, CommitDetailsTable, CommitsTable
Expand Down Expand Up @@ -41,6 +41,19 @@ def index(request):
context = {'projects': parts, 'groups': groups}
return render(request, 'ponder/index.html', context)

def register(request):
if request.method == 'POST':
form = UserRegistrationForm(request.POST)
if form.is_valid():
new_user = form.save(commit=False)
new_user.set_password(form.cleaned_data['password'])
new_user.save()
login(request, new_user)
return redirect('index')
else:
form = UserRegistrationForm()
return render(request, 'ponder/register.html', {'form': form})

@login_required
def special(request):
return HttpResponse("You are logged in")
Expand Down

0 comments on commit fb87177

Please sign in to comment.