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')
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())
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)
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))
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)
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))
def get(self, request): form = LoginForm() return render(request, template_name='quiz/login.html', context={'form': form})