users can now register but still there is no concept of activation e-mail .
--- a/feedback.html Fri Apr 09 13:21:46 2010 +0530
+++ b/feedback.html Fri Apr 09 15:35:40 2010 +0530
@@ -1,12 +1,7 @@
-<html>
-<head>
-<title>
-</title>
-</head>
-<body>
+{% extends "base.html" %}
+{% block content %}
<form action="" method="post">
{{ form.as_p }}
<input type="submit" value="submit">
</form>
-</body>
-</html>
+{% endblock %}
--- a/list_feedbacks.html Fri Apr 09 13:21:46 2010 +0530
+++ b/list_feedbacks.html Fri Apr 09 15:35:40 2010 +0530
@@ -1,11 +1,7 @@
-<html>
-<head>
-<title>
-</title>
-</head>
+{% extends "base.html" %}
+{% block content %}
{% for feed in feeds %}
{{ feed }}<br />
{% endfor %}
<a href="/feedback/submit">submit another one here</a>
-</body>
-</html>
+{% endblock %}
--- a/login.html Fri Apr 09 13:21:46 2010 +0530
+++ b/login.html Fri Apr 09 15:35:40 2010 +0530
@@ -1,12 +1,7 @@
-<html>
-<head>
-<title>
-</title>
-</head>
-<body>
+{% extends "base.html" %}
+{% block content %}
<form action="" method="post">
{{ form.as_p }}
<input type="submit" value="Login">
</form>
-</body>
-</html>
+{% endblock %}
--- a/reg/events.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/events.py Fri Apr 09 15:35:40 2010 +0530
@@ -4,20 +4,38 @@
from django.db import IntegrityError
-from workshop.reg.models import Event
+from workshop.reg.models import Profile, Event
from workshop.reg.utils import gen_key
-def create_user(email, password, firstname="", lastname=""):
+def create_user(email, password, firstname="", lastname="", gender="M", profession="S", affiliated_to="", interests="" ):
""" create a user with random username and set the password.
"""
- username = ('%s %s'%(firstname, lastname)).title().strip()
+ while True:
+ try:
+ username = gen_key(8)
+ user = User.objects.get(username=username)
+ except User.DoesNotExist:
+ break
new_user = User.objects.create_user(username, email, password)
new_user.firstname = firstname
new_user.lastname = lastname
new_user.is_active = False
new_user.save()
- return new_user
+
+ new_profile = Profile(user=new_user)
+ new_profile.gender = gender
+ new_profile.profession = profession
+ new_profile.affiliated_to = affiliated_to
+ new_profile.interests = interests
+
+ while True:
+ try:
+ new_profile.activation_key = gen_key(30)
+ new_profile.save()
+ return new_user
+ except IntegrityError:
+ pass
def create_event(title, desc, start_date, stop_date, created_by=None):
""" make an event and save it.
@@ -32,10 +50,14 @@
if created_by:
new_event.organizers.add(created_by)
- new_event.key = gen_key()
while True:
try:
+ new_event.key = gen_key(10)
new_event.save()
return new_event
except IntegrityError:
- new_event.key = gen_key()
+ pass
+'''
+def mail_user(email):
+ """ get the user
+'''
--- a/reg/forms.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/forms.py Fri Apr 09 15:35:40 2010 +0530
@@ -1,8 +1,12 @@
+import string
+
from django.contrib.auth.models import User
from django import forms
from django.contrib.auth import authenticate
+from workshop.reg.models import Profile
+
class LoginForm(forms.Form):
""" a form to handle login.
"""
@@ -26,3 +30,39 @@
raise forms.ValidationError("Incorrect e-mail or password")
return email
+class RegisterForm(forms.ModelForm):
+ """ add the fields email and password
+ and then generate form using profile model.
+ """
+
+ email = forms.EmailField()
+ password = forms.CharField(widget=forms.PasswordInput, help_text="Choose a good password which 8 to 30 chars long")
+ confirm_password = forms.CharField(widget=forms.PasswordInput)
+
+ first_name = forms.CharField(required=True)
+ last_name = forms.CharField()
+
+ class Meta:
+ model = Profile
+ fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
+
+ def clean_email(self):
+ email = self.cleaned_data['email']
+ try:
+ User.objects.get(email__iexact=email)
+ raise forms.ValidationError("An account already exists with this email.\
+ Click on forgot password if you have forgotten your password")
+ except User.DoesNotExist:
+ return email
+
+ def clean_password(self):
+ password = self.cleaned_data['password']
+
+ if password.strip(string.ascii_letters+string.punctuation+string.digits):
+ raise forms.ValidationError("Only alphabets, digits and punctuation symbols are allowed in password")
+
+ if not 8 <= len(password) <= 30:
+ raise forms.ValidationError("Password must be atleast 8 characters and at most 30 characters")
+
+ if not password == self.data['confirm_password']:
+ raise forms.ValidationError("Passwords do not match")
--- a/reg/models.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/models.py Fri Apr 09 15:35:40 2010 +0530
@@ -13,8 +13,6 @@
""" A model to hold extra information about the user.
"""
- key = models.CharField(max_length=10, unique=True)
-
user = models.ForeignKey(User, unique=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
profession = models.CharField(max_length=1, choices=PROFESSION_CHOICES)
@@ -39,3 +37,7 @@
feedback_open = models.BooleanField()
quiz_open = models.BooleanField()
+
+ def __unicode__(self):
+
+ return self.title
--- a/reg/site/urls.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/site/urls.py Fri Apr 09 15:35:40 2010 +0530
@@ -6,4 +6,5 @@
('^$', reg_views.homepage),
('^login/$', reg_views.user_login),
('^logout/$', reg_views.user_logout),
+ ('^register/$', reg_views.user_register),
)
--- a/reg/utils.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/utils.py Fri Apr 09 15:35:40 2010 +0530
@@ -1,6 +1,6 @@
import string
import random
-def gen_key():
+def gen_key(no_of_chars):
allowed_chars = string.digits+string.uppercase
- return ''.join([random.choice(allowed_chars) for i in range(10)])
+ return ''.join([random.choice(allowed_chars) for i in range(no_of_chars)])
--- a/reg/views.py Fri Apr 09 13:21:46 2010 +0530
+++ b/reg/views.py Fri Apr 09 15:35:40 2010 +0530
@@ -4,7 +4,9 @@
from django.shortcuts import render_to_response, redirect
+from workshop.reg.models import Event
from workshop.reg import forms as reg_forms
+from workshop.reg import events as reg_events
from django.http import HttpResponse
@@ -16,12 +18,8 @@
user = request.user
- if not user.is_authenticated():
- return HttpResponse('not logged in<br><a href="/reg/login">login</a>')
- elif not user.is_active:
- return HttpResponse('not active<br /><a href="/reg/logout">logout</a>')
- else:
- return HttpResponse('you are ogey<br /><a href="/reg/logout">logout</a>')
+ events = Event.objects.all()[:10]
+
def user_login(request):
""" get the user object from e-mail and then check for password.
@@ -54,4 +52,26 @@
logout(request)
return redirect('/reg')
+def user_register(request):
+ """ take the credentials like name, college and gender here itself.
+ """
+ if request.method == "POST":
+ form = reg_forms.RegisterForm(request.POST)
+ if form.is_valid():
+ data = form.cleaned_data
+ reg_events.create_user(email=data['email'],
+ password=data['password'],
+ firstname=data['first_name'],
+ lastname=data['last_name'],
+ gender=data['gender'],
+ profession=data['profession'],
+ affiliated_to=data['affiliated_to'],
+ interests=data['interests']
+ )
+ return render_to_response('account_created.html')
+ else:
+ return render_to_response('register.html', {'form':form})
+ else:
+ form = reg_forms.RegisterForm()
+ return render_to_response('register.html', {'form':form})