def public_create_user(): data = request.get_json() error = False try: new_user = User(name=str(data['user']), last_name=str(data['last_name'])) new_user.insert() except Exception: error = True db.session.rollback() print(sys.exc_info()) finally: db.session.close() if error: abort(422) else: return jsonify({ "success": True, "message": 'User was successfully added to database.' })
def callback_handling(): # Get authorization token token = auth0.authorize_access_token() access_token = token['access_token'] # Store access token in Flask session session[constants.ACCESS_TOKEN] = access_token resp = auth0.get('userinfo') userinfo = resp.json() session[constants.JWT_PAYLOAD] = userinfo session[os.environ['PROFILE_KEY']] = { 'user_id': userinfo['sub'], 'name': userinfo['name'], 'picture': userinfo['picture'] } # Store user email in session session[constants.USER_EMAIL] = userinfo["email"] email = session['user_email'] # If user is new, add to users table res = User.query.filter(User.email == email).one_or_none() # Location information not available for manual registered account try: loc = userinfo['locale'] except Exception: loc = None if res is None: user = User(email=session['user_email'], name=userinfo['name'], location_iso2=loc) user.insert() res = User.query.filter(User.email == email).one() user_id = res.id session[constants.USER_ID] = user_id return redirect("/home")