def new_user(): username = "******" password = "******" email = "*****@*****.**" hashedPassword = bcrypt.generate_password_hash(password).decode('utf-8') user = User(username=username, email=email, password=hashedPassword) return user
def activate_account(token): user = User.verify_reset_token(token) if user is None: flash("That is an invalid or expired token", 'warning') return redirect(url_for('users.register')) user.active = True db.session.commit() flash("Your account has been activated, now you're able to login", "success") return redirect(url_for('users.login'))
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashedPassword = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashedPassword, active=False) db.session.add(user) db.session.commit() send_activate_email(user) flash("Please activate your account, an activation link has been sent to your email", "info") return redirect(url_for("users.login")) return render_template("register.html", title="Register", form=form)
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashedPassword = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashedPassword) db.session.add(user) db.session.commit() flash("Your account has been created! You are now able to login!", "success") return redirect(url_for("users.login")) return render_template("register.html", title="Register", form=form)
def reset_token(token): if current_user.is_authenticated: return redirect(url_for('main.home')) user = User.verify_reset_token(token) if user is None: flash("That is an invalid or expired token", 'warning') return redirect(url_for('users.reset_request')) form = ResetPasswordForm() if form.validate_on_submit(): hashedPassword = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user.password = hashedPassword db.session.commit() flash("Your password has been updated! You are now able to login!", "success") return redirect(url_for("users.login")) return render_template('reset_password.html', form=form, user=user)
def init_db(db, bcrypt): """Clear existing data and create new tables.""" with current_app.app_context(): db.drop_all() db.create_all() username = "******" password = "******" email = "*****@*****.**" hashedPassword = bcrypt.generate_password_hash("Admin").decode('utf-8') user = User(username=username, email=email, password=hashedPassword) db.session.add(user) db.session.commit() print(f"[+] Generate admin user") print(f" [>] username = {username}") print(f" [>] email = {email}") print(f" [>] password = {password}") RoomList = [ [ 'Dicranodontium Moss', 'FMIPA', 'Auditorium', 'Universal exuding focus group' ], [ 'Colorado Four O' 'clock', 'FEMA', 'Auditorium', 'Customer-focused reciprocal groupware' ], [ 'Thurber' 's Sandpaper Plant', 'FEM', 'Auditorium', 'Centralized homogeneous superstructure' ], [ 'Leadville Milkvetch', 'FEMA', 'Ruang Terbuka', 'Customer-focused mobile toolset' ], [ 'Rough Draba', 'SB', 'Ruang Terbuka', 'Multi-tiered homogeneous middleware' ], [ 'Acorn Buckwheat', 'FEM', 'Ruang Terbuka', 'Advanced contextually-based secured line' ], [ 'Sawleaf Bush Penstemon', 'REKTORAT', 'Ruang Kelas', 'Organized zero defect architecture' ], [ 'Guiana Brosimum', 'FEMA', 'Ruang Terbuka', 'Horizontal actuating architecture' ], [ 'Gregg' 's Tube Tongue', 'FEMA', 'Ruang Terbuka', 'Expanded fresh-thinking synergy' ], [ 'Plantainleaf Dubautia', 'FMIPA', 'Ruang Terbuka', 'Enterprise-wide zero administration database' ], [ 'Canada Lily', 'FEMA', 'Ruang Kelas', 'Object-based analyzing emulation' ], [ 'Alyssumleaf Phlox', 'FEMA', 'Ruang Terbuka', 'Cloned multi-state conglomeration' ], [ 'Hybrid Oak', 'FEMA', 'Ruang Kelas', 'Realigned bandwidth-monitored focus group' ], [ 'Sparse-flowered Bog Orchid', 'FEMA', 'Auditorium', 'Horizontal responsive service-desk' ], [ 'Chamomile', 'FMIPA', 'Ruang Terbuka', 'Robust analyzing success' ], [ 'Common Starlily', 'FMIPA', 'Ruang Terbuka', 'Virtual 4th generation throughput' ], [ 'Southern Globethistle', 'FEMA', 'Ruang Kelas', 'Customizable content-based contingency' ], [ 'Hornwort', 'FAHUTAN', 'Ruang Terbuka', 'Cross-group needs-based open architecture' ], [ 'Panic Veldtgrass', 'SB', 'Ruang Terbuka', 'Multi-layered value-added middleware' ], [ 'Arctoparmelia Lichen', 'FEMA', 'Ruang Terbuka', 'Cross-group secondary intranet' ], [ 'Dicranoweisia Moss', 'REKTORAT', 'Ruang Kelas', 'Multi-layered client-driven policy' ], [ 'Alkanna', 'FEM', 'Auditorium', 'Vision-oriented zero tolerance internet solution' ], [ 'Vaupesia', 'FAHUTAN', 'Ruang Kelas', 'Grass-roots exuding encoding' ], [ 'Caloncoba', 'FMIPA', 'Ruang Terbuka', 'Multi-lateral maximized interface' ], [ 'Great Lakes Dewberry', 'FEM', 'Ruang Kelas', 'Phased high-level capability' ], ] for i in range(len(RoomList)): print(f"[+] Creating Room {i}") name = RoomList[i][0] location = RoomList[i][1] room_type = RoomList[i][2] information = RoomList[i][3] room = Room(name=name, location=location, room_type=room_type, information=information) db.session.add(room) db.session.commit() print(f"[+] To login as admin the following credential") print(f" [>] email = {email}") print(f" [>] password = {password}")
def create_mockData(app, create_admin=True): with app.app_context(): if (create_admin): username = "******" password = "******" email = "*****@*****.**" hashedPassword = bcrypt.generate_password_hash("Admin").decode( 'utf-8') user = User(username=username, email=email, password=hashedPassword, active=True) db.session.add(user) db.session.commit() print(f"[+] Generate admin user") print(f" [>] username = {username}") print(f" [>] email = {email}") print(f" [>] password = {password}") for i, user_data in enumerate(UserList): print(f"[+] Generating user {i}") username = user_data["username"] password = user_data["password"] email = user_data["email"] user = User(username=username, email=email, password=password, active=True) db.session.add(user) db.session.commit() room_id_list = [] for i, (roomdat, pic) in enumerate(zip(RoomList, PersonInCharge)): print(f"[+] Creating Room {i}") name = roomdat["name"] location = roomdat["location"] room_type = roomdat["room_type"] information = roomdat["information"] list_image_file = [] for j in range(5): name_image_file = f"room_image_{random.randint(1, 60)}.jpeg" image_file = Room_Image_File(name=name_image_file) list_image_file.append(image_file) pic_name = pic["name"] pic_number = pic["number"] pic_username = pic["username"] pic_email = pic["email"] pic_password = pic["password"] list_person_in_charge = [] person_in_charge = Person_In_Charge(name=pic_name, number=pic_number, username=pic_username, email=pic_email, password=pic_password, active=True) list_person_in_charge.append(person_in_charge) room = Room(name=name, location=location, room_type=room_type, information=information, capacity=random.randint(100, 150), price=random.randint(100000, 300000), person_in_charge=list_person_in_charge, image_file=list_image_file) room_id_list.append(room.id) db.session.add(room) db.session.commit() # Membuat room untuk keperluan demo print(f"[+] Creating mock data for demo") fmipa_auditorium_information = """FMIPA menyediakan fasilitas auditorium untuk menunjang penyelenggaraan kegiatan bagi civitas IPB dan umum. Auditorium FMIPA berlokasi di Jalan Agatis Kampus Dramaga IPB. Fasilitas Standar: 1. LCD Projector Screen dan Sound System 2. Air Conditioner 3. 250 Kursi Standar Auditorium FMIPA Cocok digunakan untuk acara besar yang membutuhkan ruangan yang besar dengan budget yang minimal. """ list_image_file_auditorium_fmipa = [] for j in range(5): name_image_file = f"au_fmipa_{j+1}.jpg" image_file = Room_Image_File(name=name_image_file) list_image_file_auditorium_fmipa.append(image_file) list_person_in_charge_audit_fmipa = [] hashedPassword = bcrypt.generate_password_hash("RPLkelompok9!").decode( 'utf-8') person_in_charge_audit_fmipa = Person_In_Charge( name="Bambang Satriya", number="+6281334623784", username="******", email="*****@*****.**", password=hashedPassword, active=True) list_person_in_charge_audit_fmipa.append(person_in_charge_audit_fmipa) room = Room(name="Auditorium FMIPA", location="FMIPA", room_type="Auditorium", information=fmipa_auditorium_information, capacity=150, price=100000, person_in_charge=list_person_in_charge_audit_fmipa, image_file=list_image_file_auditorium_fmipa) db.session.add(room) db.session.commit() print(f"[+] Booking demo room") for event in EventList: user = User.query.filter_by(id=random.randint(2, 149)).first() daterand = datetime.strptime( random_date("2021/1/1", "2021/12/31", random.random()), "%Y/%m/%d").date() isBooked = Booked.query.filter_by(room_booked=room, date=daterand).first() if (isBooked): continue booked = Booked(booked_by=user, room_booked=room, date=daterand, event=event["event"], organization=event["organization"], phone=event['phone'], email=event['email'], name=event["name"]) db.session.add(booked) db.session.commit() for i in range(len(RoomList)): print(f"[+] Booking room {i}") for event in EventList: user = User.query.filter_by(id=random.randint(2, 149)).first() room = Room.query.filter_by(id=room_id_list[i]).first() daterand = datetime.strptime( random_date("2021/1/1", "2021/12/31", random.random()), "%Y/%m/%d").date() isBooked = Booked.query.filter_by(room_booked=room, date=daterand).first() if (isBooked): continue booked = Booked(booked_by=user, room_booked=room, date=daterand, event=event["event"], organization=event["organization"], phone=event['phone'], email=event['email'], name=event["name"]) db.session.add(booked) db.session.commit() if (create_admin): print(f"[+] To login as admin, use the following credential") print(f" [>] email = [email protected]") print(f" [>] password = Admin")