コード例 #1
0
ファイル: __init__.py プロジェクト: bentipping/victims-web
    def create_user(self, username, password, roles=[]):
        """
        Shortcut for creating users.
        """
        if username not in self._created_users:
            self._created_users.append(username)

        self.account = Account.objects(username=username).first()

        if self.account:
            return

        account = Account()
        account.username = username
        account.password = generate_password_hash(
            password,
            application.app.config['BCRYPT_LOG_ROUNDS']
        )
        account.active = True
        account.roles = roles
        account.save()

        self.account = account
コード例 #2
0
ファイル: user.py プロジェクト: bentipping/victims-web
def create_user(username, password, email=None, roles=[]):
    """
    Create a new user

    :Parameters:
        - `username`: User Name
        - `password`: Plain-text password
        - `roles`: A list of roles to assign the user
        - `email`: The user's email address
    """
    new_user = Account()
    new_user.username = username
    new_user.set_password(password)
    if email is not None:
        new_user.email = email.strip()

    new_user.roles = roles
    new_user.active = True

    new_user.validate()
    new_user.save()

    return User(username)