def login(): """Login using naive db or LDAP (work on it @priest)""" if current_user.is_authenticated: app.logger.error("Shouldn't login when auth") flash("Shouldn't login when auth", "error") return redirect(url_for("devices")) if request.method == "POST": try: user = User.get(User.username == request.form["username"]) except User.DoesNotExist: user = None if user is not None and user.auth(request.form["password"]) is True: login_user(user) app.logger.info("logged in: {}".format(user.username)) flash( "Hello {}! You can now claim and manage your devices.".format( current_user.username ), "success", ) return redirect(url_for("devices")) else: app.logger.info("failed log in: {}".format(request.form["username"])) flash("Invalid credentials", "error") return render_template("login.html", **common_vars_tpl)
def callback(): token = oauth.sso.authorize_access_token() user_info = oauth.sso.parse_id_token(token) if user_info: print(user_info) try: user = User.get(User.username == user_info["preferred_username"]) except User.DoesNotExist: user = None app.logger.warning("no user: {}".format( user_info["preferred_username"])) if user is not None: login_user(user) app.logger.info("logged in: {}".format(user.username)) flash( "Hello {}! You can now claim and manage your devices.".format( current_user.username), "success", ) return redirect(url_for("devices")) else: app.logger.info("failed log in: {}".format( user_info["preferred_username"])) flash("Invalid credentials", "error") return redirect(url_for("login"))