B
    £0H[X  ã               @   s¼  d dl Z d dlmZm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( d dl)m*Z*m+Z+ d dl,m-Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 eƒ Z9G dd„ dƒZ:G dd„ de:e8ƒZ;deeddfdd„Z	G dd „ d e:e6ƒZ<dd!edfd"d#„Ze=ƒ Z>de>fd$d%„Z?defd&d'„Z@e2d(d)d*eedddddf
d+d,„ƒZAdLd.d/„ZBe4ƒ e0ddd0eeddfd1d2„ƒƒZCdMd4d5„ZDG d6d7„ d7ƒZEG d8d9„ d9eEe8ƒZFd:ZGd;ZHG d<d=„ d=eEe6ƒZIG d>d?„ d?eEe8ƒZJG d@dA„ dAeEe6ƒZKe4ƒ e2edBdedfdCdD„ƒƒƒZLedNdFdG„ƒZMG dHdI„ dIeEe8ƒZNG dJdK„ dKeEe6ƒZOdS )Oé    N)ÚurlparseÚ
urlunparse)Ú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)ÚValidationError)ÚHttpResponseRedirectÚ	QueryDict)Úresolve_url)ÚTemplateResponse)ÚreverseÚreverse_lazy)Úmethod_decorator)ÚRemovedInDjango21Warning)Úis_safe_urlÚurlsafe_base64_decode)Úgettext_lazy)Únever_cache)Úcsrf_protect)Úsensitive_post_parameters)ÚTemplateView)ÚFormViewc               @   s   e Zd Zeƒ Zdd„ ZdS )ÚSuccessURLAllowedHostsMixinc             C   s   | j  ¡ h}| | j¡ |S )N)ÚrequestÚget_hostÚupdateÚsuccess_url_allowed_hosts)ÚselfÚallowed_hosts© r)   ú]C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\auth\views.pyÚget_success_url_allowed_hosts%   s    z9SuccessURLAllowedHostsMixin.get_success_url_allowed_hostsN)Ú__name__Ú
__module__Ú__qualname__Úsetr&   r+   r)   r)   r)   r*   r"   "   s   r"   c                   sŠ   e Zd ZdZeZdZeZdZ	dZ
dZeeƒ ƒeeƒeeƒ‡ fdd„ƒƒƒZdd„ Zd	d
„ Zdd„ Z‡ fdd„Zdd„ Z‡ fdd„Z‡  ZS )Ú	LoginViewz=
    Display the login form and handle the login action.
    Nzregistration/login.htmlFc                sH   | j r4| jjjr4|  ¡ }|| jjkr,tdƒ‚t|ƒS tƒ j	|f|ž|ŽS )NzsRedirection loop for authenticated user detected. Check that your LOGIN_REDIRECT_URL doesn't point to a login page.)
Úredirect_authenticated_userr#   ÚuserÚis_authenticatedÚget_success_urlÚpathÚ
ValueErrorr   ÚsuperÚdispatch)r'   r#   ÚargsÚkwargsÚredirect_to)Ú	__class__r)   r*   r8   6   s    zLoginView.dispatchc             C   s   |   ¡ }|pttjƒS )N)Úget_redirect_urlr   r   ZLOGIN_REDIRECT_URL)r'   Úurlr)   r)   r*   r4   D   s    zLoginView.get_success_urlc             C   sD   | j j | j| j j | jd¡¡}t||  ¡ | j  ¡ d�}|r@|S dS )z6Return the user-originating redirect URL if it's safe.Ú )r>   r(   Úrequire_https)r#   ÚPOSTÚgetÚredirect_field_nameÚGETr   r+   Ú	is_secure)r'   r;   Úurl_is_safer)   r)   r*   r=   H   s    zLoginView.get_redirect_urlc             C   s   | j p
| jS )N)Úauthentication_formÚ
form_class)r'   r)   r)   r*   Úget_form_classU   s    zLoginView.get_form_classc                s   t ƒ  ¡ }| j|d< |S )Nr#   )r7   Úget_form_kwargsr#   )r'   r:   )r<   r)   r*   rJ   X   s    

zLoginView.get_form_kwargsc             C   s   t | j| ¡ ƒ t|  ¡ ƒS )z)Security check complete. Log the user in.)Ú
auth_loginr#   Úget_userr   r4   )r'   Úformr)   r)   r*   Ú
form_valid]   s    zLoginView.form_validc                sP   t ƒ jf |Ž}t| jƒ}| | j|  ¡ d|d|ji¡ | jd k	rL| | j¡ |S )NÚsiteÚ	site_name)	r7   Úget_context_datar   r#   r%   rC   r=   ÚnameÚextra_context)r'   r:   ÚcontextÚcurrent_site)r<   r)   r*   rQ   b   s    


zLoginView.get_context_data)r,   r-   r.   Ú__doc__r   rH   rG   r   rC   Útemplate_namer1   rS   r   r   r   r   r8   r4   r=   rI   rJ   rN   rQ   Ú__classcell__r)   r)   )r<   r*   r0   +   s    r0   zregistration/login.htmlFc             C   s(   t jdtdd� tj|||||d�| ƒS )Nz>The login() view is superseded by the class-based LoginView().é   )Ú
stacklevel)rW   rC   rH   rS   r1   )ÚwarningsÚwarnr   r0   Úas_view)r#   rW   rC   rG   rS   r1   r)   r)   r*   r   o   s    
r   c                   sT   e Zd ZdZdZeZdZdZe	e
ƒ‡ fdd„ƒZdd„ Zdd	„ Z‡ fd
d„Z‡  ZS )Ú
LogoutViewzH
    Log out the user and display the 'You are logged out' message.
    Nzregistration/logged_out.htmlc                s0   t |ƒ |  ¡ }|rt|ƒS tƒ j|f|ž|ŽS )N)Úauth_logoutÚget_next_pager   r7   r8   )r'   r#   r9   r:   Ú	next_page)r<   r)   r*   r8   ‰   s
    zLogoutView.dispatchc             O   s   | j |f|ž|ŽS )zLogout may be done via POST.)rB   )r'   r#   r9   r:   r)   r)   r*   Úpost’   s    zLogoutView.postc             C   s�   | j d k	rt| j ƒ}ntjr(ttjƒ}n| j }| j| jjksJ| j| jjkrŒ| jj | j| jj | j¡¡}t	||  
¡ | j ¡ d�}|sŒ| jj}|S )N)r>   r(   r@   )ra   r   r   ZLOGOUT_REDIRECT_URLrC   r#   rA   rD   rB   r   r+   rE   r5   )r'   ra   rF   r)   r)   r*   r`   –   s"    
zLogoutView.get_next_pagec                sJ   t ƒ jf |Ž}t| jƒ}| ||jtdƒdœ¡ | jd k	rF| | j¡ |S )Nz
Logged out)rO   rP   Útitle)r7   rQ   r   r#   r%   rR   Ú_rS   )r'   r:   rT   rU   )r<   r)   r*   rQ   ¯   s    

zLogoutView.get_context_data)r,   r-   r.   rV   ra   r   rC   rW   rS   r   r   r8   rb   r`   rQ   rX   r)   r)   )r<   r*   r^   €   s   	r^   zregistration/logged_out.htmlc             C   s&   t jdtdd� tj||||d�| ƒS )Nz@The logout() view is superseded by the class-based LogoutView().rY   )rZ   )ra   rW   rC   rS   )r[   r\   r   r^   r]   )r#   ra   rW   rC   rS   r)   r)   r*   r   ¼   s    
r   c             C   s6   |t k	rt dt¡ |stj}t|ƒ}tj|d�| ƒS )zR
    Log out the user if they are logged in. Then redirect to the login page.
    zJThe unused `extra_context` parameter to `logout_then_login` is deprecated.)ra   )	Ú	_sentinelr[   r\   r   r   Ú	LOGIN_URLr   r^   r]   )r#   Ú	login_urlrS   r)   r)   r*   Úlogout_then_loginÏ   s    rh   c             C   sR   t |p
tjƒ}tt|ƒƒ}|rFt|d dd�}| ||< |jdd�|d< tt|ƒƒS )zM
    Redirect the user to the login page, passing the given 'next' page.
    é   T)Zmutableú/)Úsafe)	r   r   rf   Úlistr   r   Ú	urlencoder   r   )Únextrg   rC   Zresolved_urlZlogin_url_partsZquerystringr)   r)   r*   Úredirect_to_loginß   s    ro   z%registration/password_reset_form.htmlz&registration/password_reset_email.htmlz'registration/password_reset_subject.txtc          	   C   s¨   t jdtdd� |d kr"tdƒ}nt|ƒ}| jdkrv|| jƒ}| ¡ r||  ¡ ||||| |	|
dœ}|j	f |Ž t
|ƒS n|ƒ }|tdƒdœ}|d k	rœ| |¡ t| ||ƒS )	NzOThe password_reset() view is superseded by the class-based PasswordResetView().rY   )rZ   Úpassword_reset_donerA   )Ú	use_httpsÚtoken_generatorÚ
from_emailÚemail_template_nameÚsubject_template_namer#   Úhtml_email_template_nameÚextra_email_contextzPassword reset)rM   rc   )r[   r\   r   r   r   ÚmethodrA   Úis_validrE   Úsaver   rd   r%   r   )r#   rW   rt   ru   Zpassword_reset_formrr   Úpost_reset_redirectrs   rS   rv   rw   rM   ÚoptsrT   r)   r)   r*   Úpassword_resetõ   s0    





r}   ú%registration/password_reset_done.htmlc             C   s:   t jdtdd� dtdƒi}|d k	r.| |¡ t| ||ƒS )NzXThe password_reset_done() view is superseded by the class-based PasswordResetDoneView().rY   )rZ   rc   zPassword reset sent)r[   r\   r   rd   r%   r   )r#   rW   rS   rT   r)   r)   r*   rp   #  s    

rp   z(registration/password_reset_confirm.htmlc             C   s  t jdtdd� |dk	r |dk	s$t‚|dkr6tdƒ}nt|ƒ}yt|ƒ ¡ }tj	j
|d�}	W n" ttttjfk
r~   d}	Y nX |	dk	rÚ| |	|¡rÚd}
tdƒ}| jd	krÐ||	| jƒ}| ¡ rØ| ¡  t|ƒS qê||	ƒ}nd
}
d}tdƒ}|||
dœ}|dk	�r
| |¡ t| ||ƒS )ze
    Check the hash in a password reset link and present a form for entering a
    new password.
    z^The password_reset_confirm() view is superseded by the class-based PasswordResetConfirmView().rY   )rZ   NÚpassword_reset_complete)ÚpkTzEnter new passwordrA   FzPassword reset unsuccessful)rM   rc   Ú	validlink)r[   r\   r   ÚAssertionErrorr   r   r   ÚdecodeÚ	UserModelÚ_default_managerrB   Ú	TypeErrorr6   ÚOverflowErrorÚDoesNotExistÚcheck_tokenrd   rx   rA   ry   rz   r   r%   r   )r#   Úuidb64ÚtokenrW   rr   Zset_password_formr{   rS   Úuidr2   r�   rc   rM   rT   r)   r)   r*   Úpassword_reset_confirm3  s:    







r�   ú)registration/password_reset_complete.htmlc             C   sB   t jdtdd� ttjƒtdƒdœ}|d k	r6| |¡ t| ||ƒS )Nz`The password_reset_complete() view is superseded by the class-based PasswordResetCompleteView().rY   )rZ   zPassword reset complete)rg   rc   )	r[   r\   r   r   r   rf   rd   r%   r   )r#   rW   rS   rT   r)   r)   r*   r   g  s    

r   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚPasswordContextMixinNc                s2   t ƒ jf |Ž}| j|d< | jd k	r.| | j¡ |S )Nrc   )r7   rQ   rc   rS   r%   )r'   r:   rT   )r<   r)   r*   rQ   �  s
    

z%PasswordContextMixin.get_context_data)r,   r-   r.   rS   rQ   rX   r)   r)   )r<   r*   r�   ~  s   r�   c                   s`   e Zd ZdZdZeZdZdZdZ	e
dƒZdZedƒZeZeeƒ‡ fdd„ƒZ‡ fd	d
„Z‡  ZS )ÚPasswordResetViewz&registration/password_reset_email.htmlNz'registration/password_reset_subject.txtrp   z%registration/password_reset_form.htmlzPassword resetc                s   t ƒ j||ŽS )N)r7   r8   )r'   r9   r:   )r<   r)   r*   r8   •  s    zPasswordResetView.dispatchc          	      sB   | j  ¡ | j| j| j| j| j | j| jdœ}|jf |Ž t	ƒ  
|¡S )N)rq   rr   rs   rt   ru   r#   rv   rw   )r#   rE   rr   rs   rt   ru   rv   rw   rz   r7   rN   )r'   rM   r|   )r<   r)   r*   rN   ™  s    
zPasswordResetView.form_valid)r,   r-   r.   rt   rw   r   rH   rs   rv   ru   r   Úsuccess_urlrW   rd   rc   r   rr   r   r   r8   rN   rX   r)   r)   )r<   r*   r�   ‰  s   r�   zset-passwordZ_password_reset_tokenc               @   s   e Zd ZdZedƒZdS )ÚPasswordResetDoneViewz%registration/password_reset_done.htmlzPassword reset sentN)r,   r-   r.   rW   rd   rc   r)   r)   r)   r*   r’   ¬  s   r’   c                   s~   e Zd ZeZdZdZedƒZdZ	e
dƒZeZeeƒ ƒeeƒ‡ fdd„ƒƒZdd	„ Z‡ fd
d„Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚPasswordResetConfirmViewFNr   z(registration/password_reset_confirm.htmlzEnter new passwordc                sº   d|krd|kst ‚d| _|  |d ¡| _| jd k	r¬|d }|tkrx| jj t¡}| j	 
| j|¡r¬d| _tƒ j||ŽS n4| j	 
| j|¡r¬|| jjt< | jj |t¡}t|ƒS |  |  ¡ ¡S )NrŠ   r‹   FT)r‚   r�   rL   r2   ÚINTERNAL_RESET_URL_TOKENr#   ÚsessionrB   ÚINTERNAL_RESET_SESSION_TOKENrr   r‰   r7   r8   r5   Úreplacer   Zrender_to_responserQ   )r'   r9   r:   r‹   Zsession_tokenZredirect_url)r<   r)   r*   r8   º  s    
z!PasswordResetConfirmView.dispatchc             C   sH   yt |ƒ ¡ }tjj|d�}W n$ ttttjt	fk
rB   d }Y nX |S )N)r€   )
r   rƒ   r„   r…   rB   r†   r6   r‡   rˆ   r   )r'   rŠ   rŒ   r2   r)   r)   r*   rL   ×  s    
z!PasswordResetConfirmView.get_userc                s   t ƒ  ¡ }| j|d< |S )Nr2   )r7   rJ   r2   )r'   r:   )r<   r)   r*   rJ   à  s    

z(PasswordResetConfirmView.get_form_kwargsc                s4   |  ¡ }| jjt= | jr(t| j|| jƒ tƒ  |¡S )N)	rz   r#   r•   r–   Úpost_reset_loginrK   Úpost_reset_login_backendr7   rN   )r'   rM   r2   )r<   r)   r*   rN   å  s
    
z#PasswordResetConfirmView.form_validc                s8   t ƒ jf |Ž}| jrd|d< n| d tdƒddœ¡ |S )NTr�   zPassword reset unsuccessfulF)rM   rc   r�   )r7   rQ   r�   r%   rd   )r'   r:   rT   )r<   r)   r*   rQ   ì  s    

z)PasswordResetConfirmView.get_context_data)r,   r-   r.   r   rH   r˜   r™   r   r‘   rW   rd   rc   r   rr   r   r   r   r8   rL   rJ   rN   rQ   rX   r)   r)   )r<   r*   r“   ±  s   	r“   c                   s(   e Zd ZdZedƒZ‡ fdd„Z‡  ZS )ÚPasswordResetCompleteViewz)registration/password_reset_complete.htmlzPassword reset completec                s    t ƒ jf |Ž}ttjƒ|d< |S )Nrg   )r7   rQ   r   r   rf   )r'   r:   rT   )r<   r)   r*   rQ   ý  s    z*PasswordResetCompleteView.get_context_data)r,   r-   r.   rW   rd   rc   rQ   rX   r)   r)   )r<   r*   rš   ù  s   rš   z&registration/password_change_form.htmlc             C   s¢   t jdtdd� |d kr"tdƒ}nt|ƒ}| jdkrj|| j| jd�}| ¡ rv| 	¡  t
| |jƒ t|ƒS n|| jd�}|tdƒd	œ}|d k	r–| |¡ t| ||ƒS )
NzQThe password_change() view is superseded by the class-based PasswordChangeView().rY   )rZ   Úpassword_change_donerA   )r2   Údata)r2   zPassword change)rM   rc   )r[   r\   r   r   r   rx   r2   rA   ry   rz   r	   r   rd   r%   r   )r#   rW   Zpost_change_redirectZpassword_change_formrS   rM   rT   r)   r)   r*   Úpassword_change  s"    




r�   ú&registration/password_change_done.htmlc             C   s:   t jdtdd� dtdƒi}|d k	r.| |¡ t| ||ƒS )NzZThe password_change_done() view is superseded by the class-based PasswordChangeDoneView().rY   )rZ   rc   zPassword change successful)r[   r\   r   rd   r%   r   )r#   rW   rS   rT   r)   r)   r*   r›   &  s    

r›   c                   sf   e Zd ZeZedƒZdZedƒZ	e
eƒ ƒe
eƒe
eƒ‡ fdd„ƒƒƒZ‡ fdd„Z‡ fdd	„Z‡  ZS )
ÚPasswordChangeViewr›   z&registration/password_change_form.htmlzPassword changec                s   t ƒ j||ŽS )N)r7   r8   )r'   r9   r:   )r<   r)   r*   r8   <  s    zPasswordChangeView.dispatchc                s   t ƒ  ¡ }| jj|d< |S )Nr2   )r7   rJ   r#   r2   )r'   r:   )r<   r)   r*   rJ   B  s    
z"PasswordChangeView.get_form_kwargsc                s"   |  ¡  t| j|jƒ tƒ  |¡S )N)rz   r	   r#   r2   r7   rN   )r'   rM   )r<   r)   r*   rN   G  s    zPasswordChangeView.form_valid)r,   r-   r.   r   rH   r   r‘   rW   rd   rc   r   r   r   r
   r8   rJ   rN   rX   r)   r)   )r<   r*   rŸ   6  s   rŸ   c                   s0   e Zd ZdZedƒZeeƒ‡ fdd„ƒZ‡  Z	S )ÚPasswordChangeDoneViewz&registration/password_change_done.htmlzPassword change successfulc                s   t ƒ j||ŽS )N)r7   r8   )r'   r9   r:   )r<   r)   r*   r8   S  s    zPasswordChangeDoneView.dispatch)
r,   r-   r.   rW   rd   rc   r   r
   r8   rX   r)   r)   )r<   r*   r    O  s   r    )r~   N)rŽ   N)rž   N)Pr[   Úurllib.parser   r   Zdjango.confr   Zdjango.contrib.authr   r   r   rK   r   r_   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.exceptionsr   Zdjango.httpr   r   Zdjango.shortcutsr   Zdjango.template.responser   Zdjango.urlsr   r   Zdjango.utils.decoratorsr   Zdjango.utils.deprecationr   Zdjango.utils.httpr   r   Zdjango.utils.translationr   rd   Zdjango.views.decorators.cacher   Zdjango.views.decorators.csrfr   Zdjango.views.decorators.debugr   Zdjango.views.generic.baser    Zdjango.views.generic.editr!   r„   r"   r0   r^   Úobjectre   rh   ro   r}   rp   r�   r   r�   r�   r”   r–   r’   r“   rš   r�   r›   rŸ   r    r)   r)   r)   r*   Ú<module>   sœ   	D<$ 
. 
H
 