Example #1
0
def login_view(request):
    # POST request handling
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user_creds = form.cleaned_data
            user = authenticate(request,
                                username=user_creds['username'],
                                password=user_creds['password'])

            if user:
                login(request, user)
                if request.GET.get('next'):
                    redirect_path = request.GET['next']
                    return HttpResponseRedirect(redirect_path)
                return HttpResponseRedirect(reverse('home'))

    # GET request handling
    form = LoginForm()
    return render(request, 'form.html', {
        'title': 'Log In',
        'button_value': 'Log In',
        'form': form,
        'message': True
    })
Example #2
0
def login_view(request):
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data.get('username'),
                                password=data.get('password'))
            if user:
                login(request, user)
                return HttpResponseRedirect(
                    request.GET.get('next', reverse("homepage")))

    form = LoginForm()
    return render(request, "basic.html", {"form": form})
    def post(self, request):
        form = LoginForm(request.POST)

        if not form.is_valid():
            return render(request, 'custom_user/login.html', {'form': form})

        username = form.cleaned_data['name']
        password = form.cleaned_data['password']

        user = authenticate(request, username=username, password=password)

        if user is not None:
            login(request, user)
            return HttpResponseRedirect(reverse('games'))

        messages.add_message(request, messages.INFO, 'Credentials are invalid')
        return render(request, 'custom_user/login.html', {'form': form})
Example #4
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data.get("username"),
                                password=data.get("password"))
        if user:
            login(request, user)
            return HttpResponseRedirect(
                request.GET.get('next', reverse('homepage')))

    form = LoginForm()
    return render(request, 'generic_form.html', {
        'form': form,
        'user_string': AUTH_USER_MODEL
    })
Example #5
0
    def post(self, request):
        username = ""
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data

            try:
                username = CustomUser.objects.get(
                    library_card_number=int(data['identification'])).username
            except Exception:
                try:
                    username = CustomUser.objects.get(
                        email=data['identification']).username
                except Exception:
                    username = data['identification']
            finally:
                current_user = authenticate(username=username,
                                            password=data['password'])

            if current_user:
                login(request, current_user)
                return HttpResponseRedirect(
                    request.GET.get('next', reverse('home')))
            else:
                print(username)
                render(
                    request, self.html, {
                        "form":
                        form,
                        "message_before":
                        """Unable to authorize.
                                    Please check your information and
                                    try again."""
                    })
        return render(
            request, self.html, {
                "form":
                form,
                "message_before":
                """Unable to authorize.
                                    Please check your information and
                                    try again."""
            })
Example #6
0
def loginView(request):
    html = "portfolio/general_form.html"
    message_after = ""
    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            user = authenticate(request,
                                username=data["username"],
                                password=data["password"])
            if user is not None:
                login(request, user)
                return HttpResponseRedirect(
                    request.GET.get("next", reverse("home")))
            else:
                message_after = """Credentials supplied do not match our records.
                   Please try again."""
    form = LoginForm()
    return render(request, html, {
        "form": form,
        "message_after": message_after
    })
 def get(self, request):
     return render(request, 'custom_user/login.html', {'form': LoginForm()})
Example #8
0
 def get(self, request):
     form = LoginForm()
     return render(request, self.html, {"form": form})