def login(): """Handle login; show form or process results.""" form = LoginForm() openid_form = OpenIDForm() if openid_form.validate_on_submit(): return oid.try_login( openid_form.openid.data, ask_for=['nickname', 'email'], ask_for_optional=['fullname'], ) if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).one() login_user(user, remember=form.remember.data) identity_changed.send(current_app._get_current_object(), identity=Identity(user.id)) flash("You have been logged in.", category="success") return redirect(url_for('blog.home')) openid_errors = oid.fetch_error() if openid_errors: flash(openid_errors, category='danger') return render_template('login.html', form=form, openid_form=openid_form)
def login(): if current_user.is_authenticated: flash('You are already logged in.', 'success') 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 bcrypt.check_password_hash(user.password, form.password.data): login_user(user, remember=form.remember.data) next_page = request.args.get('next') flash('Logged in successful.', 'success') return redirect(next_page) if next_page else redirect( url_for('home')) if user and not bcrypt.check_password_hash(user.password, form.password.data): flash('Login Unsuccessful. Please check your password', 'danger') return redirect(url_for('login')) if not user: flash('Failed!, it seems you are not a member. ', 'danger') return redirect(url_for('register')) else: flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form)
def login(): session['current_path'] = request.path form = LoginForm() if form.validate_on_submit(): customer_in_db = Customer.query.filter( Customer.username == form.username.data).first() employee_in_db = Employee.query.filter( Employee.username == form.username.data).first() if not customer_in_db and not employee_in_db: flash('No user found with username: {}'.format(form.username.data)) return redirect(url_for('login')) elif employee_in_db and not customer_in_db: if (check_password_hash(employee_in_db.password_hash, form.password.data)): # flash('Login success!') session["USERNAME"] = employee_in_db.username return redirect(url_for('employee_f')) else: flash('Incorrect Password') return redirect(url_for('login')) elif customer_in_db and not employee_in_db: if (check_password_hash(customer_in_db.password_hash, form.password.data)): # flash('Login success!') session["USERNAME"] = customer_in_db.username return redirect(url_for('customer_index')) else: flash('Incorrect Password') return redirect(url_for('login')) return render_template('login.html', title='Sign in', form=form, language=language[render_languages()])
def login(request): try: if request.session["username"]: return HttpResponseRedirect("/success/") except: pass if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): try: user = Register.objects.filter( username=form.cleaned_data["username"], password=form.cleaned_data["password"] ) if len(user) == 1: request.session["username"] = user[0].username return HttpResponseRedirect("/success/") else: return HttpResponse("Log In Credential's didn't match!! Please Try Again ") except DoesNotExit: return None else: form = LoginForm() return render(request, "blogapp/login.html", {"form": form})
def login(): if current_user.is_authenticated: return redirect(url_for('index')) form = LoginForm() # If POST request is received if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() # Check if User exists or password is correct if user is None or not user.check_password(form.password.data): # Flash is used to display messages which can be # retrieved in the templates using get_flashed_messages() flash('Invalid Username or Password') return redirect(url_for('login')) # Log in user if credentials are correct login_user(user, remember=form.remember_me.data) # If next query argument is provided in the url, # redirect user to that url next_page = request.args.get('next') # If next query argument is not provided or relative path is not provided # (full url with domain name is provided), redirect to index # Second condition ensures that the redirect stays within the same site as application if not next_page or url_parse(next_page).netloc != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title='Sign In', form=form)
def sign_in_c(): form = LoginForm() if form.validate_on_submit(): user_in_db = Customer.query.filter(Customer.username == form.username.data).first() if not user_in_db: flash("No user found with username: {}") flash('No user found with username: {}'.format(form.username.data)) return redirect(url_for('sign_in')) if (check_password_hash(user_in_db.password_hash, form.password.data)): flash('Login success!') session["USERNAME"] = user_in_db.username return redirect(url_for('My_appointment')) flash('Incorrect Password') return redirect(url_for('index')) return render_template('sign_in.html', title='Sign In', 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 user is None 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 != '': next_page = url_for('index') return redirect(next_page) return render_template('login.html', title=_('Sign In'), form=form)
def login(): form = LoginForm() if form.validate_on_submit(): user_in_db = User.query.filter( User.username == form.username.data).first() if not user_in_db: flash('No user found with username: {}'.format(form.username.data)) return redirect(url_for('login')) if (check_password_hash(user_in_db.password_hash, form.password.data)): flash('Login success!') session["USERNAME"] = user_in_db.username return redirect(url_for('login')) # should go to the logged-in page flash('Incorrect Password') return redirect(url_for('login')) return render_template('login.html', title='Sign In', form=form)
def login(): if current_user.is_authenticated: return redirect(url_for('home')) login = LoginForm() if login.validate_on_submit(): person = user_collection.find_one({'email': login.email.data}) if person and bcrypt.check_password_hash(person['password'], login.password.data): user_obj = User(person['username'], person['email'], person['image']) login_user(user_obj, login.remember.data) next_page = request.args.get('next') if next_page: return redirect(next_page) flash('Welcome to BlogApp', 'success') return redirect(url_for('home')) else: flash('Login unsuccessful. Please check your email or password again.', 'danger') return render_template('login.html', title = 'Login', form = login)
def login(): form = LoginForm() if request.method == "POST": if form.validate(): username = form.data['username'] password = form.data['password'] user = User.query.filter_by(username=username).first() if user: password_salt = hashlib.sha1(user.salt+password).hexdigest() if password_salt == user.password: session['uid'] = user.id return redirect(url_for('index')) else: flash("username password not mathch !") else: flask('username is not exist') return render_template('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 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('home')) else: flash( 'Logowanie nieudane. Sprawdź czy email i hasło zostało wpisane prawidłowo.', 'danger') return render_template('login.html', title='Login', 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 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('home')) else: flash( 'Login Unsuccessful. Please check your email and password you have entered', 'red') return render_template('auth/login.html', title="Login", form=form)
def user_login(request): if not request.user.is_authenticated: if request.method=="POST": form=LoginForm(request=request,data=request.POST) if form.is_valid(): uname= form.cleaned_data["username"] upass= form.cleaned_data["password"] user=authenticate(username=uname,password=upass) if user is not none: login(request,user) messages.success(request,'Logged in Successfully !!!') return redirect('/dashboard/') else: form=LoginForm() return render(request,'blog/login.html',{'form':form}) else: return redirect('/dashboard/')