def login():
    '''Log in as administrator

    You can use wither basic auth or form based login (via POST).

    :param username: The administrator's username
    :type username: string
    :param password: The administrator's password
    :type password: string
    '''
    username = None
    password = None
    next = flask.request.args.get('next')
    auth = flask.request.authorization

    if flask.request.method == 'POST':
        username = flask.request.form['username']
        password = flask.request.form['password']

    if auth and auth.type == 'basic':
        username = auth.username
        password = auth.password

    if not flogin.current_user.is_active:
        error = 'You have to login with proper credentials'
        if username and password:
            if check_auth(username, password):
                user = _users.get(username)
                if user:
                    if flogin.login_user(user):
                        return flask.redirect(next or flask.url_for("user"))
                    error = 'Could not log in user.'
                else:
                    error = 'User not found.'
            else:
                error = 'Wrong username or password.'
        else:
            error = 'No username or password.'
        return flask.Response(
            'Could not verify your access level for that URL.\n {}'.format(error),
            401,
            {str('WWW-Authenticate'): str('Basic realm="Login Required"')})
    return flask.redirect(next or flask.url_for("user"))
Log in as administrator

    You can use wither basic auth or form based login (via POST).

    :param username: The administrator's username
    :type username: string
    :param password: The administrator's password
    :type password: string