

_V0                 @   s  d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z m Z m	 Z
 m Z d  d l m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z m Z d  d
 l m Z d  d l m Z d  d l  m! Z! m" Z" d  d l# m$ Z$ d  d l% m& Z& m' Z' d  d l( m) Z) m* Z* d  d l+ m, Z- d  d l. m/ Z/ d  d l0 m1 Z1 d  d l2 m3 Z3 d d   Z4 e4 e3   e1 e/ d e e d d d      Z e4 d d e d d d   Z	 e4 d d d d   Z5 d e d d  Z6 e4 e1 d  d! d" d# e e d d d d d d$ d%    Z7 e4 d& d d' d(   Z8 e3   e/ e4 d d d) e e d d d* d+     Z9 e4 d, d d- d.   Z: e3   e1 e e4 d/ d e d d0 d1      Z; e e4 d2 d d3 d4    Z< d S)5    N)settings)REDIRECT_FIELD_NAMEget_user_modelloginlogoutupdate_session_auth_hash)login_required)AuthenticationFormPasswordChangeFormPasswordResetFormSetPasswordForm)default_token_generator)get_current_site)reverse)HttpResponseRedirect	QueryDict)resolve_url)TemplateResponse)RemovedInDjango20WarningRemovedInDjango110Warning)
force_text)is_safe_urlurlsafe_base64_decode)urlparse
urlunparse)ugettext)never_cache)csrf_protect)sensitive_post_parametersc                s%   t  j      f d d    } | S)zG
    Handle deprecation of the current_app parameter of the views.
    c                 sw   d | k rj t  j d j   j  t  | j d  } | j d d   } | rj | d  k	 rj | | _ qj n    |  |   S)Ncurrent_appzxPassing `current_app` as a keyword argument is deprecated. Instead the caller of `{0}` should set `request.current_app`.request)warningswarnformat__name__r   popgetr   )argskwargsr   r    )func ;/tmp/pip-build-ghmbqnp_/Django/django/contrib/auth/views.pyinner$   s    	z$deprecate_current_app.<locals>.inner)	functoolswraps)r)   r,   r*   )r)   r+   deprecate_current_app    s    !r/   zregistration/login.htmlc       	      C   s
  |  j  j | |  j j | d   } |  j d k r | |  d |  j  } | j   r t d | d |  j    s t t j	  } n  t
 |  | j    t |  Sn | |   } t |   } i | d 6| | 6| d 6| j d 6} | d	 k	 r | j |  n  t |  | |  S)
z?
    Displays the login form and handles the login action.
     POSTdataurlhostformsite	site_nameN)r1   r&   GETmethodis_validr   get_hostr   r   ZLOGIN_REDIRECT_URL
auth_loginZget_userr   r   nameupdater   )	r    template_nameredirect_field_nameZauthentication_formextra_contextZredirect_tor5   current_sitecontextr*   r*   r+   r   5   s&    r   zregistration/logged_out.htmlc             C   s   t  |   | d k	 r% t |  } n  | |  j k sC | |  j k r |  j j | |  j j |   } t d | d |  j    s |  j } q n  | r t |  St	 |   } i | d 6| j
 d 6t d  d 6} | d k	 r | j |  n  t |  | |  S)zF
    Logs out the user and displays 'You are logged out' message.
    Nr3   r4   r6   r7   z
Logged outtitle)auth_logoutr   r1   r8   r&   r   r;   pathr   r   r=   _r>   r   )r    Z	next_pager?   r@   rA   rB   rC   r*   r*   r+   r   `   s&    


r   c             C   s1   | s t  j } n  t |  } t |  | d | S)zU
    Logs out the user if they are logged in. Then redirects to the log-in page.
    rA   )r   	LOGIN_URLr   r   )r    	login_urlrA   r*   r*   r+   logout_then_login   s    rJ   c             C   sv   t  | p t j  } t t |   } | rf t | d d d } |  | | <| j d d  | d <n  t t |   S)zM
    Redirects the user to the login page, passing the given 'next' page
       ZmutableTsafe/)	r   r   rH   listr   r   	urlencoder   r   )nextrI   r@   Zresolved_urlZlogin_url_partsZquerystringr*   r*   r+   redirect_to_login   s    
rQ   Fz%registration/password_reset_form.htmlz&registration/password_reset_email.htmlz'registration/password_reset_subject.txtc             C   s2  | d  k r t  d  } n t |  } |  j d k r | |  j  } | j   r i |  j   d 6| d 6| d 6| d 6| d 6|  d 6|
 d	 6| d
 6} | r t j d t d  t	 | d |  j
   } n  | j |   t |  Sn	 |   } i | d 6t d  d 6} |	 d  k	 r"| j |	  n  t |  | |  S)Npassword_reset_doner1   Z	use_httpstoken_generator
from_emailemail_template_namesubject_template_namer    html_email_template_nameextra_email_contextzzThe is_admin_site argument to django.contrib.auth.views.password_reset() is deprecated and will be removed in Django 1.10.   Zdomain_overrider5   zPassword resetrD   )r   r   r9   r1   r:   Z	is_securer!   r"   r   dictr;   saver   rG   r>   r   )r    Zis_admin_siter?   rU   rV   Zpassword_reset_formrS   post_reset_redirectrT   rA   rW   rX   r5   optsrC   r*   r*   r+   password_reset   s:    

	r^   z%registration/password_reset_done.htmlc             C   s?   i t  d  d 6} | d  k	 r/ | j |  n  t |  | |  S)NzPassword reset sentrD   )rG   r>   r   )r    r?   rA   rC   r*   r*   r+   rR      s
    rR   z(registration/password_reset_confirm.htmlc             C   s  t    } | d k	 r! | d k	 s' t  | d k rB t d  } n t |  } y+ t t |   }	 | j j d |	  }
 Wn' t t	 t
 | j f k
 r d }
 Yn X|
 d k	 r&| j |
 |  r&d } t d  } |  j d k r| |
 |  j  } | j   r#| j   t |  Sq>| |
  } n d } d } t d  } i | d	 6| d
 6| d 6} | d k	 ru| j |  n  t |  | |  S)zq
    View that checks the hash in a password reset link and presents a
    form for entering a new password.
    Npassword_reset_completepkTzEnter new passwordr1   FzPassword reset unsuccessfulr5   rD   	validlink)r   AssertionErrorr   r   r   r   Z_default_managerr&   	TypeError
ValueErrorOverflowErrorZDoesNotExistZcheck_tokenrG   r9   r1   r:   r[   r   r>   r   )r    Zuidb64tokenr?   rS   Zset_password_formr\   rA   Z	UserModeluiduserra   rD   r5   rC   r*   r*   r+   password_reset_confirm   s:    	

ri   z)registration/password_reset_complete.htmlc             C   sO   i t  t j  d 6t d  d 6} | d  k	 r? | j |  n  t |  | |  S)NrI   zPassword reset completerD   )r   r   rH   rG   r>   r   )r    r?   rA   rC   r*   r*   r+   r_     s    r_   z&registration/password_change_form.htmlc             C   s   | d  k r t  d  } n t |  } |  j d k r | d |  j d |  j  } | j   r | j   t |  | j  t |  Sn | d |  j  } i | d 6t	 d  d 6} | d  k	 r | j
 |  n  t |  | |  S)Npassword_change_doner1   rh   r2   r5   zPassword changerD   )r   r   r9   rh   r1   r:   r[   r   r   rG   r>   r   )r    r?   Zpost_change_redirectZpassword_change_formrA   r5   rC   r*   r*   r+   password_change*  s     	
rk   z&registration/password_change_done.htmlc             C   s?   i t  d  d 6} | d  k	 r/ | j |  n  t |  | |  S)NzPassword change successfulrD   )rG   r>   r   )r    r?   rA   rC   r*   r*   r+   rj   M  s
    rj   )=r-   r!   Zdjango.confr   Zdjango.contrib.authr   r   r   r<   r   rE   r   Zdjango.contrib.auth.decoratorsr   Zdjango.contrib.auth.formsr	   r
   r   r   Zdjango.contrib.auth.tokensr   Zdjango.contrib.sites.shortcutsr   Zdjango.core.urlresolversr   Zdjango.httpr   r   Zdjango.shortcutsr   Zdjango.template.responser   Zdjango.utils.deprecationr   r   Zdjango.utils.encodingr   Zdjango.utils.httpr   r   Z#django.utils.six.moves.urllib.parser   r   Zdjango.utils.translationr   rG   Zdjango.views.decorators.cacher   Zdjango.views.decorators.csrfr   Zdjango.views.decorators.debugr   r/   rJ   rQ   r^   rR   ri   r_   rk   rj   r*   r*   r*   r+   <module>   s   ("$!
(+