def post(): """ Destroy session token """ # server.logger.info("logout") headers = request.headers if request.headers.get('Authorization'): # server.logger.info(headers.get('Authorization') ) # server.logger.info(JWT.decode(headers.get('Authorization').split()[1]) ) try: encoded_token = JWT.decode( headers.get('Authorization').split()[1]) res = jsonify({ "data": { "logout": "true", "valid_session_token": "true" }, "status": "success" }) return make_response(res, 200) except: res = jsonify({ "data": [], "status": "error", "message": "Invalid session token" }) return make_response(res, 401) else: res = jsonify({ "data": [], "status": "error", "message": "No Authorization session token" }) return make_response(res, 401)
def get(page_number, per_page_data): """ Return an interviewer key information based on his name """ args = request.args # checking session token headers = request.headers if request.headers.get('Authorization') is None: res = jsonify({ "data": [], "status": "error", "message": "Require session token" }) return make_response(res, 401) if JWT.is_valid(headers.get('Authorization')) is False: res = jsonify({ "data": [], "status": "error", "message": "Invalid session token" }) return make_response(res, 401) # checking session token ends try: id = args['id'] if id == "all": interviewer = interviewerRepository.getAllIds( page_number, per_page_data) return jsonify(interviewer) else: interviewer = interviewerRepository.getById(id=id) res = jsonify({"data": interviewer.json, "status": "success"}) except: res = jsonify(interviewer) return make_response(res, 200)
def delete(id): """ delete an interviewer based on the sent information """ # checking session token headers = request.headers if request.headers.get('Authorization') is None: res = jsonify({ "data": [], "status": "error", "message": "Require session token" }) return make_response(res, 401) if JWT.is_valid(headers.get('Authorization')) is False: res = jsonify({ "data": [], "status": "error", "message": "Invalid session token" }) return make_response(res, 401) # checking session token ends repository = interviewerRepository() interviewer = repository.delete(id=id) if interviewer.get('status') == "error": res = jsonify(interviewer) return make_response(res, 404) else: return jsonify(interviewer)
def post(): """ upload image """ # checking session token headers = request.headers if request.headers.get('Authorization') is None: res = jsonify({"data": [], "status": "error", "message": "Require session token"}) return make_response(res, 401) if JWT.is_valid(headers.get('Authorization')) is False: res = jsonify({"data": [], "status": "error", "message": "Invalid session token"}) return make_response(res, 401) # checking session token ends # checking if the file is present or not. if 'file' not in request.files: res = jsonify({"data": [], "status": "error", "message": "No file found"}) return make_response(res, 404) try: app_root = '..' + os.path.dirname(os.path.abspath(__file__)) target = os.path.join(app_root, '../../static/img') if not os.path.isdir(target): os.makedirs(target) img = request.files['file'] img_name = secure_filename(img.filename) destination = '/'.join([target, img_name]) img.save(destination) res = jsonify({"data": {"message" : "file Successfully uploaded"}, "status": "success"}) return make_response(res, 200) except Exception as e: res = jsonify({"data": [], "status": "error", "message": e }) return make_response(res, 404)
def post( email, password): """ create session token """ # server.logger.info("login") interview = interviewRepository.getByEmail( email=email ) # server.logger.info(interview) if interview is not None: # hash password password_hashed = Bcrypt.get_hashed_password(password) valid_password = Bcrypt.check_password(password, interview.password) # server.logger.info(valid_password) if valid_password: payload = {"email": interview.email, "createdAt": int(time.time() * 1000)} session_token = JWT.encode(payload) session_token = str(session_token)[1:].replace("'", "") # server.logger.info(session_token) res = jsonify({"data": {"session_token": str(session_token)}, "status": "success"}) return make_response(res, 200) else: res = jsonify({"data": [], "status": "error", "message": "incorrect password"}) return make_response(res, 401) else: res = jsonify({"data": [], "status": "error", "message": "incorrect email"}) return make_response(res, 401)
def put(id, last_name, first_name, email, password, alt_email, alt_phone_no, phone_no, department, designation, profile_picture_url, country, state, city, address, created_date, last_updated_date): """ Update an interview based on the sent information """ # checking session token headers = request.headers if request.headers.get('Authorization') is None: res = jsonify({"data": [], "status": "error", "message": "Require session token"}) return make_response(res, 401) if JWT.is_valid(headers.get('Authorization')) is False: res = jsonify({"data": [], "status": "error", "message": "Invalid session token"}) return make_response(res, 401) # checking session token ends # hash password if password is not None: password = Bcrypt.get_hashed_password(password) repository = interviewRepository() interview = repository.update( id=id, last_name=last_name, first_name=first_name, email=email, password=password, alt_email=alt_email, alt_phone_no=alt_phone_no, phone_no=phone_no, department=department, designation=designation, profile_picture_url=profile_picture_url, country=country, state=state, city=city, address=address, created_date=created_date, last_updated_date=last_updated_date) try: res = jsonify({"data": interview.json, "status": "success"}) except: res = jsonify({"interview": interview}) return make_response(res, 200)
def post(last_name, first_name, email, password, alt_email, alt_phone_no, phone_no, department, designation, profile_picture_url, created_date, last_updated_date, country, state, city, address): """ Create an interviewer based on the sent information """ # checking session token headers = request.headers if request.headers.get('Authorization') is None: res = jsonify({ "data": [], "status": "error", "message": "Require session token" }) return make_response(res, 401) if JWT.is_valid(headers.get('Authorization')) is False: res = jsonify({ "data": [], "status": "error", "message": "Invalid session token" }) return make_response(res, 401) # checking session token ends # hash password password_hashed = Bcrypt.get_hashed_password(password) interviewer = interviewerRepository.create( last_name=last_name, first_name=first_name, email=email, password=password_hashed, alt_email=alt_email, alt_phone_no=alt_phone_no, phone_no=phone_no, department=department, designation=designation, profile_picture_url=profile_picture_url, country=country, state=state, city=city, address=address, created_date=created_date, last_updated_date=last_updated_date) # server.logger.info(jsonify(interviewer.json)) res = jsonify({"data": interviewer.json, "status": "success"}) return make_response(res, 200)