File: //opt/alt/python27/lib/python2.7/site-packages/paste/auth/form.pyo
�
a�Nc           @   s�   d  Z  d d l m Z m Z d Z d e f d �  �  YZ e Z d g Z d �  Z	 d e
 k r~ d d l Z e j d	 e j
 � n  d S(
   s(  
Authentication via HTML Form
This is a very simple HTML form login screen that asks for the username
and password.  This middleware component requires that an authorization
function taking the name and passsword and that it be placed in your
application stack. This class does not include any session management
code or way to save the user's authorization; however, it is easy enough
to put ``paste.auth.cookie`` in your application stack.
>>> from paste.wsgilib import dump_environ
>>> from paste.httpserver import serve
>>> from paste.auth.cookie import AuthCookieHandler
>>> from paste.auth.form import AuthFormHandler
>>> def authfunc(environ, username, password):
...    return username == password
>>> serve(AuthCookieHandler(
...           AuthFormHandler(dump_environ, authfunc)))
serving on...
i����(   t
   construct_urlt   parse_formvarss�  <html>
  <head><title>Please Login!</title></head>
  <body>
    <h1>Please Login</h1>
    <form action="%s" method="post">
      <dl>
        <dt>Username:</dt>
        <dd><input type="text" name="username"></dd>
        <dt>Password:</dt>
        <dd><input type="password" name="password"></dd>
      </dl>
      <input type="submit" name="authform" />
      <hr />
    </form>
  </body>
</html>
t   AuthFormHandlerc           B   s#   e  Z d  Z d d � Z d �  Z RS(   s�  
    HTML-based login middleware
    This causes a HTML form to be returned if ``REMOTE_USER`` is
    not found in the ``environ``.  If the form is returned, the
    ``username`` and ``password`` combination are given to a
    user-supplied authentication function, ``authfunc``.  If this
    is successful, then application processing continues.
    Parameters:
        ``application``
            The application object is called only upon successful
            authentication, and can assume ``environ['REMOTE_USER']``
            is set.  If the ``REMOTE_USER`` is already set, this
            middleware is simply pass-through.
        ``authfunc``
            This is a mandatory user-defined function which takes a
            ``environ``, ``username`` and ``password`` for its first
            three arguments.  It should return ``True`` if the user is
            authenticated.
        ``template``
            This is an optional (a default is provided) HTML
            fragment that takes exactly one ``%s`` substution
            argument; which *must* be used for the form's ``action``
            to ensure that this middleware component does not alter
            the current path.  The HTML form must use ``POST`` and
            have two input names:  ``username`` and ``password``.
    Since the authentication form is submitted (via ``POST``)
    neither the ``PATH_INFO`` nor the ``QUERY_STRING`` are accessed,
    and hence the current path remains _unaltered_ through the
    entire authentication process. If authentication succeeds, the
    ``REQUEST_METHOD`` is converted from a ``POST`` to a ``GET``,
    so that a redirect is unnecessary (unlike most form auth
    implementations)
    c         C   s%   | |  _  | |  _ | p t |  _ d  S(   N(   t   applicationt   authfunct   TEMPLATEt   template(   t   selfR   R   R   (    (    s@   /opt/alt/python27/lib/python2.7/site-packages/paste/auth/form.pyt   __init__[   s    		c         C   s  | j  d d � } | r( |  j | | � Sd | d k r� t | d t �} | j  d � } | j  d � } | r� | r� |  j | | | � r� d | d	 <| | d <d
 | d <d | d <d | d <| d
 =|  j | | � Sq� n  |  j t | � } | d d d t t | � � f g � | g S(   Nt   REMOTE_USERt    t   POSTt   REQUEST_METHODt   include_get_varst   usernamet   passwordt   formt	   AUTH_TYPEt   GETt   CONTENT_LENGTHt   CONTENT_TYPEs   paste.parsed_formvarss   200 OKs   Content-Types	   text/htmls   Content-Length(   s   Content-Types	   text/html(	   t   getR   R   t   FalseR   R   R    t   strt   len(   R   t   environt   start_responseR   t   formvarsR   t   content(    (    s@   /opt/alt/python27/lib/python2.7/site-packages/paste/auth/form.pyt   __call__`   s(    
	N(   t   __name__t
   __module__t   __doc__t   NoneR   R   (    (    (    s@   /opt/alt/python27/lib/python2.7/site-packages/paste/auth/form.pyR   /   s   *c         K   sb   d d l  m } d d l } | | � } | j d � } | d k	 rR | | � } n  t |  | | � S(   s�   
    Grant access via form authentication
    Config looks like this::
      [filter:grant]
      use = egg:Paste#auth_form
      realm=myrealm
      authfunc=somepackage.somemodule:somefunction
      
    i����(   t   eval_importNR   (   t   paste.util.import_stringR"