def signup(): """Creates a new user for Genocrowd """ new_user = {} local_auth = LocalAuth(ca, session) data = request.get_json() local_auth.check_inputs(data) if not local_auth.get_error(): # FIXME is it safe to pass role? where does it come from? new_user = local_auth.add_user_to_database(data['username'], data['email'], data['password'], data['grade'], data['role']) new_user['_id'] = str(new_user['_id']) session['user'] = new_user return kill_apollo_session( jsonify({ 'error': local_auth.get_error(), 'errorMessage': local_auth.get_error_message(), 'user': new_user }))
def create_app(config='config/genocrowd.ini', app_name='genocrowd', blueprints=None): """Create the Genocrowd app Parameters ---------- config : str, optional Path to the config file app_name : str, optional Application name blueprints : None, optional Flask blueprints Returns ------- Flask Genocrowd Flask application """ conf = configparser.ConfigParser() conf.read(config) sentry_dsn = None try: sentry_dsn = conf['sentry']['server_dsn'] except Exception: pass if sentry_dsn: version = get_distribution('genocrowd').version name = get_distribution('genocrowd').project_name sentry_sdk.init(dsn=sentry_dsn, release="{}@{}".format(name, version), integrations=[FlaskIntegration(), CeleryIntegration()]) app = Flask(app_name, static_folder='static', template_folder='templates') app.iniconfig = FlaskIni() with app.app_context(): app.iniconfig.read(config) proxy_path = None try: proxy_path = app.iniconfig.get('genocrowd', 'reverse_proxy_path') app.config['REVERSE_PROXY_PATH'] = proxy_path except Exception: pass mongo_dbname = app.iniconfig.get('flask', 'mongo_dbname') app.config['MONGO_DBNAME'] = mongo_dbname mongo_uri = app.iniconfig.get('flask', 'mongo_uri') app.config['MONGO_URI'] = mongo_uri if not mongo_uri: raise Exception("Missing mongo_uri in config file") if not mongo_dbname: raise Exception("Missing mongo_dbname in config file") app.mongo = PyMongo(app) app.bcrypt = Bcrypt(app) users = app.mongo.db.users app.mongo.db.genes app.mongo.db.answers groups = app.mongo.db.groups app.genocrowd_admin_email = app.iniconfig.get('genocrowd', 'genocrowd_admin_email') app.genocrowd_admin_password = app.iniconfig.get( 'genocrowd', 'genocrowd_admin_password') app.apollo_admin_email = app.iniconfig.get('genocrowd', 'apollo_admin_email') app.apollo_admin_password = app.iniconfig.get('genocrowd', 'apollo_admin_password') app.apollo_dataset_path = app.iniconfig.get('genocrowd', 'apollo_dataset_path') app.apollo_org_id = app.iniconfig.get('genocrowd', 'apollo_org_id') app.apollo_url = app.iniconfig.get('genocrowd', 'apollo_url') # We don't want ending slash if app.apollo_url.endswith("/"): app.apollo_url = app.apollo_url[:-1] app.apollo_url_ext = app.iniconfig.get('genocrowd', 'apollo_url_ext') # We don't want ending slash if app.apollo_url_ext.endswith("/"): app.apollo_url_ext = app.apollo_url_ext[:-1] configure_logging(app) if users.find_one() is None: # Create default admin user local_auth = LocalAuth(app, None) local_auth.add_user_to_database('admin', app.genocrowd_admin_email, app.genocrowd_admin_password, 'admin', 'admin') if blueprints is None: blueprints = BLUEPRINTS for blueprint in blueprints: app.register_blueprint(blueprint) if groups.find_one() is None: # Initiate the groups database data = Data(app, None) data.initiate_groups() if proxy_path: ReverseProxyPrefixFix(app) return app