# HG changeset patch # User nishanth # Date 1271140392 -19800 # Node ID 9354ef8119c6b0ed0630672f9b06a378280a3ab3 # Parent 115860e872381e61c4eeb253ffd40fff8f2c5afc added account_inactive and resend_activationkey functionalities diff -r 115860e87238 -r 9354ef8119c6 reg/events.py --- a/reg/events.py Tue Apr 13 10:50:29 2010 +0530 +++ b/reg/events.py Tue Apr 13 12:03:12 2010 +0530 @@ -37,6 +37,12 @@ except IntegrityError: pass +def send_activation(user): + """ get key from profile and send an email. + """ + + print user.get_profile().activation_key + def create_event(title, description, start_date, stop_date, created_by=None): """ make an event and save it. """ diff -r 115860e87238 -r 9354ef8119c6 reg/site/urls.py --- a/reg/site/urls.py Tue Apr 13 10:50:29 2010 +0530 +++ b/reg/site/urls.py Tue Apr 13 12:03:12 2010 +0530 @@ -7,6 +7,8 @@ (r'^login/$', reg_views.user_login), (r'^logout/$', reg_views.user_logout), (r'^register/$', reg_views.user_register), + (r'^account_created/$', reg_views.account_created), + (r'^send_activation/$', reg_views.send_activation), (r'^profile/view/$', reg_views.view_profile), (r'^profile/edit/$', reg_views.edit_profile), (r'^password_reset/$', reg_views.reset_password), diff -r 115860e87238 -r 9354ef8119c6 reg/views.py --- a/reg/views.py Tue Apr 13 10:50:29 2010 +0530 +++ b/reg/views.py Tue Apr 13 12:03:12 2010 +0530 @@ -1,5 +1,8 @@ from datetime import datetime +from django.http import Http404 +from django.utils.datastructures import MultiValueDictKeyError + from django.contrib.auth.models import User from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required @@ -12,8 +15,6 @@ from workshop.feedback.models import Feedback -from django.http import HttpResponse - def homepage(request): """ see if the user is active. If not, only show the re send activation email link. @@ -40,8 +41,11 @@ username = User.objects.get(email__iexact=email).username user = authenticate(username=username, password=password) - login(request, user) - return redirect('/reg') + if user.is_active: + login(request, user) + return redirect('/reg') + else: + return render_to_response('account_inactive.html', {'user':user, 'email':email}) else: return render_to_response('login.html', {'user':user, 'form':form}) else: @@ -63,22 +67,50 @@ form = reg_forms.RegisterForm(request.POST) if form.is_valid(): data = form.cleaned_data - reg_events.create_user(email=data['email'], - password=data['password'], - first_name=data['first_name'], - last_name=data['last_name'], - gender=data['gender'], - profession=data['profession'], - affiliated_to=data['affiliated_to'], - interests=data['interests'] - ) - return render_to_response('account_created.html') + new_user = reg_events.create_user(email=data['email'], + password=data['password'], + first_name=data['first_name'], + last_name=data['last_name'], + gender=data['gender'], + profession=data['profession'], + affiliated_to=data['affiliated_to'], + interests=data['interests'] + ) + return redirect('/reg/account_created') else: return render_to_response('register.html', {'form':form}) else: form = reg_forms.RegisterForm() return render_to_response('register.html', {'form':form}) +def account_created(request): + """ simply display a page. + """ + + user = request.user + return render_to_response('account_created.html', {'user':user}) + +def send_activation(request): + + try: + email = request.GET['email'] + except MultiValueDictKeyError: + raise Http404 + + try: + user = User.objects.get(email__iexact=email) + except User.DoesNotExist: + raise Http404 + + if user.is_active: + return redirect('/reg') + + profile = user.get_profile() + activation_key = profile.activation_key + reg_events.send_activation(user) + + return render_to_response('sent_activationkey.html', {'user':user}) + def create_event(request): """ see if the user is a staff and only then let him do it. """ @@ -117,7 +149,7 @@ except Event.DoesNotExist: return redirect("/reg") - is_guest = False if user.is_authenticated() else True + is_guest = False if user.is_authenticated() and user.is_active else True is_attendee = True if user in event.attendees.all() else False is_org = True if user in event.organizers.all() else False @@ -274,7 +306,7 @@ """ user = request.user - if user.is_authenticated(): + if user.is_authenticated() and user.is_active: try: event = Event.objects.get(key__iexact=event_key) except Event.DoesNotExist: diff -r 115860e87238 -r 9354ef8119c6 templates/404.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/404.html Tue Apr 13 12:03:12 2010 +0530 @@ -0,0 +1,5 @@ +{% extends "base.html" %} +{% block content %} +The page you requested does not exist. +Click here to return to home page. +{% endblock %} diff -r 115860e87238 -r 9354ef8119c6 templates/account_created.html --- a/templates/account_created.html Tue Apr 13 10:50:29 2010 +0530 +++ b/templates/account_created.html Tue Apr 13 12:03:12 2010 +0530 @@ -1,7 +1,5 @@ {% extends "base.html" %} {% block content %} -The account has been created.
-Click here to activate your account.
-This link will be sent to your email.
+Account has been created and an activation email has been sent to your email address.
click here to go to login page. {% endblock %} diff -r 115860e87238 -r 9354ef8119c6 templates/account_inactive.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/account_inactive.html Tue Apr 13 12:03:12 2010 +0530 @@ -0,0 +1,6 @@ +{% extends "base.html" %} +{% block content %} +Your account is inactive. An activation email has been sent to your email address.
+Click here to resend the activation email.
+click here to go to home page. +{% endblock %} diff -r 115860e87238 -r 9354ef8119c6 templates/sent_activationkey.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/sent_activationkey.html Tue Apr 13 12:03:12 2010 +0530 @@ -0,0 +1,5 @@ +{% extends "base.html" %} +{% block content %} +Activation email has been sent to your email address.
+click here to go to home page. +{% endblock %}