def app_login(request): """ Attempts to authenticate a user to Aristotle Library Apps :param request: HTTP Request """ if request.method == 'GET': return HttpResponse("IN GET App Login") username = request.POST['username'] password = request.POST['password'] next_page = request.REQUEST.get('next') errors = [] try: user = authenticate(last_name=username, iii_id=password) except KeyError: user = None if user is not None: if user.is_active: login(request, user) if len(next_page) > 0: return redirect(next_page) else: return redirect('/apps') else: error_msg = "User not active" logger.error(error_msg) errors.append(error_msg) else: error_msg = "User {0} not found or unable to authenticate".format(username) logger.error(error_msg) errors.append(error_msg) auth_form = AuthenticationForm(request.POST) auth_form.full_clean() auth_form._errors[NON_FIELD_ERRORS] = auth_form.error_class(errors) return direct_to_template(request, 'registration/login.html', {'app':None, 'institution':json_loader.get('institution'), 'form': auth_form, 'navbar_menus':json_loader.get('navbar-menus'), 'user':user})