I have developed a user management system using Flask using Flask-Security. I would like to add a Watson chatbot to the page, and it should check if the user is authenticated or not. This will be done inside Flask-Security in its login module as follows:
@app.route('/login', methods=['GET', 'POST'])
def login():
# Here we use a class of some kind to represent and validate our
# client-side form data. For example, WTForms is a library that will
# handle this for us, and we use a custom LoginForm to validate.
form = LoginForm()
if form.validate_on_submit():
# Login and validate the user.
# user should be an instance of your `User` class
login_user(user)
flask.flash('Logged in successfully.')
next = flask.request.args.get('next')
# is_safe_url should check if the url is safe for redirects.
# See http://flask.pocoo.org/snippets/62/ for an example.
if not is_safe_url(next):
return flask.abort(400)
return flask.redirect(next or flask.url_for('index'))
return flask.render_template('login.html', form=form)
Is it possible when a user starts asking questions from the chat interface (e.g. asking from the date of registration in the system) we redirect him/her to the login page of Flask and after authentication, we get back to conversation dialog and pull data related to the authenticated user (e.g. the record timestamp of user profile)?