Пример #1
0
def user_register(request):
    # Preverimo, če je metoda zahtevka POST in obdelamo form za registracijo
    if request.method == "POST":
        form = RegisterForm(request.POST)

        if form.is_valid():
            username = form.cleaned_data["username"]
            password1 = form.cleaned_data["password1"]
            password2 = form.cleaned_data["password2"]
            email = form.cleaned_data["email"]

            if password1 == password2:
                if len(password1) > 6:
                    user = User.objects.create_user(username, email, password1)
                    user.save()
                    logger.info("User " + str(user) + " successfully registered")
                else:
                    messages.error(request, "Password has to be longer than 6 characters")
                    logger.error("Password has to be longer than 6 characters")
            else:
                messages.error(request, "Passwords do not match!")
                logger.error("Passwords to not match")
        else:
            logger.error("Not a valid form")
            request.session["register_data"] = request.POST
    return HttpResponseRedirect("/")
Пример #2
0
def home(request):
    # Check if user has submitted login/register forms to render any errors
    register_data = request.session.pop('register_data', None)
    login_data = request.session.pop('login_data', None)

    latest_questions = Question.objects.order_by("-date_published")[:5]
    hot_questions = Question.objects.filter(
            date_published__gte=datetime.datetime.today() - datetime.timedelta(hours=5), votes__gte=2).order_by(
            "-votes")
    no_answers_questions = Question.objects.filter(answer__isnull=True)[:5]

    login_form = LoginForm(login_data)
    login_form.is_valid()
    register_form = RegisterForm(register_data)
    register_form.is_valid()

    return render(request, "nullpointer/index.html",
                  {"latest_questions": latest_questions, "hot_questions": hot_questions,
                   "no_answers_questions": no_answers_questions,
                   "login_form": login_form,
                   "register_form": register_form})