Пример #1
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['useremail']
        password = request.form['password']
        confirm_password = request.form['confirm_password']
        db = get_db()
        error = None

        if not username:
            error = 'Username is required.'
        elif not email:
            error = 'Email is required'
        elif not password:
            error = 'Password is required.'
        elif password != confirm_password:
            error = 'Passwords does not match'
        elif db.execute(
            'SELECT id FROM users WHERE username = ?', (username,)
        ).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute(
                'INSERT INTO users (username,email, password) VALUES (?,?,?)',
                (username, email, generate_password_hash(password))
            )
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)

    return render_template('auth/register.html')
Пример #2
0
def joined():
    db = get_db()

    deeds = db.execute(
        "SELECT dISTINCT deeds.* FROM deeds INNER JOIN eventreg ON deeds.id = eventreg.eventid WHERE eventreg.userid =:id",
        {"id": g.user['id']})
    return render_template('gooddeeds/joined.html', deeds=deeds)
Пример #3
0
def create():
    if request.method == 'POST':
        title = request.form['title']
        description = request.form['description']
        location = request.form['location']
        address = request.form['address']
        date = request.form['date']

        error = None

        if not title:
            error = 'Title is required.'
        elif not description:
            error = 'description is needed'
        elif not location:
            error = 'location is needed'
        elif not address:
            error = 'address is needed'
        elif not date:
            error = "date is required"
        if error is not None:
            flash(error)
        else:
            db = get_db()
            db.execute(
                'INSERT INTO deeds (title, description, created, location, isdone, address, userid, date)'
                ' VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
                (title, description, datetime.datetime.now(), location, False,
                 address, g.user['id'], date))
            db.commit()
            flash('{} created'.format(title))
            return redirect(url_for('gooddeeds.dashboard'))

    return render_template('gooddeeds/createdeed.html')
Пример #4
0
def join(id):
    db = get_db()

    deedid = db.execute("SELECT id, title FROM deeds WHERE id =:theid",
                        {"theid": id})

    error = None
    title = None
    for item in deedid:
        title = item['title']

    if db.execute(
            'SELECT id FROM eventreg WHERE userid =:userid AND eventid =:event',
        {
            "userid": g.user['id'],
            "event": id
        }).fetchone() is not None:
        error = 'You are already registered.'

    if error is not None:
        flash(error)

    else:
        db.execute('INSERT INTO eventreg (userid, eventid) VALUES (?,?)',
                   (g.user['id'], id))
        db.commit()
        flash(
            'Congratulations, you successfully registered for {}. Check back on the date provided'
            .format(title))
        return redirect(url_for('gooddeeds.dashboard', id=id))

    return render_template('gooddeeds/join.html')
Пример #5
0
def dashboard():
    db = get_db()
    deeds = db.execute(
        "SELECT id, userid, address, description, title, date, location, isdone FROM deeds WHERE  isdone =:bool ORDER BY created DESC",
        {"bool": False})

    return render_template('gooddeeds/dashboard.html', deeds=deeds)
Пример #6
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db().execute(
            'SELECT * FROM users WHERE id = ?', (user_id,)
        ).fetchone()
Пример #7
0
def update(id):
    db = get_db()
    deeds = db.execute("SELECT * FROM deeds WHERE id =:theid", {
        "theid": id
    }).fetchone()
    # is_id = None
    # for item in deedid:
    is_id = deeds['id']

    if request.method == 'POST':
        title = request.form['title']
        description = request.form['description']
        location = request.form['location']
        address = request.form['address']
        date = request.form['date']

        error = None

        if not title:
            error = 'Title is required.'
        elif not description:
            error = 'description is needed'
        elif not location:
            error = 'location is needed'
        elif not address:
            error = 'address is needed'
        elif not date:
            error = 'date is required'
        if error is not None:
            flash(error)
        else:
            db = get_db()
            db.execute(
                'UPDATE deeds SET title = ?, description = ?, date = ?, location = ?, address = ? WHERE id = ?',
                (title, description, date, location, address, is_id))
            db.commit()
            flash('{} updated'.format(title))
            return redirect(url_for('gooddeeds.dashboard'))

    return render_template('gooddeeds/update.html', deeds=deeds)
Пример #8
0
def delete(id):
    db = get_db()
    deedid = db.execute("SELECT id, title FROM deeds WHERE id =:theid",
                        {"theid": id})
    is_id = None
    title = None
    for item in deedid:
        is_id = item['id']
        title = item['title']

    db.execute('DELETE FROM deeds WHERE id = ?', (is_id, ))
    db.commit()
    flash('{} deleted'.format(title))

    return redirect(url_for('gooddeeds.dashboard'))
Пример #9
0
def details(id):
    db = get_db()
    deeds = db.execute("SELECT * FROM deeds WHERE  id =:ide", {"ide": id})
    user_name = db.execute(
        "SELECT users.username FROM users INNER JOIN deeds ON users.id = deeds.userid WHERE deeds.id=:ide ",
        {
            "ide": id
        }).fetchone()

    event_data = db.execute(
        "SELECT COUNT(*) FROM eventreg WHERE eventid =:ide", {
            "ide": id
        }).fetchone()

    username = user_name['username']
    eventdata = event_data[0]

    return render_template('gooddeeds/details.html',
                           deeds=deeds,
                           eventdata=eventdata,
                           username=username)
Пример #10
0
def isdone(deed_id):
    db = get_db()
    deedid = db.execute("SELECT id, title, isdone FROM deeds WHERE id =:theid",
                        {"theid": deed_id})

    is_done = None
    is_id = None
    title = None
    for item in deedid:
        is_done = item['isdone']
        is_id = item['id']
        title = item['title']

    db.execute("UPDATE deeds SET isdone = ? WHERE id = ?", (
        not is_done,
        is_id,
    ))

    db.commit()
    flash('{} Completed status changed'.format(title))

    return redirect(url_for('gooddeeds.dashboard'))
Пример #11
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute(
            'SELECT * FROM users WHERE username = ?', (username,)
        ).fetchone()

        if user is None:
            error = 'Incorrect username.'
        elif not check_password_hash(user['password'], password):
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            return redirect(url_for('gooddeeds.dashboard'))

        flash(error)

    return render_template('auth/login.html')
Пример #12
0
def completed():
    db = get_db()
    deeds = db.execute(
        "SELECT id, userid, title, location, address, date, description, isdone FROM deeds WHERE isdone =:bool",
        {"bool": True})
    return render_template('gooddeeds/completed.html', deeds=deeds)