Search code examples
pythonbottle

I am writing a small app in bottle. I have some conceptual problem help me to solve it out


from bottle import  route, run, debug, error, request, template

@route('/home')
@route('/home/')
def login():
    return template('templates/login')

@route('/home', method='POST')
@route('/home/', method='POST')
def welocme():
    data = request.POST
    if data:
        password = data.get('password')
        check_pass = 'password'
        if password == check_pass:
            return template('templates/welcome')
        else:
            return template('templates/login')
    else:
        return template('templates/login')

My requirement is: I will get a login and welcome page on same url. Login page has only one password field.

My problem: If I get login and go to welcome page again on refreshing, it send me to login page. But ideally it should be on the welcome page only.

@error(404)
def error404(error):
    return 'http://google.com'

My second problem: I want to redirect on a particular url on 404.


Solution

  • If the user goes to the "/home" page, don't you want to check to see if they're logged in before showing them the login screen? It appears like you assume they're not already logged in if the HTTP method is not POST.

    I don't know much about your framework, but I assume if the login is successful you should set a cookie, and then you should check the cookie for HTTP GETs to see if the user is authenticated.