You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
6.4 KiB
175 lines
6.4 KiB
# -*- coding: utf-8 -*-
|
|
#from flask import Flask, request, render_template, json, g, redirect, abort, session, jsonify, url_for, make_response, Response
|
|
|
|
from flask import Blueprint, Flask, render_template, request, redirect, url_for
|
|
|
|
from cart import cart_page
|
|
from checkout import checkout_page
|
|
|
|
from database import db_session, init_db
|
|
from models import User, Adresse, Bestellung, Warenkorb, WarenkorbProdukt, Produkt, Produktbilder, Configtable
|
|
from sqlalchemy import func, desc, asc, or_
|
|
from werkzeug.security import generate_password_hash, check_password_hash
|
|
|
|
from datetime import datetime, timedelta, date
|
|
import random
|
|
|
|
import json
|
|
import time
|
|
import requests
|
|
|
|
from flask_login import LoginManager, UserMixin, \
|
|
login_required, login_user, logout_user
|
|
|
|
#from flask_weasyprint import HTML, render_pdf
|
|
|
|
# Create appF
|
|
app = Flask(__name__)
|
|
app.register_blueprint(cart_page)
|
|
app.register_blueprint(checkout_page)
|
|
|
|
app.config['DEBUG'] = True
|
|
app.config['TESTING'] = True
|
|
|
|
#app.config['MYSQL_DATABASE_CHARSET'] = 'utf8mb4'
|
|
|
|
app.config['SECRET_KEY'] = 'shadk67d%sad%DSuad356=0cklasLASdqdadSIDasd/209sadLSmaca)Xaa'
|
|
app.config['SQLALCHEMY_DATABASE_URI'] ='mysql+mysqldb://root:ujIyFEznJHib6gH4@localhost/corten'
|
|
|
|
#init_db()
|
|
|
|
login_manager = LoginManager()
|
|
login_manager.init_app(app)
|
|
|
|
#_________________________________________________________________________
|
|
#___________________________________Home__________________________________
|
|
#_________________________________________________________________________
|
|
|
|
@login_manager.user_loader
|
|
def load_user(user_id):
|
|
return User.query.get(user_id)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
@app.route('/', methods=['POST','GET'])
|
|
@app.route('/index.html', methods=['POST','GET'])
|
|
def home():
|
|
produkte = Produkt.query.order_by(func.random()).limit(3).all()
|
|
return render_template("index.html",produkte=produkte,site="home")
|
|
|
|
@app.route('/produkte', methods=['POST','GET'])
|
|
def produkte():
|
|
produkte = Produkt.query.order_by(func.random()).all()
|
|
return render_template("produkte.html",produkte=produkte,site="produkte")
|
|
|
|
|
|
@app.route('/<id>/produkt', methods=['GET', 'POST'])
|
|
def produkt(id):
|
|
produkt = Produkt.query.filter_by(id=id).first()
|
|
return render_template("produkt.html",produkt=produkt)
|
|
|
|
#-----------------------------------------------------------------------------
|
|
@app.route('/loginpanel', methods=['POST','GET'])
|
|
def loginpanel():
|
|
return render_template("userpanel.html", site="login")
|
|
|
|
@app.route('/login', methods=['POST'])
|
|
def login_post():
|
|
email = request.form.get('email')
|
|
password = request.form.get('password')
|
|
remember = True if request.form.get('remember') else False
|
|
|
|
user = User.query.filter_by(mail=email).first()
|
|
|
|
# check if the user actually exists
|
|
# take the user-supplied password, hash it, and compare it to the hashed password in the database
|
|
if not user or not check_password_hash(user.passwort, password):
|
|
flash('Bitte logindaten Überprüfen')
|
|
return redirect(url_for('home')) # if the user doesn't exist or password is wrong, reload the page
|
|
|
|
login_user(user,force=True)
|
|
# if the above check passes, then we know the user has the right credentials
|
|
return redirect(url_for('home'))
|
|
|
|
@app.route('/signup', methods=['POST','GET'])
|
|
def signup_post():
|
|
# code to validate and add user to database goes here
|
|
name = request.form.get('name')
|
|
firma = request.form.get('firma')
|
|
tel = request.form.get('tel')
|
|
uid = request.form.get('uid')
|
|
email = request.form.get('email')
|
|
password = request.form.get('password')
|
|
|
|
user = User.query.filter_by(mail=email).first() # if this returns a user, then the email already exists in database
|
|
|
|
if user: # if a user is found, we want to redirect back to signup page so user can try again
|
|
return redirect(url_for('home'))
|
|
|
|
# create a new user with the form data. Hash the password so the plaintext version isn't saved.
|
|
new_user = User(name=name, firma=firma, tel=tel, uid=uid, mail=email, passwort=generate_password_hash(password, method='sha256'), lang="de", datetime=datetime.now())
|
|
|
|
# add the new user to the database
|
|
db_session.add(new_user)
|
|
db_session.commit()
|
|
db_session.flush()
|
|
login_user(new_user,force=True)
|
|
|
|
return redirect(url_for('home'))
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
@app.route('/kundencenter', methods=['POST','GET'])
|
|
def kundencenter():
|
|
return render_template("index.html", site="kundencenter")
|
|
|
|
@app.route('/warenkorb', methods=['POST','GET'])
|
|
def warenkorb():
|
|
return render_template("warenkorb.html", site="warenkorb")
|
|
|
|
@app.route('/impressum', methods=['POST','GET'])
|
|
def impressum():
|
|
return render_template("impressum.html")
|
|
|
|
@app.route('/agb', methods=['POST','GET'])
|
|
def AGB():
|
|
return render_template("agb.html")
|
|
|
|
@app.route('/lieferung', methods=['POST','GET'])
|
|
def lieferung():
|
|
return render_template("lieferung.html")
|
|
|
|
@app.route('/datenschutz', methods=['POST','GET'])
|
|
def datenschutz():
|
|
return render_template("datenschutz.html")
|
|
|
|
@app.route('/cookie', methods=['POST','GET'])
|
|
def cookie():
|
|
return render_template("cookie.html")
|
|
|
|
@app.route('/kontakt', methods=['POST','GET'])
|
|
def kontakt():
|
|
if request.method == 'POST':
|
|
#if recaptcha.verify():
|
|
name = request.form.get('name')
|
|
email = request.form.get('email')
|
|
subject = request.form.get('subject')
|
|
message_user = request.form.get('message')
|
|
capture = request.form.get('g-recaptcha-response')
|
|
if capture!=None:
|
|
url = "https://recaptchaenterprise.googleapis.com?secret=6Lcrd88eAAAAAKpGc4qQDUKDkTGiEmvRQHxbPhfU&response=" + capture
|
|
x = requests.post(url)
|
|
json_data = json.loads(x.text)
|
|
if json_data['success']:
|
|
#msg = Message('Usermessage Dive air ' + subject + ' name:' + name+ ' email:' + email, sender=email, recipients=['chris@diveair.eu'])
|
|
#msg.body = message_user
|
|
#mail.send(msg)
|
|
return render_template('kontakt.html', success=True, site="kontakt")
|
|
return render_template('kontakt.html', success=False, site="kontakt")
|
|
else:
|
|
return render_template("kontakt.html",success=None)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.debug = True
|
|
app.run(host='localhost',port=8087)
|