コード例 #1
0
    def create(self, data) -> User:
        user = User()
        user.email = data["email"]
        user.password = encrypt(data["password"])
        if "active" in data.keys():
            user.active = data["active"]
        else:
            user.active = True
        self._repository.create(user)
        self._dbcontext.commit()

        return user
コード例 #2
0
ファイル: client.py プロジェクト: wangt328/fastapi-demo
    def create_user(self, user: User) -> bool:
        if self.query(user.username) is not None:
            logger.info(f'Failed to create new user with username {user.username}, user already existed')
            return False

        user.password = self.get_hashed_password(user.password)
        user.active = True
        user.roles.append('visitor')

        self._collection.update_one({'username': user.username}, {'$set': user.dict()}, upsert=True)
        logger.info(f'Successfully create new user with username {user.username}')
        return True
コード例 #3
0
ファイル: services.py プロジェクト: GonzaloLeyton/rad
def create_user():
    # print request.json
    if not request.json or not 'email' in request.json:
        abort(400)

    new_user = User()
    new_user.name = request.json['name']
    new_user.email = request.json['email']
    new_user.active = request.json['active']
    new_user.password = request.json['password']
    new_user.hash_password()

    # Acá sacar la fecha y hora actual.
    current_time = datetime.datetime.now()
    new_user.registry_date = request.json.get('registry_date', current_time)

    # Controlamos error en caso de que se inserte un usuario que ya existe
    try:
        new_user.save()
    except Exception, e:
        print e
        abort(400)
コード例 #4
0
ファイル: services.py プロジェクト: GonzaloLeyton/rad
def create_user():
    # print request.json
    if not request.json or not 'email' in request.json:
        abort(400)

    new_user = User()
    new_user.name = request.json['name']
    new_user.email = request.json['email']
    new_user.active = request.json['active']
    new_user.password = request.json['password']
    new_user.hash_password()

    # Acá sacar la fecha y hora actual.
    current_time = datetime.datetime.now()
    new_user.registry_date = request.json.get('registry_date', current_time)
    
    # Controlamos error en caso de que se inserte un usuario que ya existe
    try:
        new_user.save()
    except Exception, e:
        print e
        abort(400)