예제 #1
0
파일: views.py 프로젝트: praekelt/ummeli
def mobi_register(request):
    if request.method == "POST":
        post_data = process_post_data_username(request.POST)
        username = post_data["username"]
        form = MobiUserCreationForm(post_data)
        if form.is_valid():
            form.save()
            # auto-login user
            password = request.POST.get("password1")
            user = authenticate(username=username, password=password)
            auth_login(request, user)
            request.session[settings.UMMELI_PIN_SESSION_KEY] = True
            return redirect(reverse("home"))
    else:
        form = MobiUserCreationForm()

    return render(request, "register.html", {"form": form})
예제 #2
0
파일: views.py 프로젝트: praekelt/ummeli
def login(
    request,
    template_name="login.html",
    redirect_field_name=REDIRECT_FIELD_NAME,
    authentication_form=AuthenticationForm,
    current_app=None,
    extra_context=None,
):
    """
    Displays the login form and handles the login action.
    """
    redirect_to = request.REQUEST.get(redirect_field_name, "")

    if request.method == "POST":
        form = authentication_form(data=process_post_data_username(request.POST))
        if form.is_valid():
            netloc = urlparse.urlparse(redirect_to)[1]

            # Use default setting if redirect_to is empty
            if not redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Security check -- don't allow redirection to a different
            # host.
            elif netloc and netloc != request.get_host():
                redirect_to = settings.LOGIN_REDIRECT_URL

            # setting the PIN for this session
            request.session[settings.UMMELI_PIN_SESSION_KEY] = True

            # Okay, security checks complete. Log the user in.
            auth_login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

            return redirect(redirect_to)
    else:
        form = authentication_form(request)

    request.session.set_test_cookie()

    return render(request, template_name, {"form": form, redirect_field_name: redirect_to})
예제 #3
0
파일: views.py 프로젝트: praekelt/ummeli
def forgot_password_view(request):
    if request.method == "POST":
        post_data = process_post_data_username(request.POST)
        form = ForgotPasswordForm(post_data)

        if form.is_valid():
            username = form.cleaned_data["username"]
            new_password = generate_password(chars=string.digits)

            send_password_reset.delay(username, new_password)

            user = User.objects.get(username=username)
            user.set_password(new_password)
            user.save()
            messages.success(request, "An SMS has been sent with your new PIN")
            return redirect(reverse("login"))
    else:
        form = ForgotPasswordForm()

    return render(request, "forgot_password.html", {"form": form})