def login(request): # User has already logged in, so redirect to the dashboard if request.session.get('user_id') is not None: return HttpResponseRedirect('/todo/') if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: user = User.objects.get(username=username, password=password) request.session['user_id'] = user.id request.session.set_expiry(0); return HttpResponseRedirect('/todo/') except User.DoesNotExist: error_msg = 'Incorrect username or password' else: error_msg = 'Invalid login' return render(request, 'todo/login.html', { 'errorMsg': error_msg, 'loginForm': form }) else: form = LoginForm() return render(request, 'todo/login.html', {'loginForm': form})
def login(): # if current_user.is_authenticated: # return redirect(url_for('dashboard')) if session.get('username', None): return redirect(url_for('dashboard')) form = LoginForm() if form.validate_on_submit(): # check if the entered email (from the form) exists in the database user = Users.query.filter_by(email=form.email.data).first() if user and bcrypt.check_password_hash(user.password, form.password.data): # login_user(user) session['username'] = user.username flash('Login successful', 'success') return redirect(url_for('dashboard')) else: flash('Login Unsuccessful: Invalid email and/or password!', 'danger') return render_template('login.html', title="Login", form=form, signup=True) return render_template('login.html', title="Login", login=True, form=form, signup=False)
def login_view(request): if not request.user.is_authenticated: if request.POST: login_form = LoginForm(request.POST) if login_form.is_valid(): if login_form.user.profile.is_active: auth_login(request, login_form.user) return redirect( reverse("todo:profile", args=(login_form.user.profile.id, ))) else: return HttpResponse( "Hi %s, Your Login Request is pending for Approval" % login_form.user.username.title()) else: login_form = LoginForm() return render(request, "todo/login.html", { "form": login_form, "error": "" }) else: return redirect( reverse("todo:profile", args=(request.user.profile.id, )))
def index(): if current_user.is_authenticated: return redirect(url_for('home')) login_form = LoginForm() register_form = RegistrationForm() if login_form.validate_on_submit(): user = User.query.filter_by(email=login_form.email.data).first() if user and bcrypt.check_password_hash(user.password, login_form.password.data): login_user(user, remember=login_form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('home')) else: flash('Login Unsuccessful. Please check email and password', 'danger') if register_form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(register_form.password.data).decode('utf-8') user = User(username=register_form.username.data, email=register_form.email.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('index')) return render_template('index.html', title='Please login or register!', register_form=register_form, login_form=login_form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if request.method == 'GET': return render_template('login.html', title='Login', form=form) if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: if bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect( url_for('about')) msg = "Email or Password incorrect" return render_template("login.html", title="Login", form=form, msg=msg) msg = "User doesn't exists" return render_template("login.html", title="Login", form=form, msg=msg) msg = "Form is not valid,please check the entries!" return render_template("login.html", title="Login", form=form, msg=msg)
def login_view(request): if request.user.is_authenticated(): return HttpResponseRedirect("/todo/list/") if request.method == 'POST': print 'hi' form = LoginForm(request.POST) print form if form.is_valid(): print form.errors email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = auth.authenticate(username=email, password=password) if user is not None and user.is_active: auth.login(request, user) return HttpResponseRedirect("/todo/list/") else: return HttpResponseRedirect("/todo/login/") else: return render_to_response('login.html', locals(), context_instance=RequestContext(request)) else: form = LoginForm(request.POST) return render_to_response('login.html', locals(), context_instance=RequestContext(request))
def login(): title = 'Login' form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by( username=form.username.data).first() or User.query.filter_by( email=form.username.data).first() if user is not None and user.check_password(form.password.data): login_user(user, form.remember_me.data) flash(f'Successfully Logged in as {current_user.username}!') return redirect(request.args.get('next') or url_for('index')) flash('Invalid username or password') return render_template('login.html', title=title, form=form)
def signin(request): if request.method == "POST": form = LoginForm(request.POST) username = request.POST['username'] password = request.POST['password'] user = authenticate(username = username, password = password) if user is not None: login(request, user) return redirect('main') else: return HttpResponse("<script>alert('로그인 실패. 다시 시도해주세요.');history.back();</script>") else: form = LoginForm() return render(request, 'registration/login.html', {'form': form})
def login(): if current_user.is_authenticated: return redirect(url_for('home')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email = form.email.data).first() if user and str(form.password.data) == str(user.password): login_user(user, remember = form.remember.data) next_page = request.args.get('next') return redirect(next_page) if next_page else redirect(url_for('home')) else: flash('Login Unsuccessful', 'danger') return render_template('login.html', title='Login', form=form)
def login(): if current_user.is_authenticated: flash("You are already logged in", "warning") return redirect(url_for("landing.index")) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() login_user(user) return redirect(session.get("after_login") or url_for("landing.index")) return render_template("users/login.html", form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if not user or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('login')) login_user(user, remember=form.remember_me.data) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': return redirect(url_for('index')) return redirect(next_page) return render_template('login.html', form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if request.method == 'GET': return render_template("register.html", title='Register', form=form) if form.validate_on_submit(): form = RegistrationForm() username = form.username.data email = form.email.data password = form.password.data hashed_pw = bcrypt.generate_password_hash(password).decode('utf-8') user = User(username=username, email=email, password=hashed_pw) db.session.add(user) db.session.commit() msg = f'Dear, {username} new account is successfully created for you!' form = LoginForm() return render_template("login.html", title="Login", form=form, msg=msg) msg = 'Form is not valid' return render_template('register.html', title='Register', form=form, msg=msg)
def login(): if current_user.is_authenticated: return redirect(url_for("home")) form = LoginForm() if request.method == "POST": print(request.form.get('username')) print(User.query.all()) print(request.form.get("username")) user = User.query.filter_by(email=request.form.get("username")).first() print(user) if user and bcrypt.check_password_hash( user.password, request.form.get("password") ): login_user(user) return redirect(url_for("skills")) # print(next_page) # print(user.todo) return render_template("login.html", form=form)