Example #1
0
def add_user(email, name='Paul Anderson'):
    """Setup a new user for the database with a default institute."""
    connect('variantDatabase', host='localhost', port=27017)

    institute = Institute.objects.first()
    Whitelist(email=email).save()
    # create a default user
    user = User(email=email,
                name=name,
                roles=['admin'],
                institutes=[institute])
    user.save()
Example #2
0
File: api.py Project: CGHQ/uscout
def init():
    """Initialize Scout database with an admin user account."""
    admin_email = request.form['email']
    admin_name = request.form.get('name', admin_email)
    admin_institutes = request.form.getlist('institutes')

    try:
        logger.debug('whitelist the email account')
        whitelist_obj = Whitelist(email=admin_email)
        whitelist_obj.save()
    except NotUniqueError:
        logger.debug('email already whitelisted')

    try:
        logger.debug('setup the Scout admin account')
        user_obj = User(email=admin_email, name=admin_name,
                        institutes=admin_institutes, roles=['admin'])
        user_obj.save()
    except NotUniqueError:
        logger.debug('user account already created')
        return jsonify(success=False)
    return jsonify(**prepare_json(user_obj.to_mongo()))
    def init(self, admin_mail=None, admin_name=None, admin_institutes=None):
        """Initialize Scout database with an admin user account."""
        admin_config = self.config["scout"]["admin"]
        admin_mail = admin_mail or admin_config["email"]
        admin_name = admin_name or admin_config.get("name")
        admin_institutes = admin_institutes or admin_config.get("institutes")

        try:
            logger.debug("whitelist the email account")
            whitelist_obj = Whitelist(email=admin_mail)
            whitelist_obj.save()
        except NotUniqueError:
            logger.debug("email already whitelisted")

        try:
            logger.debug("setup the Scout admin account")
            user_obj = User(email=admin_mail, name=admin_name, institutes=(admin_institutes or []), roles=["admin"])
            user_obj.save()
        except NotUniqueError:
            logger.debug("user account already created")
            return None

        return prepare_json(user_obj.to_mongo())