Example #1
0
def login_view(request):
    if request.method == 'GET':
        goto = request.GET.get("next", "home")
    else:
        goto = "home"

    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = LoginForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            username = request.POST['user_name']
            password = request.POST['password']
            goto = request.POST['goto_f']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
            else:
                return render(request, 'interface/error_page.html', {"error_m": "Invalid user name or/and password"})

            user_folder = os.path.join(settings.MEDIA_ROOT, str(request.user.id))
            if not os.path.exists(user_folder):
                os.makedirs(user_folder)

            return redirect(goto)

    # if a GET (or any other method) we'll create a blank form
    else:
        form = LoginForm()
    return render(request, 'interface/login.html', {'form': form, "goto": goto})
Example #2
0
def login_view(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.data['username'],
                                password=form.data['password'])
            if user and user.username in settings.ACS_USER_WHITELIST:
                login(request, user)
                return redirect(homepage)
    else:
        form = LoginForm()

    return render(request, 'interface/login.html', {'form': form})
Example #3
0
def log_in(request):
    erro = False
    msg = 'Informe seu usuário e senha'
    form = LoginForm()
    if request.POST:
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            if user:
                login(request, user)
                if request.GET.get(REDIRECT_FIELD_NAME):
                    return redirect(request.GET.get(REDIRECT_FIELD_NAME))
                else:
                    return redirect("/")
            erro = True
            msg = 'Usuário ou senha inválido. Tente novamente.'
    return render(request, "interface/login.html", locals())
Example #4
0
def login_view(request):
    if request.user.is_authenticated:
        return redirect(homepage)

    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.data["username"]
            password = form.data["password"]

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

            if not user:
                log.info("Login failure for %s", username)
            else:
                login(request, user)
                return redirect(homepage)
    else:
        form = LoginForm()

    return render(request, "interface/login.html", {"form": form})
Example #5
0
def login_view(request):
    if request.user.is_authenticated:
        return redirect(homepage)

    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.data['username']
            password = form.data['password']

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

            if not user:
                log.info(f"Login failure for {username}")
            else:
                login(request, user)
                return redirect(homepage)
    else:
        form = LoginForm()

    return render(request, 'interface/login.html', {'form': form})
        def link_to_login():
            Log.save_to_log('[Interface.py] Login')

            form = LoginForm()
            if form.validate_on_submit():
                user = self.dataHandler.checkEmailPasswordLogin(
                    form.email.data, form.password.data)
                if user:
                    flash(f'You are now logged in: {user["email"]}!',
                          'success')

                    session['logged_in'] = True
                    session['user'] = user

                    return render_template('dashboard.html')

                else:
                    flash(
                        'Login unsuccessful. Please check username and password.',
                        'danger')
            return render_template('login.html', title='Login', form=form)