コード例 #1
0
    def post(self):
        data = UserRegister.parser.parse_args()
        if UserModel.search_from_database_by_username(data["username"]):
            return {"message": "The username has been used"}, 400

        UserModel.add_to_database(UserModel(**data))
        return {"message": "User is successfully created"}, 201
コード例 #2
0
def identity(payload):
    user = UserModel.search_from_database_by_id(payload["identity"])
    admin = AdminModel.search_from_database_by_id(payload["identity"])

    if UserModel.search_from_database_by_username(user.username):
        return user
    elif AdminModel.search_from_database_by_username(admin.username):
        return admin
コード例 #3
0
    def post(self, username):
        data = Profile.parser.parse_args()

        user = UserModel.search_from_database_by_username(username)
        user.update_attributes(**data)

        UserModel.update_to_database(user)

        return {"message": "Update profile successfully"}, 200
コード例 #4
0
def authentication(username, password):
    user = UserModel.search_from_database_by_username(username)
    admin = AdminModel.search_from_database_by_username(username)
    if user and safe_str_cmp(user.password, password):
        return user
    elif admin and safe_str_cmp(admin.password, password):
        return admin
コード例 #5
0
    def post(self, name):
        data = Product.parser.parse_args()
        data.update({"status": False})

        catalog = CatalogModel.search_from_database_by_type(
            data["catalog_type"])
        del data["catalog_type"]

        ProductModel.add_to_database_by_catalog(ProductModel(**data), catalog)

        product = sorted(ProductModel.search_from_database_by_name(
            data["name"]),
                         key=lambda product: product.id)[-1]
        username = UserModel.search_from_database_by_id(
            data["user_id"]).username
        url = "http://192.168.2.107:8080/" + username + "/" + str(product.id)
        product.update_img_url(url)

        return {
            "message": "Product posted successfully",
            "img_vid_url": url
        }, 201
コード例 #6
0
 def get(self):
     lenders = []
     for lender_id, first_name, last_name, gender, \
         birthday, email, username, password, phone, address, \
         job, free_trial_start, free_trial_end, average_star in UserModel.get_top_lender():
         lender = {
             "id": lender_id,
             "first_name": first_name,
             "last_name": last_name,
             "gender": gender,
             "birthday": birthday.\
                 strftime("%Y/%m/%d") if isinstance(birthday, datetime.date) else birthday,
             "email": email,
             "username": username,
             "password": password,
             "phone": phone,
             "address": address,
             "job": job,
             "free_trial_start": free_trial_start,
             "free_trial_end": free_trial_end,
             "average_star": average_star
         }
         lenders.append(lender)
     return {"top_lender": lenders}, 200
コード例 #7
0
 def get(self, username):
     return UserModel.search_from_database_by_username(username).json(), 200
コード例 #8
0
 def get(self):
     return {
         "users": [user.json() for user in UserModel.get_all_user()]
     }, 200