Beispiel #1
0
def login():
    loginform = LDAPLoginForm()
    if loginform.validate_on_submit():
        login_user(loginform.user)
        next_url = request.args.get("next")
        return redirect(next_url or url_for("main.home"))
    return render_template("main/form.html", form=loginform)
Beispiel #2
0
def login():
    template = """
    {{ get_flashed_messages() }}
    {{ form.errors }}
    <form method="POST">
        <label>Username{{ form.username() }}</label>
        <label>Password{{ form.password() }}</label>
        {{ form.submit() }}
        {{ form.hidden_tag() }}
    </form>
    """

    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        login_user(form.user)  # Tell flask-login to log them in.
        print(current_user.dn)
        print(current_user.data['memberOf'])
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(current_user.dn))
        return redirect('/')  # Send them home

    return render_template_string(template, form=form)
Beispiel #3
0
def login():
    target_url = url_path(request.args.get('url', '/'))
    if current_user.is_authenticated:
        return redirect(target_url)
    form = LDAPLoginForm(meta=wft_locales())
    if form.validate_on_submit():
        user = form.user
        # flask_login stores user in session
        login_user(user)
        app.logger.info("Logging in as user '%s'" % user.username)
        app.logger.info("Groups: %s" % user.groups)
        if user.groups:
            identity = {'username': user.username, 'groups': user.groups}
        else:
            identity = user.username
        # Create the tokens we will be sending back to the user
        access_token = create_access_token(identity)
        # refresh_token = create_refresh_token(identity)

        resp = make_response(redirect(target_url))
        # Set the JWTs and the CSRF double submit protection cookies
        # in this response
        set_access_cookies(resp, access_token)
        return resp
    elif form.submit():
        # Replace untranslated messages
        for field, errors in form.errors.items():
            if 'Invalid Username/Password.' in errors:
                errors.remove('Invalid Username/Password.')
                errors.append(i18n.t('auth.auth_failed'))

    return render_template('login.html',
                           form=form,
                           i18n=i18n,
                           title=i18n.t("auth.login_page_title"))
Beispiel #4
0
def login():
    form = LDAPLoginForm()

    if form.validate_on_submit():
        login_user(form.user)
        return redirect(
            request.args.get("next", url_for("index", _external=True)))

    return render_template("login.html", form=form)
Beispiel #5
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LDAPLoginForm()

    if form.validate_on_submit():
        login_user(form.user)
        return redirect('/')

    return render_template('auth/login.html', form=form)
Beispiel #6
0
def login():
    if current_user.is_authenticated:
        return redirect(_next_url(request))
    form = LDAPLoginForm()
    if form.validate_on_submit():
        login_user(form.user)
        return jsonify({'nextURL': _next_url(request)}), 200
    if form.username.errors:
        abort(401)
    return render_template('vue/index.html',
                           site_title=current_app.config['SITE_TITLE'])
Beispiel #7
0
def login():

    form = LDAPLoginForm()

    if form.validate_on_submit():

        login_user(form.user)

        return redirect('/')

    return render_template('auth/index.html', title='Sign In', form=form)
    def test_save_user_in_form(self):
        users = {}

        @self.manager.save_user
        def user_saver(dn, username, data, memberships):
            users[dn] = data
            return data

        with self.app.test_request_context():
            form = LDAPLoginForm(username='******', password='******')
            self.assertTrue(form.validate())
            assert form.user['dn'] in users
    def test_save_user_in_form(self):
        users = {}

        @self.manager.save_user
        def user_saver(dn, username, data, memberships):
            users[dn] = data
            return data

        with self.app.test_request_context():
            form = LDAPLoginForm(username='******', password='******')
            self.assertTrue(form.validate())
            assert form.user['dn'] in users
Beispiel #10
0
def login():
    """Login Method """
    next_page = request.args.get('next', None)
    form = LDAPLoginForm()
    validation = form.validate_on_submit()
    if validation:
        if next_page is not None and next_page.endswith('login'):
            next_page = None
        login_user(form.user)
        return redirect(next_page or url_for('default'))
    return render_template("registration/login.html",
                           next=next_page,
                           user=None,
                           form=form)
Beispiel #11
0
def login():

    form = LDAPLoginForm()

    if current_user.is_authenticated:
        return redirect(url_for('dashboard'))

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        login_user(form.user)  # Tell flask-login to log them in.
        return redirect(url_for('dashboard'))  # Send them home

    return render_template('login.html', title='Accounts - Login', form=form)
Beispiel #12
0
def login():
    """Login a user if they have access."""
    if "next" in request.args:
        session["next_url"] = request.args["next"]

    user_id = None
    user_mail = None
    if current_app.config.get("LDAP_HOST") and request.method == "POST":
        form = LDAPLoginForm()
        LOG.info("Validating LDAP user")
        if not form.validate_on_submit():
            flash(
                "username-password combination is not valid, plase try again",
                "warning")
            return redirect(url_for("public.index"))
        user_id = form.username.data

    if current_app.config.get("GOOGLE"):
        if session.get("email"):
            user_mail = session["email"]
            session.pop("email", None)
        else:
            LOG.info("Google Login!")
            redirect_uri = url_for(".authorized", _external=True)
            try:
                return oauth_client.google.authorize_redirect(redirect_uri)
            except Exception as ex:
                flash(
                    "An error has occurred while logging in user using Google OAuth"
                )

    if request.args.get("email"):  # log in against Scout database
        user_mail = request.args.get("email")
        LOG.info("Validating user %s email %s against Scout database", user_id,
                 user_mail)

    user_obj = store.user(email=user_mail, user_id=user_id)
    if user_obj is None:
        flash("User not found", "warning")
        return redirect(url_for("public.index"))

    user_obj["accessed_at"] = datetime.now()
    if session.get("name"):  # These args come from google auth
        user_obj["name"] = session.get("name")
        user_obj["locale"] = session.get("locale")
    store.update_user(user_obj)

    user_dict = LoginUser(user_obj)
    return perform_login(user_dict)
Beispiel #13
0
def login():
    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        current_app.logger.debug(
                "Logged in user: {user.username} ({user.full_name})".format(
                    user = form.user))
        login_user(form.user)  # Tell flask-login to log them in.
        return redirect('/')  # Send them home

    return render_template('login.html', form=form)
Beispiel #14
0
def login():

    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        login_user(form.user)  # Tell flask-login to log them in.
        identity_changed.send(current_app._get_current_object(),
                              identity=Identity(form.user.get_id))
        return redirect(url_for('index'))  # Send them home

    return render_template('login.html', form=form)
Beispiel #15
0
def login():
    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()
    # consultaBot()
    if request.method=="POST":
        if form.validate_on_submit():
            # Successfully logged in, We can now access the saved user object
            # via form.user.
            login_user(form.user)  # Tell flask-login to log them in.
            return redirect('/')  # Send them home
        else:
            #erro de login aqui
            return render_template('login.html', form=form, var=1)
    if request.method=="GET":
        return render_template('login.html',form=form, var=0)
Beispiel #16
0
def cc_login():
    """Login Method """
    form = LDAPLoginForm()
    if request.method.startswith("GET"):
        return render_template(
            "login.html",
            login=form,
            scholar=current_user,
        )
    validation = form.validate_on_submit()
    if validation:
        login_user(form.user)
        return redirect(url_for('academic_profile'))
    else:
        flash("Invalid username or password")
        return render_template("login.html", login=form, scholar=current_user)
Beispiel #17
0
def login():
    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        login_user(form.user)  # Tell flask-login to log them in.
        return redirect('/')  # Send them home

    return render_template('login.html',
                           page='login',
                           form=form,
                           dcs=dcs,
                           dc=dc)
Beispiel #18
0
def login():

    form = LDAPLoginForm()

    if form.validate_on_submit():

        login_user(form.user)
        flask.flash('Logged in successfully')
        next = flask.request.args.get('next')

        if not is_safe_url(next):
            return flask.abort(400)


        return redirect(next or url_for('auth.front_page'))

    return render_template('login.html', form=form)
Beispiel #19
0
def login():
    """Login a user if they have access."""
    if "next" in request.args:
        session["next_url"] = request.args["next"]

    user_id = None
    user_mail = None
    if current_app.config.get("LDAP_HOST") and request.method == "POST":
        form = LDAPLoginForm()
        LOG.info("Validating LDAP user")
        if not form.validate_on_submit():
            flash(
                "username-password combination is not valid, plase try again",
                "warning")
            return redirect(url_for("public.index"))
        user_id = form.username.data

    if current_app.config.get("GOOGLE"):
        if session.get("email"):
            user_mail = session["email"]
            session.pop("email")
        else:
            LOG.info("Validating Google user login")
            callback_url = url_for(".authorized", _external=True)
            return google.authorize(callback=callback_url)

    if request.args.get("email"):  # log in against Scout database
        user_mail = request.args.get("email")
        LOG.info("Validating user {} against Scout database".format(user_id))

    user_obj = store.user(email=user_mail, user_id=user_id)
    if user_obj is None:
        flash("User not whitelisted", "warning")
        return redirect(url_for("public.index"))

    user_obj["accessed_at"] = datetime.now()
    if session.get("name"):  # These args come from google auth
        user_obj["name"] = session.get("name")
        user_obj["locale"] = session.get("locale")
    store.update_user(user_obj)

    user_dict = LoginUser(user_obj)
    return perform_login(user_dict)
Beispiel #20
0
def authorize(*args, **kwargs):
    if current_user.is_authenticated:
        current_app.logger.info(
            "Authorizing {user.username}".format(user=current_user))
        return True

    # Otherwise instantiate a login form to log the user in.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        current_app.logger.debug(
            "Logged in user: {user.username} ({user.full_name})".format(
                user=form.user))
        login_user(form.user)  # Tell flask-login to log them in.
        return True

    return render_template('login.html', form=form)
Beispiel #21
0
def home():
    search_form = SearchForm()
    departments = []
    results = CONNECTION.datastore.query(ORG_LISTING)
    for row in results:
        departments.append(
            (row.get('iri').get('value'), row.get('label').get('value')))
    search_form.department.choices = departments
    return render_template("index.html",
                           login=LDAPLoginForm(),
                           search_form=search_form,
                           scholar=current_user)
Beispiel #22
0
def login():
    if 'demo' in app.config and app.config['demo']:
        app.logger.debug(' Demo mode authentication')
        session['username'] = user.get_id()
        users[user.get_id()] = user
        login_user(user)
        return redirect('/')
    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        #login_user(form.user)  # Tell flask-login to log them in.
        session['username'] = form.user.username
        session['infos'] = form.user.mail + " - " + form.user.department

        return redirect('/')

    return render_template('pages/login.html', form=form, title="Login")
def login():
    template = """
    {{ get_flashed_messages() }}
    {{ form.errors }}
    <form method="POST">
        <label>Username{{ form.username() }}</label>
        <label>Password{{ form.password() }}</label>
        {{ form.submit() }}
        {{ form.hidden_tag() }}
    </form>
    """

    # Instantiate a LDAPLoginForm which has a validator to check if the user
    # exists in LDAP.
    form = LDAPLoginForm()

    if form.validate_on_submit():
        # Successfully logged in, We can now access the saved user object
        # via form.user.
        login_user(form.user)  # Tell flask-login to log them in.
        return redirect('/')  # Send them home

    return render_template_string(template, form=form)
Beispiel #24
0
    def test_save_user_in_form(self):
        users = {}

        @self.manager.save_user
        def user_saver(dn, username, data, memberships):
            users[dn] = data
            return users[dn]

        with self.app.test_request_context():
            form = LDAPLoginForm(username="******",
                                 password="******")
            self.assertTrue(form.validate())
            assert form.user["dn"] in users

            form = LDAPLoginForm(username="******",
                                 password="******")
            self.assertFalse(form.validate())
 def test_with_valid_form_data_invalid_ldap(self):
     with self.app.test_request_context():
         form = LDAPLoginForm(
             username='******', password='******')
         self.assertFalse(form.validate())
 def test_with_valid_form_data_invalid_ldap(self):
     with self.app.test_request_context():
         form = LDAPLoginForm(username='******',
                              password='******')
         self.assertFalse(form.validate())
 def test_invalid_form_data(self):
     with self.app.test_request_context():
         form = LDAPLoginForm(password='******')
         self.assertFalse(form.validate())
Beispiel #28
0
def login():
    form = LDAPLoginForm()
    if form.validate_on_submit():
        login_user(form.user, remember=True)
        return redirect(request.args.get('next') or '/index')
    return render_template('login.html', form=form)
Beispiel #29
0
def login():
    form = LDAPLoginForm()
    if form.validate_on_submit():
        login_user(form.user)  # Tell flask-login to log them in.
        return redirect(url_for('items.index'))  # Send them home
    return render_template('login.html', form=form)
Beispiel #30
0
def index():
    """Show the static landing page."""
    form = None
    if current_app.config.get("LDAP_HOST"):
        form = LDAPLoginForm()
    return render_template("public/index.html", version=__version__, form=form)
 def test_invalid_form_data(self):
     with self.app.test_request_context():
         form = LDAPLoginForm(password='******')
         self.assertFalse(form.validate())