Beispiel #1
0
def handle_login(env):
    tmpl = jinjaenv.get_template('loginform.html')

    if str(env['REQUEST_METHOD']) == 'POST':
        data = read_post_data(env)

        if 'user' not in data or 'pass' not in data:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

        user = urllib.unquote_plus(data['user'].value)
        pass_ = urllib.unquote_plus(data['pass'].value)

#        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

        if u.password == pass_:
            env['beaker.session']['user_name'] = user
            env['beaker.session'].save()
            return main_page(env)
        else:
            return template_render(tmpl, env,
            {   'session' : env['beaker.session'], 'loginfail' : True}  )

    return template_render(tmpl, env, { })
Beispiel #2
0
        def webtool_func(env, *args, **key_args):
            """
            webtool internal function wrapper
            """

            # Force a login if necessary
            if require_login:
                if not loggedin_and_require(env):
                    return handle_login(env)

            # Lookup user
            try:
                user_name = env['beaker.session']['user_name']
                user = lookup_user(user_name)
            except KeyError, e:
                user = None
Beispiel #3
0
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html',
                                               loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

        #        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')
Beispiel #4
0
def handle_login():
    print 'Handle das login'
    #tmpl = jinjaenv.get_template('loginform.html')
    _login_fail = lambda: pyro_render_template('loginform.html', loginfail=True)
    print 'Request method:', request.method

    if request.method == 'POST':
        if 'user' not in request.form or 'pass' not in request.form:
            return _login_fail()

        user = request.form['user']
        passwd = request.form['pass']

#        pass = hashlib.sha256(pass).hexdigest()
        u = lookup_user(user)
        if u is None:
            return _login_fail()

        if u.password == passwd:
            print 'Login succes.'
            session['user_name'] = user

            # Redirect user to original page, or if not possible
            # to the main page.
            redir_url = session.pop('login_redirect_url', None)
            if redir_url:
                print 'Redirecting to:', redir_url
                return redirect_client_prg(url=redir_url)

            return redirect_client_prg('main_view_page')

        else:
            return _login_fail()

    # Not logged in?
    # Render login page, and store
    # current URL in beaker session.
    if not loggedin():
        print 'Not logged in, storing session data:', request.base_url
        session['login_redirect_url'] = request.base_url

        return pyro_render_template('loginform.html')

    # User already loggedin, redirect to main page.
    else:
        return redirect_client('main_view_page')
Beispiel #5
0
def add_torrent_page(env, target):
    """
    Page for adding torrents.
    Works: Adding a correct torrent (URL only)
    What doesn't work:
        Error handling,
        Uploading .torrent files
        Option to add and start, or not start on add
    """
    if not loggedin_and_require(env):
        return handle_login(env)

    target = lookup_target(target)
    if target is None:
        return None # 404

    try:
        user_name = env['beaker.session']['user_name']
        user = lookup_user(user_name)
    except KeyError, e:
        user = None
Beispiel #6
0
        def pyroview_func(*args, **key_args):
            """
            pyroview internal function wrapper
            """

            print "pyroview_func"
            print args, key_args

            # Force a login if necessary
            if require_login:
                if not loggedin_and_require():
                    # If you wonder why the definition of the
                    # following function is nowhere to be found, check
                    # '/pyrotorrent.py'.
                    return handle_login()

            # Lookup user
            try:
                user_name = session['user_name']
                user = lookup_user(user_name)
            except KeyError, e:
                user = None
Beispiel #7
0
        def pyroview_func(*args, **key_args):
            """
            pyroview internal function wrapper
            """

            print "pyroview_func"
            print args, key_args

            # Force a login if necessary
            if require_login:
                if not loggedin_and_require():
                    # If you wonder why the definition of the
                    # following function is nowhere to be found, check
                    # '/pyrotorrent.py'.
                    return handle_login()

            # Lookup user
            try:
                user_name = session['user_name']
                user = lookup_user(user_name)
            except KeyError, e:
                user = None