Advertisement
sriyanto

route_login

Oct 12th, 2022
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. #login
  2. @app.route('/login', methods=('GET', 'POST'))
  3. def login():
  4.     if request.method == 'POST':
  5.         email = request.form['email']
  6.         password = request.form['password']
  7.        
  8.         #cek data username
  9.         #cursor = mysql.connection.cursor()
  10.         cursor = db.cursor()
  11.         cursor.execute('SELECT * FROM tb_users WHERE email=%s',(email, ))
  12.         akun = cursor.fetchone()
  13.         if akun is None:
  14.             flash('Login Gagal, Cek Username Anda','danger')
  15.         elif not check_password_hash(akun[3], password):
  16.             flash('Login gagal, Cek Password Anda', 'danger')
  17.         else:
  18.             session['loggedin'] = True
  19.             session['username'] = akun[1]
  20.             session['level'] = akun[4]
  21.             return redirect(url_for('index'))
  22.     return render_template('login.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement