示例#1
0
def update_manager_profile(profile_id): 
	update_profile_form = UpdateProfileForm()
	branch = get_current_branch()
	manager_profile = Profile.query.get(profile_id)
	if update_profile_form.validate_on_submit():
		profile_id = update_profile_form.data.get("id")
		profile = Profile.query.get(profile_id)
		if manager_profile == profile:
			data = update_profile_form.data
			first_name = data.get("first_name")
			last_name = data.get("last_name")
			email = data.get("email")
			telephone_code = data.get("telephone_code")		
			telephone = data.get("telephone")		
			profile.first_name = first_name
			profile.last_name = last_name
			new_email = email
			new_telephone = join_telephone(telephone_code, telephone)
			update_profile_email_and_telephone(profile, new_email, new_telephone)
			db.session.commit()
			flash("Manager updated", "success")
		else:
			flash("An error occured!", "danger")

	else:
		flash(f"{update_profile_form.errors}", "danger")

	return redirect(request.referrer)
示例#2
0
def get_profile_credit():
	user = current_user
	profile = user.profile
	update_profile_credit_form = UpdateProfileCreditForm(profile=profile)
	if request.method == "POST":
		if update_profile_credit_form.validate_on_submit():
			# get info
			data = update_profile_credit_form.data
			telephone_code = data.get("telephone_code")		
			telephone = data.get("telephone")
			amount = data.get("amount")
			telephone = join_telephone(telephone_code, telephone, joiner="")
			success = process_momo_pay(telephone, amount)
			update_profile_credit_process_patch_template = render_template('profile/update-profile-credit-process-patch.html', success=success)
			data = {
				"form_templates": {
					"#updateProfileCreditFormPatch": update_profile_credit_process_patch_template
				}
			}
			
		else:
			update_profile_credit_patch_template = render_template('profile/update-profile-credit-patch.html', update_profile_credit_form=update_profile_credit_form)
			data = {
				"form_templates": {
					"#updateProfileCreditFormPatch": update_profile_credit_patch_template
				}
			}
		return data
		
	
	return render_template('profile/profile-credit.html', update_profile_credit_form=update_profile_credit_form)
示例#3
0
def update_profile():
	user = current_user
	profile = user.profile
	
	if profile:
		code, telephone = split_telephone(profile.telephone)
		profile.telephone = telephone
		profile.telephone_code = code

	update_profile_form = UpdateProfileForm(obj=user.profile)
	update_user_password_form = UpdateUserPasswordForm(current_user=user)
	if update_profile_form.validate_on_submit():
		data = update_profile_form.data
		first_name = data.get("first_name")
		last_name = data.get("last_name")
		email = data.get("email")
		telephone_code = data.get("telephone_code")		
		telephone = data.get("telephone")		
		profile.first_name = first_name
		profile.last_name = last_name
		new_email = email
		new_telephone = join_telephone(telephone_code, telephone)
		update_profile_email_and_telephone(profile, new_email, new_telephone)
		db.session.commit()
		flash("Profile updated.", "success")
		
	return render_template('profile/passenger-profile.html', update_user_password_form=update_user_password_form, update_profile_form=update_profile_form)
示例#4
0
def create_payment_checkout(bus_id):
    bus = Bus.query.filter_by(id=bus_id).first()
    create_passenger_booking_form = CreatePassengerBookingForm(
        data=request.form, bus=bus)

    profile = None
    if current_user.is_authenticated:
        profile = current_user.profile

    if create_passenger_booking_form.validate_on_submit():
        # create payment checkout
        data = create_passenger_booking_form.data
        grid_id = data.get("grid_id")
        pricing_id = data.get("pricing_id")
        passenger_name = data.get("passenger_name")
        passenger_email = data.get("passenger_email")
        telephone_code = data.get("telephone_code")
        passenger_telephone = data.get("passenger_telephone")
        telephone = join_telephone(telephone_code, passenger_telephone)

        grid = Grid.query.filter_by(id=grid_id).first()
        pricing = Pricing.query.filter_by(id=pricing_id).first()

        app_charge = round(pricing.price * app.config.get("APP_CHARGE"))

        payment = Payment(amount=pricing.price,
                          app_charge=app_charge,
                          method="ONLINE",
                          passenger_name=passenger_name,
                          passenger_email=passenger_email,
                          passenger_telephone=telephone,
                          grid_number=grid.number,
                          bus_number=bus.number,
                          bus_id=bus.id,
                          grid_id=grid.id,
                          company=bus.company,
                          profile=profile,
                          journey=bus.journey,
                          pricing=pricing)

        db.session.add(payment)
        db.session.commit()
        return redirect(url_for('payment.get_payment', payment_id=payment.id))

    return render_template(
        "bus/passenger-bus.html",
        bus=bus,
        create_passenger_booking_form=create_passenger_booking_form)
示例#5
0
def create_cashier_profile(): 
	create_profile_form = CreateProfileForm()
	branch = get_current_branch()
	if create_profile_form.validate_on_submit():
		first_name = create_profile_form.data.get("first_name")
		last_name = create_profile_form.data.get("last_name")
		email = create_profile_form.data.get("email")
		telephone_code = create_profile_form.data.get("telephone_code")
		telephone = create_profile_form.data.get("telephone")

		user = User(username=email)
		profile = Profile(first_name=first_name, last_name=last_name, telephone=join_telephone(telephone_code, telephone), email=email, is_cashier=True)
		profile.branch = branch
		profile.user = user
		db.session.add(user)
		db.session.add(profile)
		create_user_token(user)
		db.session.commit()
		send_auth_mail(user.username, user.token.token)
		flash("Cashier created", "success")
	else:
		flash(f"{create_profile_form.errors}", "danger")

	return redirect(request.referrer)
示例#6
0
def create_passenger_profile(): 
	signup_form = SignupForm()
	if signup_form.validate_on_submit():
		first_name = signup_form.data.get("first_name")
		last_name = signup_form.data.get("last_name")
		email = signup_form.data.get("email")
		telephone_code = signup_form.data.get("telephone_code")
		telephone = signup_form.data.get("telephone")
		password = signup_form.data.get("password")

		user = User(password=password, username=email)
		profile = Profile(first_name=first_name, last_name=last_name, telephone=join_telephone(telephone_code, telephone), email=email, is_passenger=True)
		profile.user = user
		db.session.add(user)
		db.session.add(profile)
		create_user_token(user)
		db.session.commit()
		send_auth_mail(user.username, user.token.token)
		flash("Registration was successful. Login here.", "success")
		return redirect(url_for('index.login'))

	else:
		search_buses_form = SearchBusesForm()
		return render_template('index/signup.html', signup_form=signup_form)