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 register(): if not current_user.is_authenticated: return redirect(url_for("users.login")) elif not current_user.is_admin: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, is_admin=form.admin.data, password=hashed_password) db.session.add(user) db.session.commit() flash('Your account has been created. You are able to log in.!', 'success') return redirect(url_for('users.login')) return render_template('admin/register.html', title='Register', form=form)
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")