def create_examples(): """Adds missing app examples to all users. """ from pykern import pkio from sirepo import feature_config from sirepo import server from sirepo import simulation_db import flask server.init() for d in pkio.sorted_glob(simulation_db.user_dir_name('*')): if _is_src_dir(d): continue uid = simulation_db.uid_from_dir_name(d) # create a mock session flask.session = { server._ENVIRON_KEY_BEAKER: {}, } server.session_user(uid) for sim_type in feature_config.cfg.sim_types: simulation_db.verify_app_directory(sim_type) names = map( lambda x: x['name'], simulation_db.iterate_simulation_datafiles( sim_type, simulation_db.process_simulation_list, { 'simulation.isExample': True, })) for s in simulation_db.examples(sim_type): if s.models.simulation.name not in names: simulation_db.save_new_example(s)
def auth_login(req): from sirepo import server if cfg.auth_secret: auth_hash(req, verify=True) # DEPRECATED elif not server.cfg.enable_bluesky: util.raise_not_found('bluesky is not enabled') sid = req.simulationId sim_type = req.simulationType path = simulation_db.find_global_simulation( sim_type, sid, checked=True, ) server.session_user(simulation_db.uid_from_dir_name(path))
def _update_database(user_data, oauth_type): with _db_serial_lock: user = User.query.filter_by(oauth_id=user_data['id'], oauth_type=oauth_type).first() session_uid = server.session_user(checked=False) if user: if session_uid and session_uid != user.uid: simulation_db.move_user_simulations(user.uid) user.user_name = user_data['login'] user.display_name = user_data['name'] server.session_user(user.uid) else: if not session_uid: # ensures the user session (uid) is ready if new user logs in from logged-out session pkdlog('creating new session for user: {}', user_data['id']) simulation_db.simulation_dir('') user = User(server.session_user(), user_data['login'], user_data['name'], oauth_type, user_data['id']) _db.session.add(user) _db.session.commit() return user