Commits

Alexandre Beaulieu committed 273aff0

Added login and register forms. Added relevant views and templates.

Comments (0)

Files changed (11)

achievements/views.py

         form = ImportForm(request.POST, request.FILES)
         if form.is_valid():
             models = utils.csv2model(request.FILES['file'], Achievement, {'map': ['title', 'desc']}, auto_save=True)
-            return redirect('import_success', count=len(models), achievements=models)
+            return redirect('import_success', permanent=True, count=len(models), achievements=models)
     else:
         form = ImportForm()
     return render(request, 'achievements/import.html', {'form': form})
 
 class RegisterForm(forms.Form):
     username       = forms.CharField(max_length=32)
-    password       = forms.PasswordInput()
-    password_check = forms.PasswordInput()
+    password       = forms.CharField(widget=forms.PasswordInput())
+    password_check = forms.CharField(widget=forms.PasswordInput())

hard/templates/base.html

         <header>
           <h1>H.A.R.D.</h1>
         </header>
+        
       </div>
       <div id="content">
+      <span style="color: white;font-size: 1em;">That's what she said</span>
         <h2>{% block view_title %}View Title{% endblock %}</h2>
       {% block content %}{% endblock %}
       </div>

hard/templates/hard/profile.html

Empty file added.

hard/templates/hard/register.html

+{% extends 'base.html' %}
+{% load url from future %}
+{% block title %}Enrollment Form{% endblock %}{% block view_title %}Enroll{% endblock %}
+{% block content %}
+      <p>
+        <form action="{% url 'hard.views.register' %}" method="post">{% csrf_token %}
+        <p><label for="username">Username:</label>
+                <input id="username" type="text" name="username" maxlength="32"/></p>
+        <p><label for="password">Password:</label>
+                <input id="password" type="password" name="password"/></p>
+        <p><label for="password_check">Confirm Password:</label>
+                <input id="password_check" type="password" name="password_check"/></p>
+        <input type="submit" value="Submit"/>
+        </form>         
+      </p>
+{% endblock %}

hard/templates/hard/register_success.html

+{% extends 'base.html' %}
+{% block title %}Successfully Enrolled{% endblock %}{% block view_title %}Welcome to the ranks, {{ username }}{% endblock %}
+{% block content %}
+      
+      <p>
+        You have been successfully enrolled in project H.A.R.D. Bring honor to
+        your own name and show your fellow developers how HARD you really are.
+      </p>
+      
+      <p>
+        <a href="/" title="Home page">Click here</a> to get started.
+      </p>
+{% endblock %}

hard/templates/registration/login.html

+{% extends 'base.html' %}
+{% load url from future %}
+{% block title %}Login{% endblock %}{% block view_title %}Login{% endblock %}
+{% block content %}
+            {% if form.errors %}
+            <p>Your username and password didn't match. Please try again.</p>
+            {% endif %}
+
+            <form method="post" action="{% url 'django.contrib.auth.views.login' %}">
+            {% csrf_token %}
+            <table>
+            <tr>
+                <td>{{ form.username.label_tag }}</td>
+                <td>{{ form.username }}</td>
+            </tr>
+            <tr>
+                <td>{{ form.password.label_tag }}</td>
+                <td>{{ form.password }}</td>
+            </tr>
+            </table>
+
+            <input type="submit" value="Login" />
+            <input type="hidden" name="next" value="{{ next }}" />
+            </form>
+{% endblock %}
 from django.conf.urls.defaults import patterns, include, url
 
 urlpatterns = patterns('',
-    url(r'^$', 'hard.views.index', name='global index'),
+    url(r'^$', 'hard.views.profile', name='profile'),
+    url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
+    url(r'^register/$', 'hard.views.register', name='register'),
+    url(r'^register/success/$', 'hard.views.register_success', name='register_success'),
 )
-from django.http import HttpResponse
-from django.shortcuts import render
+from django.shortcuts import render, redirect
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.models import User
+from hard.forms import RegisterForm
+
+def register(request):
+    if request.method == 'POST':
+        form = RegisterForm(request.POST)
+        if form.is_valid():
+            username = form.cleaned_data['username']
+            password = form.cleaned_data['password']
+            password_check = form.cleaned_data['password_check']
+            if password == password_check:
+                new_user = User(username=username, password=password)
+                new_user.save()
+                return redirect('register_success', permanent=True)
+            return render(request, 'hard/register.html', {'form': form}) # TODO: Error: Passwords don't match!
+    else:
+        form = RegisterForm()
+
+    return render(request, 'hard/register.html', {'form': form})
+
+def logout(request):
+    auth_logout(request)
+    return HttpResponseRedirect('/')
+    
+def register_success(request):
+    return render(request, 'hard/register_success.html')
+
+@login_required    
+def profile(request):
+    return render(request, 'hard/profile.html')
     "django.core.context_processors.i18n",
     "django.core.context_processors.media",
     "django.core.context_processors.static",
-    "django.core.context_processors.tz",
     "django.contrib.messages.context_processors.messages",
     'HARD.hard.context_processors.current_date_processor',
 ) 
 
+LOGIN_URL = '/login'
+LOGIN_REDIRECT_URL = '/'
+AUTHENTICATION_BACKENDS = (
+#    'social_auth.backends.google.GoogleBackend', # Uncomment if we decide to support oAuth.
+    'django.contrib.auth.backends.ModelBackend',
+)
+
 # A sample logging configuration. The only tangible logging
 # performed by this configuration is to send an email to
 # the site admins on every HTTP 500 error.
 admin.autodiscover()
 
 urlpatterns = patterns('',
-    url(r'^$', include('HARD.achievements.urls'), name='index'), # TODO: This should point to the Honors Profile Page
+    url(r'^', include('HARD.hard.urls'), name='index'),
     url(r'^achievements/', include('HARD.achievements.urls'), name='achievements'),
     url(r'^admin/', include(admin.site.urls)),
 )