def login(): form = LoginForm() username_not_recognised = None password_does_not_match_username = None if form.validate_on_submit(): # POST try: user = services.get_user(form.username.data, repo.repository_instance) # Authenticate user services.authenticate_user(user.user_name, form.password.data, repo.repository_instance) # Initialize session session.clear() session['username'] = user.user_name return redirect(url_for('home_bp.home')) except services.UnknownUserException: username_not_recognised = 'Unknown User' except services.AuthenticationException: # Authentication failed, set a suitable error message. password_does_not_match_username = '******' return render_template( 'authentication/credentials.html', title='Login', username_error_message=username_not_recognised, password_error_message=password_does_not_match_username, form=form )
def login(): form = LoginForm() username_not_recognised = None password_does_not_match_username = None if form.validate_on_submit(): # Successful POST, i.e. the username and password have passed validation checking. # Use the service layer to lookup the user. try: user = services.get_user(form.username.data, repo.repo_instance) # Authenticate user. services.authenticate_user(user['username'], form.password.data, repo.repo_instance) # Initialise session and redirect the user to the home page. session.clear() session['username'] = user['username'] return redirect(url_for('home_bp.home')) except services.UnknownUserException: # Username not known to the system, set a suitable error message. username_not_recognised = 'Username not recognised - please supply another' except services.AuthenticationException: # Authentication failed, set a suitable error message. password_does_not_match_username = '******' # For a GET or a failed POST, return the Login Web page. return render_template( 'authentication/credentials.html', title='Login', username_error_message=username_not_recognised, password_error_message=password_does_not_match_username, form=form)
def test_authentication_with_invalid_credentials(memory_repo): username = '******' password = '******' auth_services.add_user(username, password, memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(username, '0987654321', memory_repo)
def test_authentication_with_invalid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) with pytest.raises(auth_services.AuthenticationException): auth_services.authenticate_user(new_username, '0987654321', in_memory_repo)
def test_authentication_with_valid_credentials(memory_repo): username = '******' password = '******' auth_services.add_user(username, password, memory_repo) try: auth_services.authenticate_user(username, password, memory_repo) except AuthenticationException: assert False
def test_authentication_with_valid_credentials(in_memory_repo): new_username = '******' new_password = '******' auth_services.add_user(new_username, new_password, in_memory_repo) try: auth_services.authenticate_user(new_username, new_password, in_memory_repo) except AuthenticationException: assert False
def login(): form = LoginForm() if request.method == 'GET': return render_template('./authentication/login.html',form=form) user = request.form.get('user') pwd = request.form.get('pwd') messages = services.authenticate_user(user,pwd,repo.repo_instance) if messages['state']: session['user_info'] = user return redirect('/movieslist/') else: return render_template('./authentication/login.html',form=form,message=messages['error'])
def login(): form = LoginForm() username_error_msg = None password_error_msg = None if form.validate_on_submit(): try: user = services.get_user(form.username.data, repo.repo_instance) services.authenticate_user(form.username.data, form.password.data, repo.repo_instance) session.clear() session['username'] = user['username'] return redirect(url_for(HOME_BP + '.' + 'home')) except services.UnknownUserException: username_error_msg = 'User cannot be recognized, please check your username' except services.AuthenticationException: password_error_msg = 'Password cannot be authenticated, please check your password' return render_template('credentials.html', title='Movie Login', form=form, username_error_msg=username_error_msg, password_error_msg=password_error_msg)