예제 #1
0
def login_submit():
    """Handles authentication."""
    username = flask.request.form.get('username', None)
    password = flask.request.form.get('password', None)

    if username is not None and password is not None:
        user_id = helpers.authenticate(username, password)
        if user_id is not None:
            permissions = auth_utils.get_permissions(username)
            flask.session['username'] = username
            flask.session['permissions'] = permissions
            # True if there's any reason to show a link to the admin interface.
            flask.session['show_admin'] = len(
                auth_utils.generate_admin_links()) > 0
            # Update last login time
            auth_utils.update_last_login(username)

            # Return to previous page if in session
            if 'next' in flask.session:
                redirect_to = flask.session.pop('next')
                return flask.redirect(redirect_to)
            else:
                return flask.redirect(flask.url_for('home'))
    flask.flash('Incorrect username or password. Please try again!')
    return flask.redirect(flask.url_for('auth.login'))
예제 #2
0
def admin_home():
    """
  Loads a home page for admins, providing links to various tools.
  """
    links = auth_utils.generate_admin_links()
    # If there are no links, they have no business being here so we return an
    # access denied error.
    if len(links) == 0:
        flask.abort(httplib.FORBIDDEN)
    return flask.render_template('admin.html', links=links)
예제 #3
0
def admin_home():
  """
  Loads a home page for admins, providing links to various tools.
  """
  links = auth_utils.generate_admin_links()
  # If there are no links, they have no business being here so we return an
  # access denied error.
  if len(links) == 0:
    flask.abort(httplib.FORBIDDEN)
  return flask.render_template('admin.html', links=links)
예제 #4
0
def login_submit():
  """Handles authentication."""
  username = flask.request.form.get('username', None)
  password = flask.request.form.get('password', None)

  if username is not None and password is not None:
    user_id = helpers.authenticate(username, password)
    if user_id is not None:
      permissions = auth_utils.get_permissions(username)
      flask.session['username'] = username
      flask.session['permissions'] = permissions
      # True if there's any reason to show a link to the admin interface.
      flask.session['show_admin'] = len(auth_utils.generate_admin_links()) > 0
      # Update last login time
      auth_utils.update_last_login(username)

      # Return to previous page if in session
      if 'next' in flask.session:
        redirect_to = flask.session.pop('next')
        return flask.redirect(redirect_to)
      else:
        return flask.redirect(flask.url_for('home'))
  flask.flash('Incorrect username or password. Please try again!')
  return flask.redirect(flask.url_for('auth.login'))