示例#1
0
 def _check_auth(*args, **kwargs):
     sess = Session(bottle.request, bottle.response)
     if not sess.is_new():
         user = User.find_by_id(sess['id'])
         if user:
             return handler(user, *args, **kwargs)
     bottle.redirect('/login')
示例#2
0
def sign_up():
    if 'name' in bottle.request.POST and 'password' in bottle.request.POST:
        name = bottle.request.POST['name']
        if name not in reserved_usernames.split():
            password = bottle.request.POST['password']

            attributes = {}
            if 'firstName' in bottle.request.POST:
                attributes['firstName'] = bottle.request.POST['firstName']

            if 'lastName' in bottle.request.POST:
                attributes['lastName'] = bottle.request.POST['lastName']

            if 'greeting' in bottle.request.POST:
                attributes['greeting'] = bottle.request.POST['greeting']

            user = User.create(name, password, attributes)
            if user:
                sess = Session(bottle.request, bottle.response)
                sess['id'] = user.id
                sess.save()
                bottle.redirect('/home')
        return bottle.template('login',
                               page='login',
                               error_login=False,
                               error_signup=True,
                               logged=False)
示例#3
0
def login():
    if 'name' in bottle.request.POST and 'password' in bottle.request.POST:
        name = bottle.request.POST['name']
        password = bottle.request.POST['password']

        user = User.find_by_username(name)
        if user and user.password == settings.SALT + password:
            sess = Session(bottle.request, bottle.response)
            sess['id'] = user.id
            sess.save()
            bottle.redirect('/home')

    return bottle.template('login',
                           page='login',
                           error_login=True,
                           error_signup=False,
                           logged=False)
示例#4
0
def logged_in_user():
    sess = Session(bottle.request, bottle.response)
    if not sess.is_new():
        return User.find_by_id(sess['id'])
    return None
示例#5
0
def logout():
    sess = Session(bottle.request, bottle.response)
    sess.invalidate()
    bottle.redirect('/')