How to use the dbutils.User.create function in DBUtils

To help you get started, we’ve selected a few DBUtils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jensl / critic / quickstart.py View on Github external
if initialize_database:
        import dbutils
        import auth

        db = dbutils.Database()
        cursor = db.cursor()

        cursor.execute("""INSERT INTO systemidentities (key, name, anonymous_scheme,
                                                        authenticated_scheme, hostname,
                                                        description, installed_sha1)
                               VALUES ('main', 'main', 'http', 'http', 'localhost', 'Main', ?)""",
                       (subprocess.check_output("git rev-parse HEAD", shell=True).strip(),))

        db.commit()

        admin = dbutils.User.create(
            db,
            name=arguments.admin_username,
            fullname=arguments.admin_fullname,
            email=arguments.admin_email,
            email_verified=None,
            password=auth.hashPassword(arguments.admin_password))

        if not arguments.testing:
            if not quiet:
                print

            print ("Created administrator user %r with password '1234'"
                   % data["installation.admin.username"])

        cursor.execute("""INSERT INTO userroles (uid, role)
                               SELECT %s, name
github jensl / critic / src / auth / oauth.py View on Github external
RETURNING id""",
                    (self.name, account, email))
                external_user_id, = updating_cursor.fetchone()
                user_id = None

        user = None

        if user_id is not None:
            user = dbutils.User.fromId(db, user_id)
        else:
            if auth.isValidUserName(username) \
                    and self.configuration.get("bypass_createuser"):
                try:
                    dbutils.User.fromName(db, username)
                except dbutils.NoSuchUser:
                    user = dbutils.User.create(
                        db, username, fullname, email, email_verified=None,
                        external_user_id=external_user_id)
                    user.sendUserCreatedMail("wsgi[oauth/%s]" % self.name,
                                             { "provider": self.name,
                                               "account": account })

        if user is None:
            token = auth.getToken()

            with db.updating_cursor("externalusers") as updating_cursor:
                updating_cursor.execute(
                    """UPDATE externalusers
                          SET token=%s
                        WHERE id=%s""",
                    (token, external_user_id))
github jensl / critic / src / operation / registeruser.py View on Github external
verify_email_address = provider.configuration["verify_email_addresses"]

            # Reset 'email' column in 'externalusers': we only need it to detect
            # if the user changed the email address in the "Create user" form.
            # Also reset the 'token' column, which serves no further purpose
            # beyond this point.
            with db.updating_cursor("externalusers") as cursor:
                cursor.execute("""UPDATE externalusers
                                     SET email=NULL,
                                         token=NULL
                                   WHERE id=%s""",
                               (external_user_id,))

        email_verified = False if email and verify_email_address else None

        user = dbutils.User.create(
            db, username, fullname, email, email_verified, password,
            external_user_id=external_user_id)

        if email_verified is False:
            sendVerificationMail(db, user)

        user.sendUserCreatedMail("wsgi[registeruser]", external)

        auth.createSessionId(db, req, user)

        return OperationResult()
github jensl / critic / src / maintenance / criticctl.py View on Github external
email = None
    else:
        email = use_argument_or_ask(arguments.email, "Email address:")
        if not email.strip():
            email = None

    if arguments.password is NoPassword:
        hashed_password = None
    else:
        if arguments.password is None:
            password = inpututils.password("Password:")
        else:
            password = arguments.password
        hashed_password = auth.hashPassword(password)

    dbutils.User.create(db, name, fullname, email, email_verified=None,
                        password=hashed_password)

    print "%s: user added" % name
github jensl / critic / src / background / githook.py View on Github external
def getUser(db, user_name):
    if user_name == configuration.base.SYSTEM_USER_NAME:
        return dbutils.User.makeSystem()
    try:
        return dbutils.User.fromName(db, user_name)
    except dbutils.NoSuchUser:
        if configuration.base.AUTHENTICATION_MODE == "host":
            email = getUserEmailAddress(user_name)
            return dbutils.User.create(
                db, user_name, user_name, email, email_verified=None)
        raise