Пример #1
0
def register(request):
    args = {}
    args.update(csrf(request))
    args['form'] = UserCreationForm()
    args['top10_facilities'] = best_facilities()
    args['latest_comments'] = Comment.objects.order_by('date').reverse()[:8]
    if request.POST:
        newuser_form = UserCreationForm(request.POST)
        if newuser_form.is_valid():
            newuser_form.save()
            newuser = auth.authenticate(username=newuser_form.cleaned_data['username'], password=newuser_form.cleaned_data['password2'])
            auth.login(request, newuser)
            return redirect('/')
        else:
            args['form'] = newuser_form
    return render_to_response('register.html', args)
Пример #2
0
def login(request):
    args = dict()
    args['top10_facilities'] = best_facilities()
    args['latest_comments'] = Comment.objects.order_by('date').reverse()[:8]
    args.update(csrf(request))
    if request.POST:
        username = request.POST.get('username', '')
        password = request.POST.get('password', '')
        user = auth.authenticate(username=username, password=password)
        if user is not None:
            auth.login(request, user)
            return redirect('/')
        else:
            args['login_error'] = "Ви увели невірне ім'я користувача чи невірний пароль"
            return render_to_response('login.html', args)
    else:
        return render_to_response('login.html', args)