Esempio n. 1
0
    def post(self, request):
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(request,
                                username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            if ((user is not None) and (user.is_superuser)):
                login(request, user)
                return redirect('quiz:admin_home')
            elif user is not None:
                login(request, user)
                return redirect('quiz:list_courses')

        return redirect('quiz:login_page')
Esempio n. 2
0
def login_page_Admin(request):
    if request.method == "POST":
        form9 = LoginForm(data=request.POST or None)
        if form9.is_valid():
            username = form9.cleaned_data['username']
            password = form9.cleaned_data['password']
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('quiz:adminpage')
        else:
            print(form9.errors)
    else:
        form9 = LoginForm(data=request.POST or None)

    return render(request, 'registration/LoginAdmin.html', locals())
Esempio n. 3
0
def login():
    global count
    count = 0
    if current_user.is_authenticated:
        return redirect(
            url_for('home')
        )  #if user is logged in then the login button will return to homepage
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first(
        )  # check if username exist in db
        if user and bcrypt.check_password_hash(
                user.password,
                form.password.data):  # check if username and password match
            login_user(user, remember=form.remember.data)  # login the user
            return redirect(url_for('account'))
        else:
            flash(f'Login Unsuccessful. Please try again!', 'danger')
    return render_template('login.html', title='Login', form=form)
Esempio n. 4
0
def login():
    if (current_user.is_authenticated):
        return (redirect(url_for('playquiz')))
    form = LoginForm()
    if (form.validate_on_submit()):
        user = Users.query.filter_by(username=form.username.data).first()
        if (user and bcrypt.check_password_hash(user.password,
                                                form.password.data)):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            if (next_page):
                return (redirect(next_page))
            return (redirect(url_for('home')))
        else:
            return (render_template("login.html",
                                    title="Login",
                                    form=form,
                                    unsuccessful=True))
    return (render_template("login.html",
                            title="Login",
                            form=form,
                            unsuccessful=False))
Esempio n. 5
0
def home():
    adminCheck()

    if current_user.is_authenticated:
        return redirect(url_for("dashboard"))

    form = LoginForm()

    if form.validate_on_submit():

        user = UserInfo.query.filter_by(username=form.username.data).first()

        if user and checkPasswordHash(user.password, form.password.data):
            login_user(user)
            loginPage = request.args.get("next")

            if loginPage:
                return redirect(loginPage)
            else:
                return redirect(url_for("dashboard"))
        else:
            flash("Неверные данные", "danger")

    return render_template('home.html', form=form)
Esempio n. 6
0
def register():
    if (current_user.is_authenticated):
        return (redirect(url_for('account')))
    form = RegistrationForm()
    if (form.validate_on_submit()):
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        new_user = Users(name=form.name.data,
                         username=form.username.data,
                         email=form.email.data,
                         password=hashed_password)
        db.session.add(new_user)
        db.session.commit()
        return (render_template("login.html",
                                title="Login",
                                form=LoginForm(),
                                unsuccessful=False))
    return (render_template("register.html", title="Register", form=form))
Esempio n. 7
0
 def get(self, request):
     form = LoginForm()
     return render(request,
                   template_name='quiz/login.html',
                   context={'form': form})