

@app.route('/login', methods=['GET', 'POST'])
def handleLogin():
    app.logger.info(('handleLogin [%s]' % request.method))
    form = LoginForm(me='', client_id=cfg['client_id'], redirect_uri=('%s/success' % cfg['baseurl']), from_uri=request.args.get('from_uri'))
    if form.validate_on_submit():
        app.logger.info(('me [%s]' % form.me.data))
        me = baseDomain(form.me.data)
        authEndpoints = ninka.indieauth.discoverAuthEndpoints(me)
        if ('authorization_endpoint' in authEndpoints):
            authURL = None
            for url in authEndpoints['authorization_endpoint']:
                authURL = url
                break
            if (authURL is not None):
                url = ParseResult(authURL.scheme, authURL.netloc, authURL.path, authURL.params, urllib.urlencode({
                    'me': me,
                    'redirect_uri': form.redirect_uri.data,
                    'client_id': form.client_id.data,
                    'scope': 'post',
                    'response_type': 'id',
                }), authURL.fragment).geturl()
                if (db is not None):
                    key = ('login-%s' % me)
                    data = db.hgetall(key)
                    if data:
                        db.delete(('token-%s' % data['token']))
                        db.hdel(key, 'token')
                    db.hset(key, 'from_uri', form.from_uri.data)
                    db.hset(key, 'redirect_uri', form.redirect_uri.data)
                    db.hset(key, 'client_id', form.client_id.data)
                    db.hset(key, 'scope', 'post')
                    db.expire(key, cfg['auth_timeout'])
                return redirect(url)
        else:
            return ('insert fancy no auth endpoint found error message here', 403)
    templateData['title'] = 'Sign In'
    templateData['form'] = form
    return render_template('login.jinja', **templateData)

dataset/ETHPy150Open bear/python-indieweb/indieweb.py handleLogin/original