
    d                         d dl mZmZ d dl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 d dlZd dlmZ d d	lmZ d
 Z e
d          dd            Z eddd           e
d          d                         ZdS )    )renderredirect)authenticateloginlogout)User)login_required)messages)VoterN)cache_control)HttpResponseRedirectc                 ,   d}| j         j        rt          d          S | j        dk    rW| j                            d                                                              dd                                          }| j                            d          }	 t          j
                            |          }n#  t          j        | d	           Y nxY wt          | ||
          }|t          | |           | j         j        j        dk    r,t          j        | d|j        z              t          d          S t'          |            t          j        | d           t          d          S t          j        | d           d|i}t)          | d|          S )Npresiding_logingenerate_tokenPOSTusername  password)r   zUser does not exist)r   r   TzLogged in as zYou are not authorizedz"Username OR password does not exitpagezpresiding/login.html)useris_authenticatedr   methodr   getlowerreplacestripr   objectsr
   errorr   r   userprofileis_presidingsuccessr   r   r   )requestr   r   r   r   contexts         *C:\xampp\htdocs\evoting\presiding\views.pyr   r      s   	D|$ *()))~<##J//5577??RHHNNPP<##J//	;<##X#66DD	;N7$9:::::GhJJJ'4   |'4<< /$-*GHHH 0111ww(@AAA 1222N7$HIII tnG'17;;;s    B8 8Cr   )	login_urlr   c                 ,   d}| j         dk    rpd}d}d}t          |          D ]B}t          j        |d          t          j        |d          z   }d                    |          }	C| j                            d                                                                          }
| j                            d	                                                                          }| j                            d
                                                                          }| j                            d                                                                          }| j                            d                                                                          }| j                            d                                                                          }| j                            d                                                                          }| j                            d                                                                          }t          |
          t          |          z   t          |          z   t          |          z   t          |          z   t          |          z   t          |          z   t          |          z   }|
                    dd          }|
                    dd          }|
                    dd          }|
                    dd          }t          j                            ||	d           t          j        | d|z              |||	d}t!          | d|          S |||d}t!          | d|          S )Ntokenr   
CDHKPQRVXY	123456789      r   firstsecondthirdfourthfifthsixthseventheighth,()'F)voter_roll_numbervoter_token_numbervoter_token_flagzToken Generated for : )r   rluczpresiding/token.html)r   rangerandomsamplejoinr   r   upperr   strr   r   r   creater
   r"   r   )r#   r<   r=   r   charsnumstotaliselectsunique_coder-   r.   r/   r0   r1   r2   r3   r4   roll_numberr$   s                       r%   r   r   .   s"   	D~u 	+ 	+AmE1--dA0F0FFG'''**KK  ))//117799!!(++113399;;  ))//117799!!(++113399;;  ))//117799  ))//117799,""9--3355;;==!!(++113399;;%jj3v;;.U;c&kkICPUJJVY\]bYcYccfijqfrfrruxy  vA  vA  A!))#r22!))#r22!))#r22!))#r22 +!,$ 	 	
 	
 	

 	":;"FGGG{+FFg5w??? 2R00G'17;;;    T)no_cachemust_revalidateno_storec                 h    t          |            t          j        | d           t          d          S )NzYou are logged outzpresiding-officer-login)r   r
   r   r   )r#   s    r%   presiding_logoutrQ   V   s1     7OOON70111 9:::rL   )r   r   )django.shortcutsr   r   django.contrib.authr   r   r   django.contrib.auth.modelsr   django.contrib.auth.decoratorsr	   django.contribr
   presiding.modelsr   r?   django.views.decorators.cacher   django.httpr   r   r   rQ    rL   r%   <module>r[      sA   - - - - - - - - ; ; ; ; ; ; ; ; ; ; + + + + + + 9 9 9 9 9 9 # # # # # # " " " " " "  7 7 7 7 7 7 , , , , , ,< < <D +,,,$< $< $< -,$<N dTBBB+,,,; ; -, CB; ; ;rL   