def login(): print("\n\n flash messages") print(get_flashed_messages()) # pdb.set_trace() if request.method == 'POST': email = request.form.get('email') password = request.form.get('password') user = crud.get_user_by_email(email) if user == None: flash("User doesnt exist") return redirect('/login') elif user.password == password: session['logged_in_as'] = user.user_id # flash("Logged in!") return redirect('/') else: flash("you fake") return redirect('/login') return render_template('/login.html')
def create_user(): fname = request.form.get('fname') lname = request.form.get('lname') dob = request.form.get('dob') address = request.form.get('address') credit_score = request.form.get('credit_score') email = request.form.get('email') password = request.form.get('password') user = crud.get_user_by_email(email) if user: flash('Cannot create an account with that email. Please try again') return redirect('/create_profile') else: crud.create_user(fname, lname, dob, address, credit_score, email, password) flash('Account created! Please log in') return redirect('/login')
def job_application(): """View All Job Application of a user """ user = crud.get_user_by_email(session['email']) user_id = user.user_id job_detail = crud.get_user_job_detail(user_id) dictionary_jobs = {} for index, job in enumerate(job_detail): dictionary_jobs[index] = {} dictionary_jobs[index]['job_id'] = job.job_id, dictionary_jobs[index]['company_name'] = job.company_name, dictionary_jobs[index]['job_title'] = job.job_title, dictionary_jobs[index][ 'application_deadline'] = job.application_deadline, dictionary_jobs[index]['job_listing_url'] = job.job_listing_url, dictionary_jobs[index]['state'] = job.state, dictionary_jobs[index][ 'app_state'] = crud.get_application_state_by_applied( job.job_completed_applications[0].job_applied_id ).application_state return render_template('view-job-application.html', dictionary_jobs=dictionary_jobs)
def registration(): """View registration page.""" if request.method == 'POST': email = request.form.get('email') password = request.form.get('password') confirm_password = request.form.get('confirm-password') print(f'password: {password}, confirm password: {confirm_password}') user = crud.get_user_by_email(email) if user: flash(f'Cannot create account with email: {email}.', 'error') elif password == confirm_password: new_user = crud.create_user(email, password) crud.create_inventory(new_user.user_id, title='default') flash('Account created successfully. Please log in.', 'info') return redirect('/login') else: flash(f'Passwords do not match. Please try again.', 'error') return redirect('/register') return render_template('registration.html')
def signup(): name = request.form.get('name') email = request.form.get('email') password = request.form.get('password') new_user = crud.get_user_by_email(email) new_user = User.query.filter_by(email=email).first() # expect: <User 'bob'> # print(user) # user_password = user.password # user_name = user.name if new_user: flash('Account already exists. Try again.') else: crud.create_user(name,email, password) flash('Account created! Please log in.') return redirect('/login')
def register(): """User registration.""" if request.method == 'POST': fname = request.form.get('fname') lname = request.form.get('lname') email = request.form.get('email') password = request.form.get('password') user = crud.get_user_by_email(email) if user: flash( 'Cannot create an account with that email. Please try again.') else: crud.create_user(fname, lname, email, password) session['user'] = email session['user_id'] = user return redirect('/parks') # else: # return render_template('registration.html') return render_template('registration.html')
def check_account(): """Confirm account and take user to welcome page.""" email = request.form.get("email") password = request.form.get("password") user = crud.get_user_by_email(email) if user == None or not user.check_password(password): flash( "Email and password did not match our records. Please try again.", "danger") else: flash("Successfully logged in!", "success") session['user_name'] = f"{user.first_name} {user.last_name}" session['user_id'] = user.user_id print(f"THE SESSION FOR USER NAME IS {session['user_name']}") print(f"THE SESSION FOR USER ID IS {session['user_id']}") print(f"THE SESSION IS {session}") return redirect("/profile") return redirect("/")
def signup_user(): """Sign up a user""" lname = request.form.get('last-name') fname = request.form.get('first-name') email = request.form.get('email') password = request.form.get('password') password2 = request.form.get('password2') phone_number = request.form.get('phone') if password == password2: flash("Your passwords match!") else: flash("Re-enter your passwords so that they match") user = crud.get_user_by_email(email) """Check to see if user is already in database""" if user: flash("This email already exists. Try again") else: crud.create_user(fname, lname, email, password, phone_number) flash("Your account was created successfully") return redirect('/login')
def signup(): """Sign up a new user""" if request.method == 'GET': return render_template("signup.html") fname = request.form.get("fname") lname = request.form.get("lname") email = request.form.get("email") password = request.form.get("password") favorite_writer = request.form.get("favorite_writer") favorite_animal = request.form.get("favorite_animal") user = crud.get_user_by_email(email) if user: flash( 'It looks like you already have an account. Try to log in with your email and password.' ) return render_template('signup.html') else: crud.create_user(fname, lname, email, password, favorite_writer, favorite_animal) flash("'We've created your account. Please log in.") return render_template('/login.html')
def events(): """Rendering event template """ user = crud.get_user_by_email(session['email']) user_id = user.user_id phone = user.phone_number event_title = request.form.get('event_title') event_text = request.form.get('reminder_text') # event_time = request.form.get('event-time') #for future use event_time = datetime.now() # created_at = event_time.astimezone(get_localzone()) # reminder_status = request.form.get('reminder') reminder_status = "Sent" print('reminder_status', reminder_status) # if event_time: #for future use # created_at = datetime.strptime(str(event_time), "%Y-%m-%d %H:%M:%S.%f") # event = crud.create_event(user_id,event_title,event_text,reminder_status, created_at) if request.method == "POST": event = crud.create_event(user_id, event_title, event_text, reminder_status, event_time) if reminder_status == 'Sent': print('For testing: ******************yes******************') # twilio(phone,event_text) event_dict = {} event_objects = crud.get_event_by_user_id(user_id) for index, obj in enumerate(event_objects): event_dict[index] = {} event_dict[index]['event_title'] = obj.event_title, event_dict[index]['reminder_status'] = obj.reminder_status event_dict[index]['created_at'] = obj.created_at print(event_dict) return render_template('events.html', event_dict=event_dict)
def update_user_password(): """Allow user to update their own password from their profile screen.""" current_pw = request.form.get('current-password') new_pw_1 = request.form.get('new-password-1') new_pw_2 = request.form.get('new-password-2') existing_user = crud.get_user_by_email(session['email']) if existing_user: if existing_user.password == current_pw: if new_pw_1 == new_pw_2: crud.update_user_password(existing_user.id, new_pw_1) flash(f"Your password has been successfully updated") flash(f"Please login with your new password") session['logged_in'] = False return redirect('/') else: flash(f"sorry, the new passwords you entered do not match") flash(f"please try again") return redirect('/profile') else: flash(f"sorry, the current password you entered is not accurate") flash(f"please try again") return redirect('/profile') else: return redirect('/')
def create_account(): """Create new user.""" #information coming from create-account form #make sure that user is New and does not exist in the database # import pdb; pdb.set_trace() first_name = request.form.get("first-name") print(first_name) last_name = request.form.get("last-name") print(last_name) username = request.form.get("username") print(username) email = request.form.get("email") print(email) password = request.form.get("password") print(password) user = crud.get_user_by_email(email) print(user) print('***\n', user) bio = '' if user: flash('Cannot create an account with that email. Try again.') print('firstname =', first_name, 'lastname =', last_name, 'username ='******'password ='******'email =', email) else: crud.create_user(first_name, last_name, username, email, password, bio) flash(f'Hello {db_user.first_name}') db_user = crud.get_username(username) session['user_id'] = db_user.user_id return redirect(f'/profile/{db_user.user_id}')
def log_in_user(): """Log a user in and show them they were successful or not.""" email = request.json.get("email") password = request.json.get("password") user = crud.get_user_by_email(email.lower()) if user: if user.check_password(password): session["user_id"] = user.id return jsonify({ "success": "Successfully logged in!", "user_id": user.id, "user_first_name": user.first_name }) else: return jsonify({ "error": "Incorrect password. Please try again or create a new account." }) else: return jsonify( {"error": "Sorry, but no account exists with that email."})
def log_in(): email = request.form['email'] password = request.form['password'] user = crud.get_user_by_email(email) user_id = user.user_id print(email) print(password) print('USER PASSWORD __________________________________________________') print(user.password) print(user) print(type(user)) print(user_id) if password == user.password: session["login"] = user_id flash('login success') else: flash('Incorrect password') return redirect('/')
def register_user(): """Create a new user.""" email = request.form.get('email') password = request.form.get('password') user = crud.get_user_by_email(email) if user: flash('Cannot create an account with that email. Try again.') else: crud.create_user(email, password) flash('Account created! Please log in.') return redirect('/') # @app.route('/login', methods=['POST']) # def login(): # """User login.""" # email = request.form.get('email') # password = request.form.get('password') return redirect('/')
def get_films_from_a_given_studio(studio_id, studio_name): """Show films results from a particular production studio.""" studio = crud.get_studio_info_from_name(studio_name) films_from_studio = crud.get_titles_from_studio(studio_id) current_user = crud.get_user_by_email(session['email']) # current_user_prefs = get_current_user_preferences(current_user) current_user_preferred_genres = crud.get_user_genre_preferences_active( current_user) all_genres = crud.get_stored_genres() flash(f"{studio_name}") session['render-search-results'] = "many" return render_template( 'homepage.html', user=current_user, # user_genres=current_user_preferred_genres, all_genres=GENRES, languages=LANGUAGES, current_recommendations=films_from_studio, studio=studio)
def user(): fname = request.form.get('fname') lname = request.form.get('lname') email = request.form.get('email') password = request.form.get('password') city = request.form.get('city') state = request.form.get('state') user = crud.get_user_by_email(email) if user: """ user_account already exists or the email already in use """ return "1" else: """ no user_account exists and create a user account """ user = crud.create_user(fname, lname, email, password, city, state) # forecast_office = crud.jcity,state) # if not forecast_office: # data = forecast_data.api_data(city,state) # add_data_todb(data) return "2"
def create_account(): """Create new account and put user into session.""" fname = request.form.get('fname') lname = request.form.get('lname') email = request.form.get('email') # how do I get these to get here? print('***2' * 10, email) password = request.form.get('password') # how do I get these to get here? user = crud.get_user_by_email(email) if user: flash(f'{email} is already in the database. Please go to login.') return redirect('/login') else: new_user = crud.create_user(fname=fname, lname=lname, email=email, password=password, consent=False) session['user_id'] = new_user.user_id flash(f'thank you, {new_user.fname}, for making an account') return redirect('/add_new_phrase')
def create_user(): """Creates a user account""" email = request.form.get('email') password = request.form.get('password') username = (request.form.get('username')).lower() pw_hash = sha256_crypt.encrypt(password) user = crud.get_user_by_email(email) user_name = crud.get_user_by_username(username) if user: flash('Email already has an account. Please try again.') elif user_name: flash('Username is already in use, please select a new one.') else: user = crud.create_user(email, username, pw_hash) crud.create_collection(user, 'home', True) crud.create_collection(user, 'to_read') crud.create_collection(user, 'read') flash('Account created! Log in.') return redirect('/')
async def score_update(request: Request, response: AnswerRes, db: Session = Depends(get_db)): token = request.session.get('csrf_token') if token and response.quiz_type != '/newquiz': request.session.pop('csrf_token') if response.csrf_token == token: char_data = response.character.split('/')[-2:] char_type = char_data[0] char_name = char_data[1].split('.')[0] current_user = crud.get_user_by_email( db=db, email=request.session.get('user_email')) user_id = current_user.id result = crud.update_user_scoreboard(db=db, user_id=user_id, char_type=char_type, char_name=char_name) if not result: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="Bad Request") else: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Invalid Access") return Response(status_code=status.HTTP_204_NO_CONTENT)
def create_user(user: schemas.UserCreate, db: Session = Depends(get_db)): db_user = crud.get_user_by_email(db, email=user.email) if db_user: raise HTTPException(status_code=400, detail="Email already registered") return crud.create_user(db=db, user=user)
def rando_results(): """shows the 5 full results from the search""" print(session) user = crud.get_user_by_email(session['email']) print(user) zipcode = request.args.get('zipcode') categories = request.args.get('categories') address = request.args.get('address') price = request.args.get('price') if price == "$": price = 1 if price == "$$": price = 2 if price == "$$$": price = 3 if price == "$$$$": price = 4 print(price) #more choices hot_and_new = request.args.get('hot-and-new') if hot_and_new == "True": hot_and_new = True if hot_and_new == ("False"): hot_and_new = False if hot_and_new == None: hot_and_new = False open_now = request.args.get('open-now') if open_now == "True": open_now = True if open_now == ("False"): open_now = False if open_now == None: open_now = False reservations = request.args.get('reservations') if reservations == "True": reservations = True if reservations == ("False"): reservations = False if reservations == None: reservations = False print(reservations) print(hot_and_new) print(zipcode) businesses = yelp.yelp_api_query( zipcode, categories, address, price, hot_and_new, open_now, reservations, ) list = [] print("^^^^^^^^", businesses) if 'error' in businesses: return redirect('/search') for business in businesses['businesses']: list.append({ "name": business["name"], "id": business["id"], "categories": business["categories"][0]['title'], "rating": business["rating"], "coordinates": business["coordinates"], "price": business['price'], "address": ', '.join(business["location"]["display_address"]), "phone": business["display_phone"], "transactions": ', '.join(business["transactions"]), }) if len(list) == 5: singular_choice = random.choice(list) list.remove(singular_choice) print("@@@@@@@", singular_choice) if businesses: return render_template( 'search_results.html', rando=singular_choice, businesses=businesses, list=list, ) else: flash('Make some selections first!') return render_template('search.html') if len(list) < 5: return render_template('search_results_small.html', businesses=businesses, list=list)
def test_find_user(self): harry = crud.get_user_by_email('*****@*****.**') self.assertEqual(harry.first_name, 'Harry')
def existing_user(): """determine if the user logging in already has a profile or not. If they do, check if the password is valid. If the password is not valid flash a message. If it is, log them in and show their profile page with emission info.""" import coolclimate email = request.args.get("email") password = request.args.get("password") user_obj = crud.get_user_by_email(email) if not user_obj: flash("Please create account below!") return redirect('/') elif password: if password != user_obj.password: flash('incorrect password') return redirect('/') else: session['current_user'] = user_obj.user_id cc_calcs = coolclimate.existing_user_cc_calcs(user_obj.user_id) elect_emit = cc_calcs['input_footprint_housing_electricity_dollars'] nat_gas_emit = cc_calcs['input_footprint_housing_naturalgas_dollars'] vehicle_emit = cc_calcs['input_footprint_transportation_miles1'] public_trans_emit = cc_calcs['input_footprint_transportation_bus'] crud.change_vehicle_carbon(user_obj.user_id, vehicle_emit) crud.change_gas_carbon(user_obj.user_id, nat_gas_emit) crud.change_elect_carbon(user_obj.user_id, elect_emit) crud.change_public_trans_carbon(user_obj.user_id, public_trans_emit) month = datetime.now().month year = datetime.now().year date = datetime.now() last_month = month - 1 current_elect_emission = crud.compare_monthly_elect( user_obj.user_id, month, year) previous_elect_emission = crud.compare_monthly_elect( user_obj.user_id, last_month, year) current_nat_gas_emit = crud.compare_monthly_nat_gas( user_obj.user_id, month, year) previous_month_gas_emit = crud.compare_monthly_nat_gas( user_obj.user_id, last_month, year) current_vehicle_emit = crud.compare_monthly_vehicle_emissions( user_obj.user_id, month, year) previous_month_vehicle_emit = crud.compare_monthly_vehicle_emissions( user_obj.user_id, last_month, year) current_public_trans_emit = crud.compare_monthly_public_trans( user_obj.user_id, month, year) previous_month_public_trans_emit = crud.compare_monthly_public_trans( user_obj.user_id, last_month, year) if previous_month_gas_emit or previous_month_vehicle_emit or previous_month_public_trans_emit: show_previous_month = True else: show_previous_month = False return render_template( "profile.html", user_obj=user_obj, vehicle_emit=vehicle_emit, nat_gas_emit=nat_gas_emit, public_trans_emit=public_trans_emit, elect_emit=elect_emit, current_elect_emission=current_elect_emission, previous_elect_emission=previous_elect_emission, current_nat_gas_emit=current_nat_gas_emit, previous_month_gas_emit=previous_month_gas_emit, current_vehicle_emit=current_vehicle_emit, previous_month_vehicle_emit=previous_month_vehicle_emit, current_public_trans_emit=current_public_trans_emit, previous_month_public_trans_emit=previous_month_public_trans_emit, show_previous_month=show_previous_month, show_current_month=True)
def show_users_details(email): user = crud.get_user_by_email(email) return render_template('user_details.html', user=user)
def get_user(email: str, db: Session = Depends(get_db)): db_user = crud.get_user_by_email(db, email=email) return db_user
def get_job_details(job_id): session['job_id'] = job_id """ Display extended job details""" print("job_id:", job_id) user = crud.get_user_by_email(session['email']) user_id = user.user_id print("user_id:", user_id) job_detail = crud.get_user_job_detail(user_id) job_applied_id = crud.get_job_applied_by_job_id(job_id) dictionary_jobs = {} for job in job_detail: print("job:", job) if job.job_id == int(job_id): print("entered if") dictionary_jobs['company_name'] = job.company_name, dictionary_jobs['job_title'] = job.job_title, dictionary_jobs['application_deadline'] = job.application_deadline, dictionary_jobs['job_listing_url'] = job.job_listing_url, dictionary_jobs['state'] = job.state, dictionary_jobs['city'] = job.city, dictionary_jobs['salary'] = job.salary, dictionary_jobs['application_listed'] = job.application_listed, dictionary_jobs[ 'app_state'] = crud.get_application_state_by_applied( job.job_completed_applications[0].job_applied_id ).application_state notes_list = crud.all_note_by_job_applied_id(job_applied_id) note_dictionary = {} for index, note in enumerate(notes_list): note_dictionary[index] = {} note_dictionary[index]['note_title'] = note.note_title, note_dictionary[index]['note_text'] = note.note_text note_job_description = crud.all_jd_by_job_applied_id(job_applied_id) print(note_job_description) note_jd = {} if note_job_description != None: note_jd[1] = {} note_jd[1]['note_title'] = note_job_description.note_title, note_jd[1]['note_text'] = note_job_description.note_text note_recruit = crud.all_recruiter_by_job_applied_id(job_applied_id) note_recruiter = {} for index, note in enumerate(note_recruit): note_recruiter[index] = {} note_recruiter[index]['note_title'] = note.note_title, note_recruiter[index]['note_text'] = note.note_text # changes note_resumes = crud.all_resume_by_job_applied_id(job_applied_id) note_resume = {} for index, note in enumerate(note_resumes): note_resume[index] = {} note_resume[index]['note_title'] = note.note_title, note_resume[index]['note_text'] = note.note_text note_followups = crud.all_followup_by_job_applied_id(job_applied_id) note_followup = {} for index, note in enumerate(note_followups): note_followup[index] = {} note_followup[index]['note_title'] = note.note_title, note_followup[index]['note_text'] = note.note_text note_interviews = crud.all_interview_by_job_applied_id(job_applied_id) note_interview_question = {} for index, note in enumerate(note_interviews): note_interview_question[index] = {} note_interview_question[index]['note_category'] = note.note_category, note_interview_question[index]['note_title'] = note.note_title, note_interview_question[index]['note_text'] = note.note_text created_at = datetime.now() note_date_created = datetime.now() application_state = request.form.get('application_state') note_category = request.form.get('note_category') note_title = request.form.get('note_title') note_text = request.form.get('note_text') if application_state: application_progress = crud.create_application_progress( application_state, job_applied_id, created_at) template = f'/view-job-application/{job_id}' return redirect(template) if note_category: note = crud.create_note(job_applied_id, user_id, note_title, note_text, note_category, note_date_created) template = f'/view-job-application/{job_id}' return redirect(template) return render_template('view-application-details.html', dictionary_jobs=dictionary_jobs, note_dictionary=note_dictionary, note_jd=note_jd, note_recruiter=note_recruiter, note_resume=note_resume, note_followup=note_followup, note_interview_question=note_interview_question)
def delete_user(email: str, db: Session = Depends(get_db)): db_user = crud.get_user_by_email(db, email=email) if db_user is None: raise HTTPException(status_code=400, detail="User does not exist.") return crud.delete_user(db, email)
def update_user(user: UserCreateSchema, db: Session = Depends(get_db)): db_user = crud.get_user_by_email(db, email=user.email) if db_user: return crud.update_user(db=db, existing_user=db_user, updated_user=user) return crud.create_user(db=db, user=user)
def create_user(user: UserCreateSchema, db: Session = Depends(get_db)): db_user = crud.get_user_by_email(db, email=user.email) if db_user: raise HTTPException(status_code=400, detail="A user with that email already exists.") return crud.create_user(db=db, user=user)