def auth_create_an_application():
        if (envs['test'] == app_param['env']):
            data = request.form.to_dict()
        else:
            data = request.get_json()
        #auth = request.authorization

        if not data or not data.get("policy") or not data.get("origin") \
                or not data.get("expiredTime") or not data.get("userId") :
            return make_response('could not verify', 401, {'Authentication': 'insufficient informations'})

        authjwt = AuthJwt(data["policy"], data["origin"], AuthGradeController.__authGradeService.unique_id(10),
                          data["userId"], data["expiredTime"])
        user =UserService().get_user_by_id(authjwt.userId)

        if user:
            #token = self.__authGradeService.generate_token(authjwt)
            token = create_limit_token(AuthGradeService(), authjwt)
            authjwt.token = token
            return jsonify({'token': token})
            authjwt.slug = AuthGradeController.__authGradeService.unique_id()
            #create application
            result = AuthGradeController.__authGradeService.create_an_application(authjwt)

            #return jsonify({'token': token.decode('UTF-8')})
            return  make_response(jsonify({"student": result}))
            #return jsonify({'token': token})

        return make_response('could not verify', 401, {'Authorization': 'Basic realm: "login required"'})
 def update_professor_by_id(id):
     if (envs['test'] == app_param['env']):
         data = request.form.to_dict()
     else:
         data = request.get_json()
     professor = None
     if data.get('username') and  data.get('password') and data.get('fullname') and data.get('hiredate') and data.get('salary'):
        # data["hiredate"] = parse(str(data["hiredate"])).date()
         professor = Professor(data['username'], data['password'], data['fullname'], data['salary'], data['hiredate'], None)
     else:
         return make_response('invalid input', 500, {'input': "invalid input"})
     if  professor is not None:
         professor = ProfessorController.__professorService.update_user_by_id(id,professor)
     return make_response(jsonify({"professor": professor}))
 def update_product_by_id(self, id):
     if (envs['test'] == app_param['env']):
         data = request.form.to_dict()
     else:
         data = request.get_json()
     product = None
     if data.get('title') and  data.get('productDescription') and data.get('productBrand') \
             and data.get('price') and data.get('userId'):
         product = Product(data['title'], data['productDescription'], data['productBrand'], data['price'], data['userId'])
     else:
         return make_response('invalid input', 500, {'input': "invalid input"})
     if  product is not None:
         product = self.__productService.update_product_by_id(id,product)
     return make_response(jsonify({"product": product}))
 def create_product():
     if (envs['test'] == app_param['env']):
         data = request.form.to_dict()
     else:
         data = request.get_json()
     result = ProductController.__productService.create_product(data)
     return make_response(jsonify({"product": result}),200)
 def create_professor():
     if (envs['test'] == app_param['env']):
         data = request.form.to_dict()
     else:
         data = request.get_json()
     #data["hiredate"] = parse(str(data["hiredate"])).date()
     #return data
     result = ProfessorController.__professorService.create_user(data)
     return make_response(jsonify({"professor": result}),200)
 def update_student_by_id(id):
     if (envs['test'] == app_param['env']):
         data = request.form.to_dict()
     else:
         data = request.get_json()
     student = None
     if data.get('username') and data.get('password') and data.get(
             'fullname') and data.get('register'):
         student = Student(data['username'], data['password'],
                           data['fullname'], data['register'], None)
         #student.id = id
         #return make_response(jsonify({"student": student.username}))
     else:
         return make_response('invalid input', 500,
                              {'input': "invalid input"})
     if student:
         print('the students {0}'.format(student))
         student = StudentController.__studentService.update_user_by_id(
             id, student)
     return make_response(jsonify(student))
    def create_student():

        if (envs['test'] == app_param['env']):
            data = request.form.to_dict()
            #print(f"{envs['test']} {app_param['env']}")
        else:
            data = request.get_json()
        #print("result = {0}".format(data))
        data["slug"] = None

        result = StudentController.__studentService.create_user(data)
        return make_response(jsonify(result), 200)
 def delete_professor_by_id(id):
     response = ProfessorController.__professorService.delete_user_by_id(id)
     return make_response({'result': response}, 204)
 def get_professor_by_id(id):
     professor = ProfessorController.__professorService.get_user_by_id(id)
     return make_response(jsonify({"professor": professor}))
 def get_all_professors():
     professors = ProfessorController.__professorService.get_all_users()
     return make_response(jsonify({"professor": professors}))
 def delete_product_by_id(id):
     response = ProductController.__productService.delete_product_by_id(id)
     return make_response({'result': response}, 204)
 def get_product_by_id(id):
     product = ProductController.__productService.get_product_by_id(id)
     return make_response(jsonify({"product": product}))
 def get_all_products():
     products = ProductController.__productService.get_all_products()
     return make_response(jsonify({"product": products}))
 def delete_student_by_id(id):
     response = StudentController.__studentService.delete_user_by_id(id)
     return make_response({'result': response}, 204)
 def get_student_by_id(id):
     student = StudentController.__studentService.get_user_by_id(id)
     return make_response(jsonify(student))
 def get_all_students():
     students = StudentController.__studentService.get_all_users()
     return make_response(jsonify(students))