def login(): """Login Route This route leads to the login page. Args: None Returns: if GET returns the rendered login page if POST returns a validated user redirected to the non-public index page Raises: redirects back to login if login not valid """ form = SignInForm() if current_user.is_authenticated: return redirect(url_for('auth.logged_in')) if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('auth.login')) login_user(user, remember=form.remember_me.data) return redirect(url_for('main.index')) return render_template('login.html', title='CONP | Log In', form=form, error=form.errors)
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('books')) signinform = SignInForm() signupform = SignUpForm() if signinform.validate_on_submit(): user = User.query.filter_by(username=signinform.username.data).first() password = make_secure_token(signinform.password.data) if user is not None and password == user.password: login_user(user) return redirect(url_for('books')) else: flash('Invalid login. Please try again.') if signupform.validate_on_submit(): username = signupform.username.data email = signupform.email.data password = make_secure_token(signupform.password.data) user = User(username=username, email=email, password=password) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('books')) return render_template('auth.html', title='Sign In', signinform=signinform, signupform=signupform, )
def signin(): form = SignInForm() if form.validate_on_submit(): e_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(name=form.name.data, email=form.email.data, password=e_password) db.session.add(user) db.session.commit() msg = "Created user {}".format(form.name.data) flash(msg, "success") return render_template("SignInForm.html", message="Register", form=form)
def signin(): form = SignInForm() if form.validate_on_submit(): student_id = form.student_id.data try: at_sign_in(student_id, column=DATE_COLUMN) flash(f"Okay, I'll sign in user {student_id}") with open('scans.csv', 'a') as f: f.write(f"{datetime.datetime.now()},{student_id},-,-\n") return redirect(url_for('signin')) except: flash('No such user!') return redirect(url_for('register', student_id=student_id)) return render_template('signinform.html', form=form)
def login(): error = None form = SignInForm() if form.validate_on_submit(): username = form.username.data password = form.password.data user = User.query.filter_by(username=username).first() if password == user.password: login_user(user, remember=True) run_watching() return redirect(url_for('index')) return render_template('signin.html', form=form, error=error)
def sign_in(): if current_user.is_authenticated: return redirect(url_for('index')) form = SignInForm(request.form) if form.validate_on_submit(): user = models.User.query.filter_by( user_email=form.user_email.data).first() if not user or not user.check_user_pw(form.user_password.data): flash('Invalid User ID or Password.') return redirect(url_for('sign_in')) login_user(user, remember=form.user_remember_me.data) return redirect(url_for('index')) return render_template('signIn.html', form=form)
def login(): error = None form = SignInForm() if current_user.is_authenticated: return redirect(url_for('logged_in')) if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(email=form.email.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) return redirect(url_for('index')) return render_template('login.html', title='CONP | Log In', form=form, error=form.errors)
def login(): title = "Login" if current_user.is_authenticated: return redirect(url_for('index')) form = SignInForm() if form.validate_on_submit(): user = User(dict = users_col.find({"username":form.username.data})[0]) if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('index')) login_user(user) 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', form=form)
def signIn(): if current_user.is_authenticated: return redirect(url_for('index')) signInForm = SignInForm() if signInForm.validate_on_submit(): user = User.query.filter_by(email=signInForm.email.data).first() if user is None or not user.check_password(signInForm.password.data): flash('Invalid email or password', 'danger') return render_template('sign_in.html', title='Sign In', form=signInForm) login_user(user, remember=signInForm.remember_me.data) return redirect(url_for('game')) else: return render_template('sign_in.html', title='Sign In', form=signInForm)
def login_page(): form = SignInForm() # object class obtained from the app.forms module # this contains the field defnitions (booleans, string & pw fields) # it is passed into the render_template, which expects these definitions # to handle user data being submitted (this function does the heavy lifting): if form.validate_on_submit(): # the validate_on_submit method won't trigger during the initial GET request # from the browser to fetch the html of the page, hence this check # or if any of the field validations (e.g. pw) fails. Can add error message later flash("Login requested for user {}, remember_me={}".format( form.username.data, form.remember_login.data )) # Flask method, flash shows a message to the user. Needs html (see base.html) # the login doesn't do anything yet, besides confirm data is recieved return redirect(url_for('game')) # sends user somewhere else # the url_for calls the corresponding page handling function rather than the path directly return render_template("login.html", form=form, title="Login to Game")
def sign_in(): if current_user.is_authenticated: return redirect(url_for("dashboard")) form = SignInForm(request.form) 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", "danger") return redirect(url_for("sign_in")) login_user(user, remember=form.remember_me.data) flash(f"User {current_user.username} logged in successful", "success") return redirect(url_for("dashboard")) return render_template("sign_in.html", title="Sign in page", form=form)
def index(): form = SignInForm() #IF USER CONNECTED REDIRECT TO DASHBOARD if current_user.is_authenticated: return redirect(url_for('dashboard')) #SEND FROM IF CONDITIONS = OK AND REDIRECTS if request.method == 'POST' and form.validate_on_submit(): #VERIFY IF USER EXIST IN DATABASE user = User.query.filter_by(username=form.username.data).first() #IF USER OR PASSWORD DONT MATCH RETURN TO LOGIN if user is None or not user.check_password(form.password.data): flash('Invalid username or password') return redirect(url_for('index')) login_user(user, remember=form.remember_me.data) return redirect(url_for('dashboard')) return render_template('signin.html', title='Sign In', form=form)
def sign_in(): # Redirect the user to the index page if he or she has been authenticated # already. if current_user.is_authenticated: return redirect(url_for('home.home')) form = SignInForm(request.form) if form.validate_on_submit(): user = form.validate_signin() if user: # Notify the login manager that the user has been signed in. login_user(user) if user.disabled: flash(_('Your account has been disabled, you are not allowed ' 'to log in'), 'danger') else: flash(_('Hey %(name)s, you\'re now logged in!', name=current_user.first_name), 'success') referer = request.headers.get('Referer') denied = ( re.match(r'(?:https?://[^/]+)%s$' % (url_for('user.sign_in')), referer) is not None) denied_from = session.get('denied_from') if not denied: if referer: return redirect(referer) elif denied_from: return redirect(denied_from) return redirect(url_for('home.home')) if form.errors: flash_form_errors(form) return render_template('user/sign_in.htm', form=form)
def signup(): form_sign_up = SignInForm() if current_user.is_authenticated: return redirect('/') if utils.find_user_by_username(form_sign_up.username.data): flash('That username is taken, please try again.') return render_template('signup.html', title='Sign Up', form=form_sign_up) if form_sign_up.password.data != form_sign_up.password2.data: flash("Your passwords didn't match, please try again.") return render_template('signup.html', title='Sign Up', form=form_sign_up) if form_sign_up.validate_on_submit( ) and form_sign_up.password.data == form_sign_up.password2.data: db.create_all() loc = models.Location.query.filter_by( city=form_sign_up.city.data, region=form_sign_up.region.data).first() if not loc: loc = models.Location(city=form_sign_up.city.data, region=form_sign_up.region.data, country='placeholder') db.session.add(loc) db.session.commit() user = models.User(username=form_sign_up.username.data, location_id=loc.id) user.set_password(form_sign_up.password.data) db.session.add(user) db.session.commit() return redirect('/login/') return render_template('signup.html', title='Sign Up', form=form_sign_up)