def login(): error = None try: c, conn = connection() flash("db ok") if request.method == "POST": flash("method is POST") data = c.execute("SELECT * FROM users WHERE username = (%s)", [thwart(request.form['username'])]) data = c.fetchone()[2] name = request.form['username'] if sha256_crypt.verify(request.form['password'], data): session['logged_in'] = True session['username'] = request.form['username'] flash("You are now logged in") if name == 'ubuntu': session['is_admin']= True flash("welcome Admin!") else: flash("Welcome Standard User") return redirect("/") else: error = "Invalid credentials, try again." gc.collect() return render_template("register/login.html", error=error) except Exception as e: #flash(e) error = "Invalid credentials, try again." return render_template('register/login.html',error = error)
def register(): try: form = RegistrationForm(request.form) if request.method == "POST" and form.validate(): username = form.username.data email = form.email.data password = sha256_crypt.encrypt((str(form.password.data))) c, conn = connection() x = c.execute("SELECT * FROM users WHERE username = (%s)", [(thwart(username))]) if int(x) > 0: flash("That username is already taken, please choose another") return render_template('register/register.html', form=form) else: c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)", (thwart(username), thwart(password), \ thwart(email), thwart("/introduction-to-python-programming/"))) conn.commit() flash("Thanks for registering!") c.close() conn.close() gc.collect() session['logged_in'] = True session['username'] = username return redirect("/") return render_template("register/register.html", form=form) except Exception as e: return (str(e))
def login(): error = None try: c, conn = connection() flash("db ok") if request.method == "POST": flash("method is POST") data = c.execute("SELECT * FROM users WHERE username = (%s)", [thwart(request.form['username'])]) data = c.fetchone()[2] name = request.form['username'] if sha256_crypt.verify(request.form['password'], data): session['logged_in'] = True session['username'] = request.form['username'] flash("You are now logged in") if name == 'ubuntu': session['is_admin'] = True flash("welcome Admin!") else: flash("Welcome Standard User") return redirect("/") else: error = "Invalid credentials, try again." gc.collect() return render_template("register/login.html", error=error) except Exception as e: #flash(e) error = "Invalid credentials, try again." return render_template('register/login.html', error=error)
def register(): try: form = RegistrationForm(request.form) if request.method == "POST" and form.validate(): username = form.username.data email = form.email.data password = sha256_crypt.encrypt((str(form.password.data))) c,conn = connection() x = c.execute("SELECT * FROM users WHERE username = (%s)", [(thwart(username))]) if int(x) > 0 : flash("That username is already taken, please choose another") return render_template('register/register.html', form=form) else: c.execute("INSERT INTO users (username, password, email, tracking) VALUES (%s, %s, %s, %s)", (thwart(username), thwart(password), \ thwart(email), thwart("/introduction-to-python-programming/"))) conn.commit() flash("Thanks for registering!") c.close() conn.close() gc.collect() session['logged_in'] = True session['username'] = username return redirect("/") return render_template("register/register.html", form=form) except Exception as e: return(str(e)) # form = RegisterForm() # if request.method == 'POST' and form.validate(): # print form.username.data,form.email.data,form.password.data # print 'success' # return render_template('register/register_complete.html') # return render_template('register/register.html', form=form)
from app import dbconnect from app import config cursor, connection = dbconnect.connection(config) class Park: """ id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(45)) size = db.Column(db.String(45)) address = db.Column(db.String(45)) zip_code = db.Column(db.String(45)) state = db.Column(db.String(45)) city = db.Column(db.String(45)) playground = db.Column(db.Integer) latitude = db.Column(db.Float(11, 8)) longitude = db.Column(db.Float(11, 8)) """ def __init__(self, id, name, size, address, zip_code, state, city, playground, latitude, longitude): self.id = id self.name = name self.size = size self.address = address self.zip_code = zip_code self.state = state self.city = city self.playground = playground self.latitude = latitude self.longitude = longitude