def authenticate_user(self, email, password): user = User.query.filter_by(email=email).first() # Checking if user credentials are correct if user and user.authenticate(password=password): return user # Throw and Error on failure. raise TinyHRError("Invalid Credentials", 401)
def wrapper(*args, **kwargs): try: data = params(request.json) data.validate() except DataError as err: error = serialize_errors(err.messages) raise TinyHRError(error) return fn(*args, **kwargs)
def download_candidate_resume(pk): resume = UserService().get_user_resume(pk) if resume: return send_file(resume, as_attachment=True, attachment_filename='resume.pdf', mimetype="application/pdf") raise TinyHRError("Resume was not uploaded.", 404)
def create(self, user_details, profile_details=None, **kwargs): try: # Put User Details user = User(**user_details, **kwargs) DB.session.add(user) DB.session.commit() # Hash User's Password user.hashify_password(user.password) if profile_details: profile = CandidateProfile(**profile_details, user_id=user.id) DB.session.add(profile) DB.session.add(user) DB.session.commit() except IntegrityError: raise TinyHRError( f"User with email '{user_details['email']}' already exist.") return user
def wrapper(*args, **kwargs): if request.files and allowed_types: for filename, file_obj in request.files.items(): if file_obj.mimetype not in allowed_types: raise TinyHRError("Uploaded file type is not allowed.", 422) return fn(*args, **kwargs)
def decorated_function(*args, **kwargs): if not (current_user and current_user.is_admin): raise TinyHRError("You are not allowed to perform this action", 403) return fn(*args, **kwargs)
def upload_resume(): if not (request.files and request.files.get('resume', None)): raise TinyHRError({"resume": "This field is required"}) resume_file = request.files.get('resume') UserService().upload_resume(current_user, resume_file) return {}, 202