Exemple #1
0
def task(board_id):
    if g.user is None:
        return redirect(url_for('index'))

    db = get_db()

    if request.method == 'POST':
        name = request.form['name']
        description = request.form['description']

        db.execute(
            'INSERT INTO task'
            ' (id, board_id, status, name, description)'
            ' VALUES (?, ?, ?, ?, ?)',
            (str(uuid.uuid4()), board_id, 'wait', name, description))
        db.commit()
        return redirect(url_for('task.task', board_id=board_id))

    if request.method == 'GET':
        board = db.execute('SELECT id, name FROM board WHERE id = ?',
                           (board_id, )).fetchone()
        task_list = db.execute('SELECT * FROM task WHERE board_id = ?',
                               (board_id, )).fetchall()
        return render_template('task/task.html',
                               board=board,
                               task_list=task_list)
Exemple #2
0
def login():
    if g.user is not None:
        return redirect(url_for('account.profile'))

    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        db = get_db()
        error = None

        if not email:
            error = 'Email is required.'
        elif not password:
            error = 'Password is required.'

        if error is None:
            user = db.execute('SELECT * FROM user WHERE email = ?',
                              (email, )).fetchone()

            if user is None:
                error = 'There are no such user.'
            elif not check_password_hash(user['password'], password):
                error = 'Wrong password.'

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

        flash(error)

    return render_template('account/login.html')
Exemple #3
0
def task_delete(board_id, task_id):
    if g.user is None:
        return redirect(url_for('index'))

    db = get_db()
    db.execute('DELETE FROM task WHERE id = ?', (task_id, ))
    db.commit()
    return redirect(url_for('task.task', board_id=board_id))
Exemple #4
0
def board_delete(board_id):
    if g.user is None:
        return redirect(url_for('index'))

    db = get_db()
    db.execute('DELETE FROM board WHERE id = ?', (board_id, ))
    os.remove(os.curdir, '/todo_app/static/board/' + board_id + '.jpg')
    db.commit()
    return redirect(url_for('board.board'))
Exemple #5
0
def load_logged_in_user():
    user_id = session.get('user_id')
    db = get_db()

    if user_id is None:
        g.user = None
    else:
        g.user = db.execute('SELECT * FROM user WHERE id = ?',
                            (user_id, )).fetchone()
Exemple #6
0
def task_change(board_id, task_id):
    if g.user is None:
        return redirect(url_for('index'))

    name = request.form['name']
    status = request.form['status']
    description = request.form['description']

    db = get_db()
    db.execute(
        'UPDATE task SET name = ?, status = ?, description = ?'
        ' WHERE id = ?', (name, status, description, task_id))
    db.commit()
    return redirect(url_for('task.task', board_id=board_id))
Exemple #7
0
def registration():
    if g.user is not None:
        return redirect(url_for('account.profile'))

    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        name = request.form['name']
        db = get_db()
        error = None

        if not email:
            error = 'Email is required.'
        elif not password:
            error = 'Password is required.'
        elif db.execute('SELECT id FROM user WHERE email = ?',
                        (email, )).fetchone() is not None:
            error = 'Email {} is already exists.'.format(email)

        if error is None:
            user_id = str(uuid.uuid4())
            db.execute(
                'INSERT INTO user(id, email, password, name) '
                'VALUES (?, ?, ?, ?)',
                (user_id, email, generate_password_hash(password), name))

            cur_dir = os.curdir
            src_avatar = os.path.join(cur_dir,
                                      'todo_app/static/default/avatar.jpg')
            dest_folder = os.path.join(cur_dir, 'todo_app/static/user')
            shutil.copy(src_avatar, dest_folder)
            dest_avatar = dest_folder + '/avatar.jpg'
            new_avatar = dest_folder + '/' + user_id + '.jpg'
            if os.path.isfile(new_avatar):
                os.remove(new_avatar)
            os.rename(dest_avatar, new_avatar)

            db.commit()
            session.clear()
            session['user_id'] = user_id
            return redirect(url_for('index'))

        flash(error)

    return render_template('account/registration.html')
Exemple #8
0
def board_change(board_id):
    if g.user is None:
        return redirect(url_for('index'))

    name = request.form['name']
    db = get_db()
    db.execute('UPDATE board SET name = ? WHERE id = ?', (name, board_id))
    f = request.files['img'] if 'img' in request.files else None

    if f:
        path = os.path.join(os.curdir,
                            'todo_app/static/board/' + board_id + '.jpg')
        if os.path.isfile(path):
            os.remove(path)
        f = request.files['img']
        f.save(path)
    db.commit()
    return redirect(url_for('board.board'))
Exemple #9
0
def board():
    if g.user is None:
        return redirect(url_for('index'))

    db = get_db()

    if request.method == 'POST':
        name = request.form['name']
        f = request.files['img'] if 'img' in request.files else None
        board_id = str(uuid.uuid4())
        db.execute('INSERT INTO board(id, owner_id, name) VALUES(?, ?, ?)',
                   (board_id, g.user['id'], name))
        print(f)
        if not f:
            cur_dir = os.curdir
            src_avatar = os.path.join(cur_dir,
                                      'todo_app/static/default/board.jpg')
            dest_folder = os.path.join(cur_dir, 'todo_app/static/board')
            shutil.copy(src_avatar, dest_folder)
            dest_avatar = dest_folder + '/board.jpg'
            new_avatar = dest_folder + '/' + board_id + '.jpg'
            if os.path.isfile(new_avatar):
                os.remove(new_avatar)
            os.rename(dest_avatar, new_avatar)
        else:
            path = os.path.join(os.curdir,
                                'todo_app/static/board/' + board_id + '.jpg')
            if os.path.isfile(path):
                os.remove(path)
            f = request.files['img']
            f.save(path)

        db.commit()
        return redirect(url_for('board.board'))

    if request.method == 'GET':
        board_list = db.execute('SELECT * FROM board WHERE owner_id = ?',
                                (g.user['id'], )).fetchall()

        return render_template('board/board.html', board_list=board_list)
Exemple #10
0
def profile():
    if g.user is None:
        return redirect(url_for('index'))

    if request.method == 'POST':
        info = request.form['info']
        db = get_db()
        error = None

        if not info:
            error = 'Info is required.'

        if error is None:
            db.execute('UPDATE user SET info = ? WHERE id = ?',
                       (info, g.user['id']))
            db.commit()
            return redirect(url_for('account.profile'))

        flash(error)

    return render_template('account/profile.html',
                           current_time=str(time.time()))