Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def login():
- ### this is if the user is already logged in and tries to access this page. it redirects to the homepage
- ### NOTICE this works fine.
- if current_user.is_authenticated:
- if current_user.full_name == Employee.query.filter_by(full_name=current_user.full_name).first():
- return redirect(url_for('employee'))
- if current_user.full_name == Administration.query.filter_by(full_name=current_user.full_name).first():
- return redirect(url_for('administrator'))
- form = LoginForm()
- if form.validate_on_submit():
- ### variables for Employee access and Administration access
- user = Employee.query.filter_by(full_name=form.username.data).first()
- admin = Administration.query.filter_by(full_name=form.username.data).first()
- ### this will redirect to fresh login page if incorrect user or pass
- ### NOTICE this works fine for both tables. correct username with incorrect pass included
- if user is None or not user.check_password(form.password.data):
- if admin is None or not admin.check_password(form.password.data):
- return redirect(url_for('login'))
- user_log = Employee(full_name=form.username.data)
- ### This takes the username from Employee table and checks with username in form
- ### This then take the password from Employee table and checks with password form
- ### NOTICE this will work fine for valid Employee table and password but when try to
- ### run a valid username/password from the Administration table it will
- ### throw a syntax for 'user.check_password(form.password.data)' because
- ### it should be using the below if statement using the 'admin.check_password(form.password.data)'
- if user_log.full_name == form.username.data and user.check_password(form.password.data):
- login_user(user, remember=form.remember_me.data)
- next_page_user = request.args.get('next')
- if not next_page_user or url_parse(next_page_user).netloc != '':
- next_page_user = url_for('employee')
- return redirect(next_page_user)
- admin_log = Administration(full_name=form.username.data)
- ### This takes the username from Administration table and checks with username in form
- ### This then take the password from Administration table and checks with password form
- ### NOTICE this does not get to run yet because the above function is where the error is.
- if admin_log.full_name == form.username.data and admin.check_password(form.password.data):
- login_user(admin, remember=form.remember_me.data)
- next_page_admin = request.args.get('next')
- if not next_page_admin or url_parse(next_page_admin).netloc != '':
- next_page_admin = url_for('administrator')
- return redirect(next_page_admin)
- return render_template('login.html', title='Sign In', form=form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement