def create_session(): if not is_logged_in(): flash('You must be logged in to perform this operation.', 'danger') return redirect('/') if request.method.upper() == 'GET': return render_template('create_session.html') elif request.method.upper() == 'POST': session_name = request.form['session_name'] if session_name is None or len(session_name) == 0: flash('Invalid session name.', 'danger') return redirect('/') else: db = Database() if db.does_session_name_exist(session_name): flash('Session name already exists.', 'danger') return redirect('/') else: session_id = db.create_session(session_name, flask_session['user_id']) set_current_session(session_id, session_name) return redirect('/')
def ext_create_new_session_name(api_key, session_name): logging.debug("EXTERNAL: Create new Session with name") db = Database() user = db.get_user_by_api_key(api_key) if user is None: return "Provided API key ('{}') is not associated with any registered user".format( api_key), HTTPStatus.UNAUTHORIZED.value if db.does_session_name_exist(session_name): return "Provided session name ('{}') already exists".format( session_name), HTTPStatus.UNAUTHORIZED.value logging.debug("Creating new session: %s (userid: %s)", session_name, user['user_id']) session_id = db.create_session(session_name, user['user_id']) logging.debug("New session id: %s", session_id) set_current_session(session_id, session_name) return "New Session ID: '{}'".format(session_id)