Esempio n. 1
0
def register():
    """Registers the user."""
    if g.user:
        return redirect(functions.url_for('/'))
    error = None
    if request.method == 'POST':
        if not request.form['username']:
            error = 'You have to enter a username'
        elif not request.form['email'] or \
                '@' not in request.form['email']:
            error = 'You have to enter a valid email address'
        elif not request.form['password']:
            error = 'You have to enter a password'
        elif request.form['password']!=request.form['confirm-password']:
            error = 'The two passwords do not match'
        elif functions.get_user_id(request.form['username']) is not None:
            error = 'The username is already taken'
        else:
            db = functions.get_db()
            db.execute('''insert into user (username, email, pw_hash) values (?, ?, ?)''',
[request.form['username'], request.form['email'],
 generate_password_hash(request.form['password'])])
            db.commit()
            flash('You were successfully registered and can login now')
            return redirect(functions.url_for('login'))
    return render_template('register.html', error=error)
Esempio n. 2
0
def add_message():
    """Registers a new message for the user."""
    if 'user_id' not in session:
        abort(401)
    if request.form['text']:
        db = functions.get_db()
        db.execute('''insert into message (author_id, text, pub_date)  values (?, ?, ?)''', (session['user_id'], request.form['text'],int(time.time())))
        db.commit()
        flash('Your message was recorded')
    return redirect(functions.url_for('/'))
Esempio n. 3
0
def add_message():
    """Registers a new message for the user."""
    if 'user_id' not in session:
        abort(401)
    if request.form['text']:
        db = functions.get_db()
        #db.execute()
        db.commit()
        flash('Your message was recorded')
    return redirect(functions.url_for('/'))
Esempio n. 4
0
def follow_user(username):
    """Adds the current user as follower of the given user."""
    if not g.user:
        abort(401)
    whom_id = functions.get_user_id(username)
    if whom_id is None:
        abort(404)
    db = functions.get_db()
    db.execute('insert into follower (who_id, whom_id) values (?, ?)',
              [session['user_id'], whom_id])
    db.commit()
    flash('You are now following "%s"' % username)
    return redirect(functions.url_for('/%(username)s', {'username':username}))
Esempio n. 5
0
def unfollow_user(username):
    """Removes the current user as follower of the given user."""
    if not g.user:
        abort(401)
    whom_id = functions.get_user_id(username)
    if whom_id is None:
        abort(404)
    db = functions.get_db()
    db.execute('delete from follower where who_id=? and whom_id=?',
              [session['user_id'], whom_id])
    db.commit()
    flash('You are no longer following "%s"' % username)
    return redirect(functions.url_for('/%(username)s', {'username':username}))
Esempio n. 6
0
def add_message():
    """Registers a new message for the user."""
    if "user_id" not in session:
        abort(401)
    if request.form["text"]:
        db = functions.get_db()
        db.execute(
            """insert into message (author_id, text, pub_date)
  values (?, ?, ?)""",
            (session["user_id"], request.form["text"], int(time.time())),
        )
        db.commit()
        flash("Your message was recorded")
    return redirect(functions.url_for("/"))