def update_localisation(): # handle authetication problems handle_authentication(False) form = Users.forms.Localisation() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # if needed add the town to Town table if form.town.data not in Town.list_all(): form.town.data = form.town.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(Town(town=form.town.data)) # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_localisation.html', title="Localisation", form=form, fields=fields, country_list=Country.list_all(), town_list=Town.list_all())
def update_searched_status(search_id): # handle connections problems handle_authentication(False) search = Search.query.filter_by(id=search_id).first() # authetication problem if current_user.id != search.user_id: flash("sorry this is not your search, you are not allowed", "danger") return redirect(url_for("main.edhunt")) form = SearchsForms.Status() fields = extract_fields(form) if request.method == 'GET': # prefill all fields for field in fields: k = getattr(form, field) k.data = getattr(search, field) else: if form.validate_on_submit(): # update user attrs for field in fields: d = getattr(form, field).data if isinstance(d, list): d = ", ".join(d) setattr(search, field, d) db.session.commit() flash("Search updated", "success") return redirect( url_for('searchs.manage_search', search_id=search.id)) else: flash_all_errors(form) return render_template('search/update/update_searched_status.html', title="Update Statuts", form=form, search_id=search.id)
def questionnaire_1(token): form = MainForms.Form_1() fields = extract_fields(form) if request.method == 'GET': pass else: if form.validate_on_submit(): if not token: token = token_hex(16) quest = Questionnaire(token=token) db.session.add(quest) db.session.commit() else: quest = Questionnaire.query.filter_by(token=token).first() if not quest: flash("Désolé, une erreur c'est produite", "danger") return redirect(url_for("main.home")) for field in fields: setattr(quest, field, getattr(form, field).data) db.session.commit() return redirect(url_for("main.questionnaire_2", token=token)) else: flash_all_errors(form) return render_template('main/questionnaire_1.html', title="Inscription 1/6", form=form, token=token, text=MainText.questionnaire.q1, back=None)
def update_language(): # handle authetication problems handle_authentication(False) form = Users.forms.Languages() fields = extract_fields(form) if request.method == 'GET': # prefill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # update user attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_language.html', title="Langues", form=form, fields=fields)
def update_expectation(): # handle authetication problems handle_authentication(False) form = Users.forms.Expectation() fields = extract_fields(form) if request.method == 'GET': # prefill the form form.employed.data = current_user.employed form.search.data = current_user.search form.order.data = current_user.order form.automation.data = current_user.automation else: if form.validate_on_submit(): # update user info current_user.employed = form.employed.data current_user.sub_employed = form.sub_employed.data current_user.search = form.search.data current_user.order = form.order.data current_user.automation = form.automation.data return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_expectation.html', title="Attentes", fields=fields, form=form)
def update_resume(n): # handle authetication problems handle_authentication(False) form = Users.forms.Resume() fields = extract_fields(form) if request.method == 'GET': # prefill the form pass else: if form.validate_on_submit(): # update user info _resume_doc = save_resume(form.resume_doc.data) setattr(current_user, f"resume{n}_doc", _resume_doc) if form.resume_name.data: setattr(current_user, f"resume{n}_name", form.resume_name.data) else: setattr(current_user, f"resume{n}_name", f"my_resume_{n}") return commit_flash_redirect('users.manage_user') else: if form.errors: flash_all_errors(form) return render_template('user/update/update_resume.html', title="CVs", fields=fields, form=form)
def questionnaire_5(token): quest = Questionnaire.query.filter_by(token=token).first() if not quest: flash("Désolé, une erreur c'est produite", "danger") return redirect(url_for("main.home")) form = MainForms.Form_5() fields = extract_fields(form) if request.method == 'GET': pass else: if form.validate_on_submit(): for field in fields: setattr(quest, field, getattr(form, field).data) db.session.commit() # flash("Super Merci!", "success") return redirect(url_for("main.questionnaire_6", token=token)) else: flash_all_errors(form) return render_template('main/questionnaire_5.html', title="Inscription 5/6", form=form, token=token, text=MainText.questionnaire.q5, back="4")
def update_user(): handle_authentication(False) form = Users.forms.Update() fields = extract_fields(form) if request.method == 'GET': # prefill the form form.username.data = current_user.username form.email.data = current_user.email form.password.data = "" form.confirm_password.data = "" else: if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') current_user.username = form.username.data current_user.email = form.email.data current_user.password = hashed_password db.session.commit() flash('Your account has been modified! Please re-log in', 'success') logout_user() return redirect(url_for('users.login')) else: flash_all_errors(form) return render_template('user/update/update_user.html', title='Compte', fields=fields, form=form)
def _register_user(token): if Params.FORCE_QUESTIONNAIRE: q = Questionnaire.query.filter_by(token=token).first() if not q: flash("Hummmm, petite futée, tu t'es crue la plus maline?") return redirect(url_for('main.questionnaire_1')) if Params.DISABLE_REGISTER: try: logout_user() except: pass return redirect(url_for('main.connection', token=token)) handle_authentication(True) form = Users.forms.Register() fields = extract_fields(form) if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = Users.table(username=form.username.data, email=form.email.data, password=hashed_password) previous_fields = [ "search", "employed", "contract", "diploma_type", "xp_at_work", "status", "diploma_year", "search", "sector", "zip_code", "function", "position", "management", "rem", "diploma_level" ] for field in previous_fields: setattr(user, field, getattr(q, field)) db.session.add(user) db.session.commit() # CREATE PLATEFORMS for p in Plateforms.list_all: Plate = getattr(Plateforms.tables, p) db.session.add(Plate(user_id=user.id)) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('user/register_user.html', title='Inscription', fields=fields, form=form)
def update_plateform(plateform): plateform_name = plateform # handle authetication problems handle_authentication(False) form = Plateforms.forms.Update() fields = extract_fields(form) plateform = getattr( Plateforms.tables, plateform_name).query.filter_by(user_id=current_user.id).first() if request.method == 'GET': if plateform: for field in fields: getattr(form, field).data = getattr(plateform, field) else: if form.validate_on_submit(): if not plateform: plateform = getattr(Plateforms.tables, plateform_name)(user_id=current_user.id) db.session.add(plateform) db.session.commit() if form.account.data == "Oui": form.sub_account.data = "Oui" plateform = getattr(Plateforms.tables, plateform_name).query.filter_by( user_id=current_user.id).first() for field in fields: setattr(plateform, field, getattr(form, field).data) db.session.commit() # if form.connection.data != "On": # flash(f"Sorry did not allow to login to {plateform}", # "danger") # return redirect(url_for("users.manage_user")) for i in ["autorisation", "good_user", "edhunt_integrity"]: if getattr(form, i).data != "Oui": flash( f"Sorry you must accept credentials to login to {plateform_name}", "danger") return redirect(url_for("plateforms.manage_plateforms")) return commit_flash_redirect('plateforms.manage_plateforms') else: flash_all_errors(form) return render_template('plateform/update_plateform.html', title=plateform_name, form=form, fields=fields)
def update_work_experience(): # handle authetication problems handle_authentication(False) form = Users.forms.WorkExperience() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # if needed add the comapny and job to relative tables if form.company.data not in Company.list_all(): form.company.data = form.company.data.upper().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") db.session.add(Company(company=form.company.data)) db.session.commit() if form.job.data not in Job.list_all(): form.job.data = form.job.data.capitalize().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") db.session.add(Job(job=form.job.data)) db.session.commit() if form.key_words.data: kwords = form.key_words.data kwords = kwords.lower().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") kwords = ", ".join([i.strip() for i in kwords.split(",")]) form.key_words.data = kwords # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) db.session.commit() return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_work_experience.html', title="Experience professionnelle", form=form, fields=fields, company_list=Company.list_all(), job_list=Job.list_all())
def delete_user(): handle_authentication(False) form = Users.forms.Delete() fields = extract_fields(form) if form.validate_on_submit(): user_id = current_user.id logout_user() user = Users.table.query.filter_by(id=user_id).first() db.session.delete(user) db.session.commit() flash("User deleted", "success") return redirect(url_for('main.home')) return render_template('user/delete_user.html', title="Suppression du compte", fields=fields, text=Users.text.delete_user, form=form)
def login(): handle_authentication(True) form = Users.forms.Login() fields = extract_fields(form) if Params.DISABLE_LOGIN: try: logout_user() except: pass return redirect(url_for('main.connection', token="error")) if form.validate_on_submit(): user = Users.table.query.filter_by(email=form.email.data).first() if not user: flash('Login Unsuccessful. Please check email', 'danger') return redirect(url_for('users.login')) good_passwd = bcrypt.check_password_hash(user.password, form.password.data) if not good_passwd: flash('Login Unsuccessful. Please check password', 'danger') return redirect(url_for('users.login')) if user and good_passwd: login_user(user, remember=form.remember.data) next_page = request.args.get('next') flash('You have been logged in!', 'success') return redirect(next_page) if next_page else redirect( url_for('users.manage_user')) else: raise AttributeError("something went wrong with login") return render_template( 'user/login_user.html', title='Connexion', form=form, fields=fields, )
def update_searched_language(search_id): # handle connections problems handle_authentication(False) search = Search.query.filter_by(id=search_id).first() # authetication problem if current_user.id != search.user_id: flash("sorry this is not your search, you are not allowed", "danger") return redirect(url_for("main.edhunt")) form = SearchsForms.Languages() fields = extract_fields(form) if request.method == 'GET': # prefill all fields form.other_languages.data = search.other_languages else: if form.validate_on_submit(): # update user attrs if form.other_languages.data: langs = form.other_languages.data langs = langs.capitalize().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") langs = ", ".join([i.strip() for i in langs.split(",")]) form.other_languages.data = langs for field in fields: d = getattr(form, field).data if isinstance(d, list): d = ", ".join(d) setattr(search, field, d) db.session.commit() flash("Search updated", "success") return redirect( url_for('searchs.manage_search', search_id=search.id)) else: flash_all_errors(form) return render_template('search/update/update_searched_language.html', title="Update Languages", form=form, search_id=search.id)
def questionnaire_6(token): quest = Questionnaire.query.filter_by(token=token).first() if not quest: flash("Désolé, une erreur c'est produite", "danger") return redirect(url_for("main.home")) if token != "error": form = MainForms.Form_6() fields = extract_fields(form) else: form = None if request.method == 'GET': pass else: if form.validate_on_submit(): # u = User.query.filter_by(email=form.email.data).all() # if u: # flash("Vous avez déja un compte!", "success") # return redirect(url_for("main.login_user")) # else: # flash("Contact créé!", "success") # quest.email = form.email.data # quest.phone = form.phone.data # quest.hour = form.hour.data # db.session.commit() # return redirect(url_for('main.home')) # flash("success", "success") for field in fields: setattr(quest, field, getattr(form, field).data) db.session.commit() return redirect(url_for('main.bienvenue', token=token)) return render_template('main/questionnaire_6.html', title="Inscription 6/6", text=MainText.questionnaire.q6, form=form, token=token, back="5")
def register_user(): if Params.FORCE_QUESTIONNAIRE: return redirect(url_for('main.questionnaire_1')) if Params.DISABLE_REGISTER: try: logout_user() except: pass return redirect(url_for('main.connection', token="error")) handle_authentication(True) form = Users.forms.Register() fields = extract_fields(form) if form.validate_on_submit(): # create user hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = Users.table(username=form.username.data, email=form.email.data, password=hashed_password) db.session.add(user) db.session.commit() # CREATE PLATEFORMS for p in Plateforms.list_all: Plate = getattr(Plateforms.tables, p) db.session.add(Plate(user_id=user.id)) db.session.commit() flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('users.login')) return render_template('user/register_user.html', title='Inscription', fields=fields, form=form)
def contact(): form = MainForms.Contact() fields = extract_fields(form) if request.method == 'GET': pass else: if form.validate_on_submit(): contact = Contact() for field in fields: setattr(contact, field, getattr(form, field).data) db.session.add(contact) db.session.commit() flash("Message envoyé !", "success") return redirect(url_for("main.home")) else: flash_all_errors(form) return render_template('main/contact.html', title="Contact", form=form, text=MainText.contact)
def update_diploma(): # handle authetication problems handle_authentication(False) form = Users.forms.Diploma() fields = extract_fields(form) if request.method == 'GET': # pre fill all fields for field in fields: k = getattr(form, field) k.data = getattr(current_user, field) else: if form.validate_on_submit(): # handle town and school if needed if form.diploma_town.data not in Town.list_all(): form.diploma_town.data = form.diploma_town.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(Town(town=form.diploma_town.data)) if form.diploma_school.data not in School.list_all(): form.diploma_school.data = form.diploma_school.data.capitalize()\ .strip().replace(" ", " ").replace(" ", " ") db.session.add(School(school=form.diploma_school.data)) # update User attrs for field in fields: setattr(current_user, field, getattr(form, field).data) return commit_flash_redirect('users.manage_user') else: flash_all_errors(form) return render_template('user/update/update_diploma.html', title="Diplôma", form=form, fields=fields, town_list=Town.list_all(), school_list=School.list_all())
def update_searched_job(search_id): # handle connections problems handle_authentication(False) search = Search.query.filter_by(id=search_id).first() # authetication problem if current_user.id != search.user_id: flash("sorry this is not your search, you are not allowed", "danger") return redirect(url_for("main.edhunt")) form = SearchsForms.Job() fields = extract_fields(form) if request.method == 'GET': # prefill all fields for field in fields: k = getattr(form, field) k.data = getattr(search, field) else: if form.validate_on_submit(): # handle company (upper....) form.company.data = form.company.data.strip().upper()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") form.not_company.data = form.not_company.data.strip().upper()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") # if needed update Comany Table company_list = form.company.data.split(",") not_company_list = form.not_company.data.split(",") for comp_list in [company_list, not_company_list]: for _company in comp_list: _company = _company.strip().upper().replace("-", " ")\ .replace(" ", " ").replace(" ", " ") if _company not in Company.list_all(): db.session.add(Company(company=_company)) if form.company.data: comps = form.company.data comps = comps.upper().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") comps = ", ".join([i.strip() for i in comps.split(",")]) form.company.data = comps if form.not_company.data: comps = form.not_company.data comps = comps.upper().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") comps = ", ".join([i.strip() for i in comps.split(",")]) form.not_company.data = comps if form.not_key_words.data: kwords = form.not_key_words.data kwords = kwords.lower().strip()\ .replace("-", " ").replace(" ", " ").replace(" ", " ") kwords = ", ".join([i.strip() for i in kwords.split(",")]) form.not_key_words.data = kwords # update user attrs for field in fields: d = getattr(form, field).data if isinstance(d, list): d = ", ".join(d) setattr(search, field, d) db.session.commit() flash("Search updated", "success") return redirect( url_for('searchs.manage_search', search_id=search.id)) else: flash_all_errors(form) return render_template('search/update/update_searched_job.html', title="Update Job", form=form, company_list=Company.list_all(), search_id=search.id)