Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 7, 2005 17:37:31

o.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Hard time with authentication


Hello,

I'm quite perfectionist and I do have a deadline for my project !

But authentication is a little bit hard and not so well documented.

Here is my view (see comments please):

class UserRegManipulator(formfields.Manipulator):
def __init__(self):
self.fields = (
formfields.TextField(field_name="username",
validator_list=, length=30, maxlength=200,
is_required=True),
formfields.EmailField(field_name="email",
is_required=True),
formfields.PasswordField(field_name="password", length=10,
is_required=True),
)
def userNotExists(self, field_data, all_data):
try:
users.get_object(username__exact=field_data)
except:
pass
else:
raise validators.ValidationError("User already exists.")

def user_reg(request):
manipulator = UserRegManipulator()

if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
new_user = users.create_user(new_data,
new_data, new_data)
# SO FAR SO GOOD
# BUT: HOW TO AUTMAGICALLY LOG THIS NEWLY CREATED USER
WHILE REDIRECTING HIM TO THE NEXT FORM TO COMPLETE ?
return HttpResponseRedirect("/contact_reg/")
else:
errors = new_data = {}

form = formfields.FormWrapper(manipulator, new_data, errors)
return render_to_response('contact/user_registration_form',
{'form': form})
# THIS IS OK


def login(request):
manipulator = AuthenticationForm(request)
if request.POST:
errors = manipulator.get_validation_errors(request.POST)
if not errors:
request.session =
manipulator.get_user_id()
request.session.delete_test_cookie()
#HERE I WOULD LIKE TO REDIRECT TO THE SAME PAGE INSTEAD OF
THIS HARDCODED ONE:
return HttpResponseRedirect('/events/')
else:
errors = {}
#SAME AS ABOVE COMMENT
return HttpResponseRedirect('/events/')

Here is my base template:
{% load i18n %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
</head>

<body>
{% block login %}
{% if user.is_anonymous %}
<p>Welcome. Please log in:
<form action="/login/" method="post">
<label for="id_username">{% trans 'Username:' %}</label> <input
type="text" name="username" id="id_username" />
<label for="id_password">{% trans 'Password:' %}</label> <input
type="password" name="password" id="id_password" />
<input type="submit" value="{% trans 'Log in' %}" />
</form>
or <a href="/user_reg/">register<a>.</p>
{% else %}
<p>Welcome, {{ user.username }}. <a href="/logout/">Logout</a></p>
{% endif %}
{% endblock %}
<div id="content">
{% block content %}{% endblock %}
</div>
</body>

Thanks for your help,

Olivier.

Offline

Board footer

Moderator control

Enjoy the 27th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support