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

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

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

        flash(error)

    return render_template('auth/register.html')
Example #2
0
	def dispatch_request(self,id):
		post = get_post(id)

		if request.method == 'POST':
			team1 = request.form['team1']
			team2 = request.form['team2']
			team3 = request.form['team3']
			team4 = request.form['team4']
			team5 = request.form['team5']
			team6 = request.form['team6']
			team7 = request.form['team7']
			team8 = request.form['team8']
			strat = request.form['strat']
			multsim = request.form['multsim']
			error = None

			if not team1:
				error = 'team1 is required.'

			if error is not None:
				flash(error)
			else:
				db = get_db()
				db.execute(
					'UPDATE post SET team1 = ?, team2 = ?, team3 = ?, team4 = ?, team5 = ?, team6 = ?, team7 = ?, team8 = ?, strat = ?, multsim = ?'
					' WHERE id = ?',
					(team1, team2, team3, team4, team5, team6, team7, team8, strat, multsim, id)
				)
				db.commit()
				return redirect(url_for('app.index'))

		return render_template('app/update.html', post=post)
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 user WHERE id = ?', (user_id,)
        ).fetchone()
Example #4
0
def index():
	db = get_db()
	posts = db.execute(
		'SELECT p.id, team1, team2, team3, team4, team5, team6, team7, team8, strat, multsim, created, author_id, username'
		' FROM post p JOIN user u ON p.author_id = u.id'
		' ORDER BY created DESC'
	).fetchall()
	last = db.execute(
		'SELECT p.id'
		' FROM post p JOIN user u ON p.author_id = u.id'
		' ORDER BY created DESC'
	).fetchone()
	print('ahhahhhhh',last)
	return render_template('app/index.html', posts=posts, last=last)
Example #5
0
def get_post(id, check_author=True):
    post = get_db().execute(
        'SELECT p.id, team1, team2, team3, team4, team5, team6, team7, team8, strat, multsim, created, author_id, username'
        ' FROM post p JOIN user u ON p.author_id = u.id'
        ' WHERE p.id = ?',
        (id,)
    ).fetchone()

    if post is None:
        abort(404, "Post id {0} doesn't exist.".format(id))

    if check_author and post['author_id'] != g.user['id']:
        abort(403)

    return post
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute(
            'SELECT * FROM user 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('index'))

        flash(error)

    return render_template('auth/login.html')
Example #7
0
def create(): #belongs in controller, in this app.py file

	if request.method == 'POST':
		team1 = request.form['team1']
		team2 = request.form['team2']
		team3 = request.form['team3']
		team4 = request.form['team4']
		team5 = request.form['team5']
		team6 = request.form['team6']
		team7 = request.form['team7']
		team8 = request.form['team8']
		strat = request.form['strat']
		multsim = request.form['multsim']


		error = None
	    #output = season.loc[team1]
		print(team1)
		if not team1:
			error = 'team1 is required.'

		if error is not None:
			flash(error)
		else:
			db = get_db()
			db.execute(
				'INSERT INTO post (team1, team2, team3, team4, team5, team6, team7, team8, strat, multsim, author_id)'
				' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
				(team1, team2, team3, team4, team5, team6, team7, team8, strat, multsim, g.user['id'])
			)
			db.commit()

			return redirect(url_for('index'))

	output = 'hello'
	return render_template('app/create.html', output=output)
Example #8
0
	def dispatch_request(self,id):
		get_post(id)
		db = get_db()
		db.execute('DELETE FROM post WHERE id = ?', (id,))
		db.commit()
		return redirect(url_for('app.index'))