Ejemplo n.º 1
0
def populate():
    session = DBSession()
    user1 = Person('fyhuang', 'Frank')
    from nilsby.util import hashed_password
    user1.password_hash = hashed_password('password')
    #post1 = ForumPost('This is a test', 'test post 1')
    #user1.forum_posts.append(post1)
    #post1.replies.append(ForumReply('test reply 1'))

    #user1.forum_posts.append(ForumPost('This is a test 2', 'test post 2'))
    #user1.forum_posts.append(ForumPost('This is a test 3', 'test post 3'))
    session.add(user1)
    session.flush()
    transaction.commit()
Ejemplo n.º 2
0
Archivo: views.py Proyecto: elui/nilsby
def login_view(request):
    db = get_session()
    if 'username' in request.POST:
        # TODO: login
        pw_hash = hashed_password(request.POST['password'])
        user = db.query(Person).\
                filter(Person.username==request.POST['username']).\
                filter(Person.password_hash==pw_hash).first()
        if user is not None:
            request.session['user_id'] = user.id
            request.session['username'] = user.username
            request.session.flash("Welcome back, {0}".format(user.username))
        else:
            request.session.flash("Incorrect login credentials, please try again")
    if request.referer:
        final_location = request.referer
    else:
        final_location = request.route_url('home')
    return HTTPFound(location=final_location)