def signin(): # See if user is already logged in if 'email' in session: return redirect('/') form = user_forms.Login() if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() # Check the user exists if user is not None: # Check the password is correct if user.check_password(form.password.data): login_user(user) # Send back to the home page session['email'] = form.email.data flash('Succesfully signed in.', 'positive') return redirect(url_for('index')) else: flash('The password you have entered is wrong.', 'negative') return redirect(url_for('userbp.signin')) else: flash('Unknown email address.', 'negative') return redirect(url_for('userbp.signin')) return render_template('user/signin.html', form=form, title='Sign in', address='test')
def signin(): form = user_forms.Login() error = None if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() # Check the user exists if user is not None: # Check the password is correct if user.check_password(form.password.data): if user.confirmation == True: login_user(user) # Send back to the home page flash('Succesfully signed in.', 'positive') return redirect(url_for('index')) else: flash('Please confirm your Email address', 'negative') return redirect(url_for('userbp.signin')) else: #error = 'The password you have entered is wrong.' flash('The password you have entered is wrong.', 'negative') return redirect(url_for('userbp.signin')) else: #error = 'Unknown email address.' flash('Unknown email address.', 'negative') return redirect(url_for('userbp.signin')) return render_template('user/signin2.html', form=form, title='Sign in')
def index(): if current_user.is_authenticated: if current_user.access_token: return redirect(url_for('userbp.dashboard')) else: return redirect(url_for('userbp.insta_signin')) form = user_forms.Login() return render_template('index.html', form=form, title='Home', action_url='/user/signin')
def signin(): form = user_forms.Login() next_url = request.args.get('next', url_for('index')) print('signin() next_url:', next_url) if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() if user is not None: if user.check_password(form.password.data): login_user(user) flash('Successfully signed in.', 'info') return redirect(next_url) else: flash('The password you have entered is wrong.', 'error') return redirect(url_for('userbp.signin', next=next_url)) else: flash('Unknown email address.', 'error') return redirect(url_for('userbp.signin', next=next_url)) return render_template('user/signin.html', form=form, title='Sign in')
def signin(): ''' Function to direct user to index page if log-in is successful, back to sign in page if incorrect password/email is given ''' form = user_forms.Login() if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() # Check the user exists if user is not None: # Check the password is correct if user.check_password(form.password.data): login_user(user) # Send back to the home page flash('Succesfully signed in.', 'positive') return redirect(url_for('product')) else: flash('The password you have entered is wrong.', 'negative') return redirect(url_for('userbp.signin')) else: flash('Unknown email address.', 'negative') return redirect(url_for('userbp.signin')) return render_template('user/signin2.html', form=form, title='Sign in')
def signin(): form = user_forms.Login() if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() # Check the user exists if user is not None: # Setup a connection between the client and LDAP server user_ldap_dn = 'cn=' + user.email.split( '@', 1)[0] + ',ou=Users,dc=ldap,dc=com' c = Connection(s, user=user_ldap_dn, password=form.password.data) # Initialize connection to LDAP server c.open() # Start TLS to encrypt credentials c.start_tls() # Check the password is correct if user.check_password(form.password.data) and c.bind(): # unbind user from LDAP server and log them in c.unbind() login_user(user) logger.info('User logged in successfully', user=current_user.get_id()) # Send back to the home page flash('Succesfully signed in.', 'positive') return redirect(url_for('index')) else: print(c) logger.info( 'User login attempt failed failed for user {}'.format( user.get_id()), user="******") flash('The password you have entered is wrong.', 'negative') return redirect(url_for('userbp.signin')) else: flash('Unknown email address.', 'negative') return redirect(url_for('userbp.signin')) return render_template('user/signin.html', form=form, title='Sign in')
def signin(): try: form = user_forms.Login() if form.validate_on_submit(): user = models.User.query.filter_by(email=form.email.data).first() if user is not None: if user.check_password(form.password.data): login_user(user) flash("Succesfully signed in", "positive") return redirect(url_for('main.index')) else: flash( "The password and the email address you have entered don't match", "negative") return redirect(url_for('userbp.signin')) else: flash('Unknown email address.', 'negative') return redirect(url_for('userbp.signin')) return render_template('user/signin.html', form=form, title='Sign in') except InvalidRequestError as e: print(e) db.session.rollback() return redirect(url_for('userbp.signin'))