Пример #1
0
def login():
    loginform = LoginForm()
    if request.method == 'POST' and loginform.validate():
        name = loginform.name.data
        phone = loginform.phone.data
        logged_user = User.query.filter(User.name == name).first()
        if logged_user and check_password_hash(logged_user.phone, phone):
            flash(f"Successfully logged in {loginform.name.data}!", 'success')
            login_user(logged_user)
            print(current_user.name)
        else:
            flash(f'Name or Phone do not match. Please check again', 'danger')
        print(name, phone)
        return redirect(url_for('index'))
    return render_template('login.html', title='Login', form=loginform)
Пример #2
0
def view_login(request):
    error = False
    login_form = LoginForm()

    if request.user.is_authenticated():
        return redirect(reverse(view_lists_contacts), locals())

    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data["username"]
            password = login_form.cleaned_data["password"]
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return redirect(reverse(view_lists_contacts))
            else:
                error = True
    return render(request, URL_RENDER['view_login'], locals())
Пример #3
0
def view_login(request):
    error = False
    login_form = LoginForm()

    if request.user.is_authenticated():
        return redirect(reverse(view_lists_contacts), locals())

    if request.method == "POST":
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            username = login_form.cleaned_data["username"]
            password = login_form.cleaned_data["password"]
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return redirect(reverse(view_lists_contacts))
            else:
                error = True
    return render(request, URL_RENDER['view_login'], locals())
Пример #4
0
 def test_login_form(self):
     form_data = {'username': self.user.username, 'password': '******'}
     form = LoginForm(data=form_data)
     self.assertEqual(form.is_valid(), True)