Example #1
0
    def post(self, *args, **kwargs):

        schema = Kanpai.Object({
            "username": (Kanpai.String(
                error='User first name must be string.').trim().required(
                    error='Please provide user first name.').max(
                        32, error='Maximum allowed length is 32')),
            "email":
            (Kanpai.Email(error='User email must be proper.').trim().required(
                error='Please provide user email.').max(
                    32, error='Maximum allowed length is 32')),
            "phone": (Kanpai.String(
                error='User phone number must be string.').trim().required(
                    error='Please provide user phone number.').max(
                        13, error='Maximum allowed length is 13')),
            "gender": (Kanpai.String().trim()),
            "firstname":
            Kanpai.String(error='User phone number must be string.'),
            "surename":
            Kanpai.String(error='User phone number must be string.'),
            "DOB": (Kanpai.String().trim()),
            "idname":
            Kanpai.String(error="It's not required")
        })

        data = request.get_json()
        validation_result = schema.validate(data)

        if validation_result.get('success', False) is False:
            return jsonify({
                "status": "Error",
                "errors": validation_result.get("error")
            })
        if data:
            idtypeid = session.query(IdTypeDB).filter_by(
                name=data['idname']).first()
            user = UserDB(
                username=data['username'],
                email=data['email'] if data['email'] else '*****@*****.**',
                phone=data['phone'],
                gender=data['gender'],
                firstname=data['firstname'],
                surename=data['surename'],
                DOB=data['DOB'],
                idnumber=idtypeid.id)
            db.add(user)
            db.commit()
            return jsonify({
                "statu": "success",
                "data": validation_result["data"]
            })
Example #2
0
# Search Book
def searchBook(Object):
    try:

        regex_query = {"Bookname": {"$regex": Object.get('Bookname')}}
        dbResponse = list(db.books.find(regex_query))

        return dbResponse
    except:
        print("Failed")


#############################################################
# Validators ################################################
schema = Kanpai.Object({
    "firstName":
    Kanpai.String().max(20).trim().required("First Name required"),
    "lastName":
    Kanpai.String().max(20).trim().required("Last Name required"),
    "email":
    Kanpai.Email().required("email required"),
    "roles":
    Kanpai.String().max(5).trim().required("User Role Required"),
    "password":
    Kanpai.String().max(20).trim().required("pass required")
})
#############################################################

if __name__ == "__main__":
    app.run()
Example #3
0
from kanpai import Kanpai

userRegister = Kanpai.Object({
    "name": Kanpai.String().trim().required(),
    "email": Kanpai.Email().required(),
    "password": Kanpai.String().trim().required(),
    "role": Kanpai.String().trim().required()
})


userLogin = Kanpai.Object({
    "email": Kanpai.Email().required(),
    "password": Kanpai.String().trim().required()
})

inputTask = Kanpai.Object({
    "user_id": Kanpai.Number().required(),
    "title": Kanpai.String().required(),
    "description": Kanpai.String().required(),
    "duedate": Kanpai.String().required(),
    "status": Kanpai.String().required()
})