示例#1
0
def register(request):
    if request.user.is_authenticated():
        logout(request)
    if request.method == 'POST':
        form = PeopleForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['password']!=form.cleaned_data['password2']:
                form.errors.update({'password2':
                    _('You did not give the same password.')})
            else:
                try:
                    people = form.save()
                    user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password'])
                    login(request, user)
                    return success(request, _('Registration'),
                        _('You have successfully registered and you have been '
                            'logged in.'))
                except IntegrityError:
                    form.errors.update({'username':
                        _('This username already exists. Please pick another.'
                            )})
    else:
        form = PeopleForm()
    c = RequestContext(request, {
        'form': form,
        })
    return render_to_response('wididitserver/registration_form.html', c)
示例#2
0
 def update(self, request, userid):
     people = get_people(userid)
     userid = people.userid()
     if not people.is_local():
         return rc.BAD_REQUEST
     if not people.can_edit(request.user):
         return rc.FORBIDDEN
     form = PeopleForm(request.PUT, instance=people)
     if not form.is_valid():
         return rc.BAD_REQUEST
     if userid != people.userid():
         # people.userid() got a new value because of PeopleForm(instance=).
         # We shouldn't allow that!
         return rc.FORBIDDEN
     people = form.save()
     people.save()
     return rc.ALL_OK