def login(): if request.method == 'POST': user = request.form['nm'] return redirect(url_for('success',name = user)) else: user = request.args.get('nm') return redirect(url_for('success',name = user))
def login(): if request.method == "POST": if request.form["username"] == "admin" : return redirect(url_for("success")) else: abort(451) else: return redirect(url_for("index"))
def register(): if request.method == "POST": username = request.form['username'] password = request.form['password'] db = get_db() error = None if not username: error = '*Username required' elif not password: error = '*Password required' elif db.execute( 'SELECT id FROM user WHERE username = ?', (username,) ).fetchone() is not None: error = 'User {} is already registered.'.format(username) if error is None: db.execute( 'INSERT INTO user (username, password) VALUES (?, ?)', (username, generate_password_hash(password)) ) db.commit() return redirect(url_for('auth.login')) flash(error)
def update(id): todo = request.form.get("todoitemupdate") update_this = Todo.query.get(id) update_this.text = todo db.session.commit() return redirect(url_for('index'))
def complete(id): todo = Todo.query.filter_by(id=int(id)).first() todo.complete = True db.session.commit() return redirect(url_for('index'))
def sign_up(): if request.method == 'POST': email = request.form.get('email') first_name = request.form.get('firstName') password1 = request.form.get('password1') password2 = request.form.get('password2') user = User.query.filter_by(email=email).first() if user: flash('Email already exists.', category='error') elif len(email) < 4: flash('Email must be greater than 3 characters.', category='error') elif len(first_name) < 2: flash('First name must be greater than 1 character.', category='error') elif password1 != password2: flash('Passwords don\'t match.', category='error') elif len(password1) < 7: flash('Password must be at least 7 characters.', category='error') else: new_user = User(email=email, first_name=first_name, password=generate_password_hash( password1, method='sha256')) db.session.add(new_user) db.session.commit() login_user(new_user, remember=True) flash('Account created!', category='success') return redirect(url_for('views.home')) return render_template("sign_up.html", user=current_user)
def login(): form = LoginForm() if form.validate_on_submit(): if form.email.data == "*****@*****.**" and form.password.data == "password": flash("You successfully logged in!","success") return redirect(url_for('home')) else: flash('Login unsuccessful, please check username and password','danger') return render_template('login.html',title='Login',form=form)
def login(): if request.method == "GET": return render_template("login.html") else: username = request.form["username"] password = request.form["password"] if utils.authenticate(username, password): session['username'] = username return redirect(url_for("user_profile")) else: return "Error: Incorrect username or password <hr><a href = '/home'>Try again</a></hr>"
def login(): error = None if request.method == 'POST': if request.form['username'] != 'admin' or \ request.form['password'] != 'admin': error = 'Invalid username or password. Please try again!' else: flash('You were successfully logged in') return redirect(url_for('index')) return render_template('login.html', error = error)
def login(): login_form = LoginForm() if login_form.validate_on_submit(): user = User.query.filter_by(email = login_form.email.data).first() if user is not None and user.verify_password(login_form.password.data): login_user(user,login_form.remember.data) return redirect(request.args.get('next') or url_for('main.index')) flash('Invalid username or Password') title = "watchlist login" return render_template('auth/login.html',login_form = login_form,title=title)
def register(): form = RegistrationForm() if form.validate_on_submit(): user = User(email = form.email.data, username = form.username.data,password = form.password.data) db.session.add(user) db.session.commit() mail_message("Welcome to blogt","email/welcome_user",user.email,user=user) return redirect(url_for('auth.login')) title = "Account" return render_template('auth/register.html',registration_form = form)
def login(): users = mongo.db.users login_user = users.find_one({"name":request.form['username']}) if login_user: if bcrypt.hashpw(request.form['pass'].encode('UTF-8'),login_user['password'].encode('UTF-8')) == login_user['password'].encode('UTF-8'): session['username'] = request.form['username'] return redirect(url_for('index')) return 'Invalid username/password' return 'No User found'
def newOnlineshopping(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newOnlineshopping = Onlineshopping( name=request.form['name']) session.add(newOnlineshopping) flash ('New Onlineshopping %s Successfully Created' % newOnlineshopping.name) session.commit() return redirect(url_for('showshoppingwebsites')) else: return render_template('newshoppingwebsite.html')
def register(): if request.method == 'POST': users = mongo.db.users existing_user = users.find_one({'name':request.form['username']}) if existing_user is None: hashpwd = bcrypt.hashpw(request.form['pass'].encode('UTF-8'),bcrypt.gensalt()) users.insert({'name':request.form['username'],'password':hashpwd}) session['username'] = request.form['username'] return url_for('index') return 'username already exist' return render_template('register.html')
def index(): if request.method == 'GET' : return '<form action="/" method ="POST"> <input name = "email"><input type="submit"></form>' email = request.form['email'] token = s.dumps(email,salt='email-confirm') msg = Message('confirm eamil',sender = '*****@*****.**',recipients=[email]) link = url_for('confirm_email',token = token,_external = True) msg.body = 'your link is {}'.format(link) mail.send(msg) return 'the email you entered is {}. the token is {}'.format(email,token)
def register(): form = RegistrationForm() # if form.validate_on_submit(): # flash(f'Accout created for {form.username.data}!',"success") # return redirect(url_for('home')) if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(username=form.username.data,email=form.email.data,password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created successfully! You are now able to login','success') return redirect(url_for('login')) return render_template('register.html',title='Register',form=form)
def deleteOnlineshopping(shoppingwebsite_id): if 'username' not in login_session: return redirect('/login') shoppingwebsiteToDelete = session.query( Onlineshopping).filter_by(id=shoppingwebsite_id).one() if request.method == 'POST': session.delete(shoppingwebsiteToDelete) flash('%s Successfully Deleted' % shoppingwebsiteToDelete.name) session.commit() return redirect(url_for('showshoppingwebsites', shoppingwebsite_id=shoppingwebsite_id)) else: return render_template ('deleteshoppingwebsite.html', shoppingwebsite=shoppingwebsiteToDelete)
def login(): if request.method == 'POST': email = request.form.get('email') password = request.form.get('password') user = User.query.filter_by(email=email).first() if user: if check_password_hash(user.password, password): flash('Logged in successfully!', category='success') login_user(user, remember=True) return redirect(url_for('views.home')) else: flash('Incorrect password, try again.', category='error') else: flash('Email does not exist.', category='error') return render_template("login.html", user=current_user)
def editOnlineshopping(shoppingwebsite_id): if 'username' not in login_session: return redirect('/login') editedOnlineshopping = session.query( Onlineshopping).filter_by(id=shoppingwebsite_id).one() if request.method == 'POST': if request.form['name']: editedOnlineshopping.name = request.form['name'] session.add(editedOnlineshopping) session.commit() flash ('Onlineshopping Successfully Edited %s' % editedOnlineshopping.name) return redirect(url_for('showshoppingwebsites')) else: return render_template ('editShoppingwebsite.html', shoppingwebsite=editedOnlineshopping)
def newProducts(shoppingwebsite_id): if 'username' not in login_session: return redirect('/login') shoppingwebsite = session.query(Onlineshopping).filter_by(id=shoppingwebsite_id).one() if request.method == 'POST': newProduct = Products(name=request.form['name'], price=request.form[ 'price'], course=request.form['course'], shoppingwebsite_id=shoppingwebsite_id, user_id=shoppingwebsite.user_id) session.add(newProduct) session.commit() flash('New Product %s Item Successfully Created' % (newProduct.name)) return redirect(url_for('showProduct', shoppingwebsite_id=shoppingwebsite_id)) else: return render_template ('newproduct.html', shoppingwebsite_id=shoppingwebsite_id)
def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] db = get_db() error = None user = db.execute( 'SELECT * FROM user WHERE username = ?', (username,) ).fetchone() if user is None: error = 'Incorrect username.' elif not check_password_hash(user['password'], password): error = 'Incorrect password.' if error is None: session.clear() session['user_id'] = user['id'] return redirect(url_for('index')) flash(error)
def editProducts(shoppingwebsite_id, product_id): if 'username' not in login_session: return redirect('/login') editedProduct = session.query(Products).filter_by(id=product_id).one() shoppingwebsite = session.query(Onlineshopping).filter_by(id=shoppingwebsite_id).one() if request.method == 'POST': if request.form['name']: editedProduct.name = request.form['name'] if request.form['price']: editedProduct.price = request.form['price'] if request.form['course']: editedProduct.course = request.form['course'] session.add(editedProduct) session.commit() flash('Products Successfully Edited') return redirect(url_for('showProduct', shoppingwebsite_id=shoppingwebsite_id)) else: return render_template ('editproduct.html', shoppingwebsite_id=shoppingwebsite_id, product_id=product_id, product=editedProduct)
def wrapped_view(**kwargs): if g.user is None: return redirect(url_for('auth.login')) return view(**kwargs)
def logout(): logout_user() flash('logged out') return redirect(url_for("main.index"))
def logout(): session.pop('username',None) return redirect(url_for('home'))
def logout(): logout_user() return redirect(url_for('auth.login'))
def logout(): session['username'] = "" return redirect(url_for("home"))
def delete(id): todo_id = Todo.query.get(id) db.session.delete(todo_id) db.session.commit() return redirect(url_for('index'))
def login(): if request.method =='POST': session['username'] = request.form['username'] return redirect(url_for('home')) return '''
def add(): todo = Todo(text=request.form['todoitem'], complete=False) db.session.add(todo) db.session.commit() return redirect(url_for('index'))