Exemple #1
0
 def register_user(data) -> User:
     user = User()
     user._id = UserModel.getcounter()
     user.email = data['email']
     user.username = data['username']
     user.password = encrypt_password(data['password'])
     user.role = data['role']
     user.save()
     return user
Exemple #2
0
    async def user(self, id: int) -> User:
        """Look up the User document of a user, whose ID is given by `id`.
        If the user doesn't have a User document in the database, first create that.

        Parameters
        ----------
        id : int
            The ID of the user we want to look up

        Returns
        -------
        User
            The User document we found from the database.
        """

        user = User.objects(_id=id).first()
        # first we ensure this user has a User document in the database before continuing
        if not user:
            user = User()
            user._id = id
            user.save()
        return user