Ejemplo n.º 1
0
def register():
    username = request.args["Username"]
    password = request.args['Password']
    blog = request.args['Blog']

    if db.isUser(username):
        flash("user already exists")
        return render_template('form.html', error=True)

    elif db.isUser(username) == False:
        db.register(username, blog, password, "Read")
        return render_template('form.html')
Ejemplo n.º 2
0
def login():
    username = request.args['user']
    password = request.args['pass']

    #username and passwords match
    if db.isUser(username) and db.getPw(username) == password:
        session['user'] = username
        return render_template('return.html', user=username)

    #username doesn't match
    elif db.isUser(username) == False:
        flash("username not found")
        return render_template('form.html', error=True)

    #password doesn't match username
    elif db.getPw(username) != password:
        flash("password incorrect")
        return render_template('form.html', error=True)
Ejemplo n.º 3
0
def search():
    user = request.args['user']
    if db.isUser(user) == True:
        print("ok")
        titles = db.getEntryTitle(user)
        entries = db.getEntryBody(user)

        titles=[x[0] for x in titles if x[0] != "CREATED"]
        entries=[x[0] for x in entries if x[0] != "CREATED"]

        return render_template("search.html", user=user, titles=titles, entries=entries)
    else: #Error handling
        flash("Username not found! Returned back to your page")
        return redirect("/")
Ejemplo n.º 4
0
def auth():
    username = request.form['username']
    password = request.form['password']

    if db.isUser(username):
        if db.getPass(username) == password:
            session['username'] = username
            return redirect('/')
        else:
            flash('Wrong password, try again')
            return redirect(url_for('logout'))
    else:
        flash('Username does not exist, try again.')
        return redirect(url_for('logout'))
Ejemplo n.º 5
0
def register():
    username = request.form['username']
    password = request.form['password']
    address = request.form['address']
    if len(username) < 3:
        flash('Username must be at least 3 characters, try again.')
        return redirect('/')
    elif len(password) < 3:
        flash('Password must be at least 3 characters, try again.')
        return redirect('/')
    try:
        suggest = api.suggest(
            address)  #list of suggestions based on user input
        address = suggest[0]  #sets address to first in suggestions
    except:
        flash('Invalid location, try again.')
        return redirect('/')

    if not db.isUser(username):
        db.register(username, password, address)
        flash('Account successfully created!')
    else:
        flash('Username already taken, try again.')
    return redirect('/')