def register(): form = RegistrationForm(request.form) if request.method == "POST" and form.validate(): name = form.name.data last_name = form.last_name.data username = form.username.data email = form.email.data phone_number = form.phone_number.data password = sha256_crypt.encrypt(form.password.data) add_user({ "name": name, "last_name": last_name, "username": username, "email": email, "phone_number": phone_number, "password": password }) flash("Başarıyla Kayıt Oldunuz", "success") return redirect(url_for("login")) else: return render_template("register.html", form=form)
def register_user(): """Registers a new user.""" data = request.get_json(force=True) first_name = data['firstname'] last_name = data['lastname'] email = data['email'] password = data['password'] print(data) user = crud.add_user(first_name, last_name, email, password) print(user) if user: clear_session() status = "You have created your account. Please log in." return jsonify(status)
def register_user(): """add new user""" data = request.get_json() print(data) email = data['email'] password = data['password'] confirmpswd = data['confirmpswd'] if ((email != '') and (password != '') and (confirmpswd == password)): print(f"email: {email}") existing_user = crud.check_user(email) print(f"existing_user: {existing_user}") if existing_user: return jsonify("Email already in use, cannot create account.") else: new_user = crud.add_user(email, password) return jsonify("Account created! please log in") else: print("in else") return jsonify("Enter valid email and password")
def get_new_user_info(): """Get new user info.""" fname = request.form.get('fname') lname = request.form.get('lname') email = request.form.get('email') phone = request.form.get('phone') password = request.form.get('password') dob = datetime.today() gender = request.form.get('gender') new_user = crud.add_user(fname, lname, email, phone, dob, gender, password) session['user_id'] = new_user.user_id return render_template('profile.html', fname=fname, lname=lname, email=email, phone=phone, password=password, dob=dob, gender=gender)
def build_mock(db_string, k=10): engine = create_engine(db_string) # Bind the engine to the metadata of the Base class so that the # declaratives can be accessed through a DBSession instance Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) # A DBSession() instance establishes all conversations with the database # and represents a "staging zone" for all the objects loaded into the # database session object. Any change made against the objects in the # session won"t be persisted into the database until you call # session.commit(). If you"re not happy about the changes, you can # revert all of them back to the last commit by calling # session.rollback() session = DBSession() # define constants CRIS = "cris" AMIT = "amit" ADAM = "adam" KEENAN = "keenan" descriptions = { CRIS: "I recently graduated with my bachelor's and will be working/volunteering fulltime. I do not smoke and I am clean (might misplace things though but)! I am also very sociable and enjoy cooking and baking 🙂 Hobbies I have are playing the violin, drawing, and watching kdramas! Feel free to message me for further questions ", AMIT: "We are pretty chill and very neat and respectful people ", ADAM: "Studying Data Science and Mathematics at the University of California, San Diego. Well-versed in Python (SKLearn, Pandas, Dask, etc..), R and Excel.Looking for an internship from June 2021 to September 2021 in the field of Data Science/Analytics where I can combine my mathematical/statistical knowledge and programming abilities with my strong writing and communication skills. ", KEENAN: "Software engineer with an attention to detail and strong people skills. Seeking full-time Software Engineering positions. " } # Add mock users cris = add_user(CRIS, "*****@*****.**", datetime.now(), "858-911-1198", descriptions[CRIS], "Third", "Data Science", session) amit = add_user(AMIT, "*****@*****.**", datetime.now(), "858-911989", descriptions[AMIT], "Third", "Data Science", session) adam = add_user(ADAM, "*****@*****.**", datetime.now(), "858-65386", descriptions[ADAM], "Third", "Computer Science and Engineering", session) keenan = add_user(KEENAN, "*****@*****.**", datetime.now(), "858-4675432", descriptions[KEENAN], "Grad", "Computer Science and Engineering", session) users = [adam, cris, amit, keenan] file_dir = "app/assets/room_mock_images/" # for user in users: # # create icons # icon_path = "app/assets/profile_default_icons/" # selected_icon = random.choice(os.listdir(icon_path)) # path_name = "/".join(["user"+str(user.id), # "profile", "headshot.jpg"]) # upload_file_wname(icon_path+selected_icon, "houseit", path_name) def generateMock(k=30): attributes = [] for attr in others: attributes.append(add_attribute(attr, "other", session)) for attr in facilities: attributes.append(add_attribute(attr, "facilities", session)) move_combos = [(datetime(2018, 6, 1), datetime(2018, 7, 1)) for _ in range(k)] move_ins = [ add_move_in(elem[0], elem[1], session) for elem in move_combos ] mock_room_types = [random.choice(room_types) for _ in range(k)] mock_prices = [random.randint(200, 1000) for _ in range(k)] houses = [random.choice(addresses_generate) for _ in range(k)] people = [users[i % len(users)] for i in range(k)] negotiables = [random.choice([True, False]) for _ in range(k)] mock_stay_periods = [ add_stay_period(datetime(2018, 6, 1), datetime(2018, 7, 1), session) for _ in range(k) ] mock_eta = [ str(random.choice(list(range(1, 30)))) + " mins" for _ in range(k) ] mock_baths = [random.choice(list(range(1, 4))) for _ in range(k)] mock_beds = [random.choice(list(range(1, 4))) for _ in range(k)] mock_attrs = [ list(set(random.sample(attributes, 8))) for _ in range(k) ] mock_rooms = [] for i in range(k): address_object = add_address(mock_eta[i], houses[i], session) temp_room = add_room(datetime.now(), mock_room_types[i], mock_prices[i], negotiables[i], "Damn it LOOOOOOL", mock_stay_periods[i], address_object, people[i], move_ins[i], mock_beds[i], mock_baths[i], session) for temp_attr in mock_attrs[i]: add_house_attribute(temp_room, temp_attr, session) mock_rooms.append(temp_room) # for i in range(k): # path_name = "/".join(["user"+str(people[i].id), "housing", # str(mock_rooms[i].id)]) # random_files = random.sample(os.listdir(file_dir), 4) # for idx, file_name in enumerate(random_files): # upload_file_wname(file_dir+file_name, "houseit", # path_name+"/"+str(idx)+".jpg") generateMock(k)
"""Script to seed database.""" import os import json from random import choice, randint from datetime import datetime import crud import model import server os.system('dropdb mytodo') os.system('createdb mytodo') model.connect_to_db(server.app) model.db.create_all() for n in range(10): email = f'user{n}@test.com' password = f'test0{n}' user = crud.add_user(email, password)
# define constants CRIS = "cris" AMIT = "amit" ADAM = "adam" KEENAN = "keenan" descriptions = { CRIS: "I recently graduated with my bachelor's and will be working/volunteering fulltime. I do not smoke and I am clean (might misplace things though but)! I am also very sociable and enjoy cooking and baking 🙂 Hobbies I have are playing the violin, drawing, and watching kdramas! Feel free to message me for further questions ", AMIT: "We are pretty chill and very neat and respectful people ", ADAM: "Studying Data Science and Mathematics at the University of California, San Diego. Well-versed in Python (SKLearn, Pandas, Dask, etc..), R and Excel.Looking for an internship from June 2021 to September 2021 in the field of Data Science/Analytics where I can combine my mathematical/statistical knowledge and programming abilities with my strong writing and communication skills. ", KEENAN: "Software engineer with an attention to detail and strong people skills. Seeking full-time Software Engineering positions. " } # Add mock users cris = add_user(CRIS, "*****@*****.**", datetime.now(), "858-911", descriptions[CRIS], 'Third', "Data Science", session) amit = add_user(AMIT, "*****@*****.**", datetime.now(), "858-911989", descriptions[AMIT], 'Third', "Data Science", session) adam = add_user(ADAM, "*****@*****.**", datetime.now(), "858-65386", descriptions[ADAM], 'Third', "Computer Science and Engineering", session) keenan = add_user(KEENAN, "*****@*****.**", datetime.now(), "858-4675432", descriptions[KEENAN], 'Grad', "Computer Science and Engineering", session) users = [adam, cris, amit, keenan] file_dir = '../assets/room_mock_images/' for user in users: