Exemple #1
0
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if logged_in_user() is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if not re.findall('^https*://', openid):
            openid = 'http://' + openid
        if openid:
            pape_req = pape.Request([])
            x = oid.try_login(openid,
                              ask_for=['email', 'nickname'],
                              ask_for_optional=['fullname'],
                              extensions=[pape_req])
            return x
    form = LoginForm()
    if form.validate_on_submit():
        return redirect(oid.get_next_uril())

    msg = oid.fetch_error()
    if msg:
        flash(msg)
    elif fns_util.pu_time():
        flash('Please enter an openid')

    return render_template('login.html',
                           next=oid.get_next_url(),
                           error=oid.fetch_error(),
                           form=form,
                           version=version.__version__)
Exemple #2
0
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if logged_in_user() is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if not re.findall('^https*://', openid):
            openid = 'http://' + openid
        if openid:
            pape_req = pape.Request([])
            x = oid.try_login(openid, ask_for=['email', 'nickname'],
                              ask_for_optional=['fullname'],
                              extensions=[pape_req])
            return x
    form = LoginForm()
    if form.validate_on_submit():
        return redirect(oid.get_next_uril())

    msg = oid.fetch_error()
    if msg:
        flash(msg)
    elif fns_util.pu_time():
        flash('Please enter an openid')

    return render_template('login.html',
                           next=oid.get_next_url(),
                           error=oid.fetch_error(),
                           form=form,
                           version=version.__version__)
Exemple #3
0
def oid_login():
    if g.user is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if openid:
            return oid.try_login(openid, ask_for=['email', 'nickname'],
                                 ask_for_optional=['fullname'])
    return render_template('web/index.html', next=oid.get_next_url(),
                           error=oid.fetch_error())
Exemple #4
0
def login():
    if g.user is not None:
        return redirect(oid.get_next_url())

    form = LoginForm()
    if form.validate_on_submit():
        return oid.try_login(form.openid.data)
    return render_template('login.html',
                           form=form,
                           next=oid.get_next_url(),
                           error=oid.fetch_error())
Exemple #5
0
def login():
  if flask.g.user is not None:
    return flask.redirect(oid.get_next_url())
  if flask.request.method == "POST":
    openid = flask.request.form.get("openid")
    if openid:
      return oid.try_login(openid, ask_for=["email", "fullname", "nickname"])
  # Display the errors on the page using the standard flash mechanism
  error = oid.fetch_error()
  if error:
    flask.flash(error, "alert-error")
  return flask.render_template("login.html", next=oid.get_next_url())
def login():
    user = g.user
    if user is not None and user.is_authenticated:
        # User must already be logged in
        return redirect(oid.get_next_url())
    form = LoginForm()
    if form.validate_on_submit():
        # Got login data from post request
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    # User must not be logged in yet and sent a get request to /login
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'],
                           next=oid.get_next_url(),
                           error=oid.fetch_error())
Exemple #7
0
def login():
    """ This function handles GET and POST requests from the login page.
    GET request is when the user is opening the page and POST is when user
    is submitting login information.
    :return:  renders a login page or redirects to the main page (index)
    """
    if g.user is not None and g.user.is_authenticated():
        # the user is already authenticated, no need to show login form
        return redirect(url_for('index'))   # url_for will produce the URL associated with function "index"
    # Create form object
    form = LoginForm()
    # The validate_on_submit method does all the form processing work.
    # If you call it when the form is being presented to the user (i.e. before the user got a
    # chance to enter data on it) then it will return False, so in that case you know that you
    # have to render the template.
    # When validate_on_submit is called as part of a form submission request, it will gather all
    # the data, run all the validators attached to fields, and if everything is all right it will
    # return True, indicating that the data is valid and can be processed. This is your indication
    # that this data is safe to incorporate into the application.
    # If at least one field fails validation then the function will return False and that will cause
    # the form to be rendered back to the user, and this will give the user a chance to correct any
    # mistakes.
    if form.validate_on_submit():
        # Form validation successful.
        # Store remember_me setting to Flask session
        session['remember_me'] = form.remember_me.data
        # Use Flask-OpenID to try to login the user.
        #     This function call will actually return redirect. If login is successful Flask.OpenID
        #     will call a function decorated with oid.after_login decorator, which will then return
        #     the redirect to the page we want to go after successful login.
        #     If login is not successful this OpenID call will redirect us back to login page.
        redirect_page = oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
        flash('oid error: {}'.format(oid.fetch_error()), 'error')
        return redirect_page
    # If we're here then we one of these things happened:
    #    a) the login form is just opening, or
    #    b) form validation failed
    # Either way, show the login page.
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Exemple #8
0
def login():
    if g.user is not None:
        return redirect(oid.get_next_url())

    if request.method == 'POST':
        openid = request.form.get('openid_auto_url')
        if not openid:
            openid = request.form.get('openid')
        if openid:
            return oid.try_login(openid, ask_for = ['email', 'fullname', 'nickname', 'country', 'timezone', 'website'])

    # login form
    form = LoginForm(request.form)
    # make sure data is valid, but doesn't validate password is right
    if form.validate_on_submit():
        g.user = User.query.filter_by(email = form.email.data).first()
        #we use werzeug to validate user's password
        if g.user and check_password_hash(g.user.password, form.password.data):
            # the session can't be modified as it's signed, it's a safe place to store the user ID
            session['user_id'] = g.user.id
            flash('Successfully logged %s in!' % g.user.name)
            return redirect(oid.get_next_url())
        flash('Wrong email or password', 'error-message')
    return render_template('users/login.html', form = form, next = oid.get_next_url(), error = oid.fetch_error())