
    g                     
   d dl 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 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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD  eed       G d d e	             ZEd! ZFd" ZGed#        ZHed$        ZIed%        ZJ G d& d'e	      ZKy)(    N)settings)JsonResponse)renderredirect)View)EmailBackEnd)loginlogout)messages)csrf_exempt)status)User)render_to_string)
strip_tags)	send_mailEmailMultiAlternatives)method_decorator)ExistsOuterRefSumQFSubqueryCaseWhenValue
FloatField	CharField)Occupations)
CategoriesSchemes)Important_Documents)Important_Portals)Scheme_Announcements)Testimonials)Artificial_Intelligence)Business_Plans)Legal_Registrations)	Marketing)Organization_Registration)	Helplinespost)namec                       e Zd Zd Zd Zy)	LoginViewc                     t        |d      S )Ncustom_admin/login.htmlr   selfrequests     5/var/www/html/SAHYOG_SETU_ADMIN/custom_admin/views.pygetzLoginView.get#   s    w 9:	:    c                     |j                   d   }|j                   d   }t        j                  |||      }|5|j                  dk(  rt	        ||       t        d      S t        |dddi      S t        |dddi      S )	NemailIdpassword)usernamer;      adminDashboardr1   errorzInvalid email Id or password)POSTr   authenticate	user_typer	   r   r   )r4   r5   r:   r;   users        r6   r,   zLoginView.post'   s    ,,y)<<
+((WPXY~~"gt$ 011g'@7MkBlmm'#<wIg>hiir8   N)__name__
__module____qualname__r7   r,    r8   r6   r/   r/   !   s    ;jr8   r/   c                    t        t        j                  j                               }t        t        j                  j                               }t        t
        j                  j                  d            }t        t
        j                  j                  d            }t        t        j                  j                               }t        t        j                  j                               }t        t        j                  j                               }t        t        j                  j                               }t        t        j                  j                  d            }	t        t        j                  j                               }
t        t        j                  j                               }t        t        j                  j                               }t        t        j                  j                               }t        t         j                  j                               }t        t"        j                  j                               }t%        | d|||||
|||||||||	|d      S )Nr=   )scheme_typer      )rB   zcustom_admin/dashboard.html)organization_registration	marketinglegal_registrationsbusiness_plansartificial_intelligenceoccupations
categoriesstate_schemescentral_schemesimportant_documentsimportant_portalsscheme_announcementstestimonialsvisitors	helplines)lenr   objectsallr    r!   filterr"   r#   r$   r%   r   r&   r'   r(   r)   r*   r+   r   )r5   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rO   rN   rM   rL   rK   rY   s                   r6   	dashboardr^   7   s   k))--/0KZ''++-.J..Q.?@M'//00q0ABO199==?@-5599;<3;;??AB|++//12L4<<&&1&56H!"9"A"A"E"E"GH//3356N199==?@I%%))+,I #$=$E$E$I$I$K LI%%))+,I'8Yr  CL  ex  M[  yP  bm  ~H  \i  N  h{  Sd  S  fr  A	I	  Y	b	  ;c	  d	  d	r8   c                     t        | d      S )Nz/custom_admin/reset-password/reset_password.htmlr2   )r5   s    r6   resetPasswordr`   M   s    'LMMr8   c                 j   	 t         j                  j                  | j                  j                  d            }dj	                  d t        d      D              }|| j                  d<   |j                  | j                  d<   d}|j                  g}t        d	t        j                  |j                  |d
      }t        |      }t        ||t        j                  |      }|j!                  |d       |j#                          t%        dt&        j(                  ddt&        j(                        S # t         j*                  $ r0 t%        dt&        j,                  ddt&        j,                        cY S t.        $ r7}t%        dt&        j,                  ddt&        j,                        cY d }~S d }~ww xY w)Nemail)rb    c              3   F   K   | ]  }t        j                  d         yw)
1234567890N)randomchoice).0is     r6   	<genexpr>zrequestOtp.<locals>.<genexpr>W   s     Eqv}}\2Es   !   otpuser_idzTry On Trends OTP requestz-custom_admin/reset-password/otp-template.html)logor-   rl   z	text/htmlzOTP sent to registered Emailmessager   Fsafer   zOTP unable to sent.-Something went wrong. Please try again later.)r   r[   r7   r@   joinrangesessionidrb   r   r   LOGO_URLr-   r   r   EMAIL_HOST_USERattach_alternativesendr   r   HTTP_200_OKDoesNotExistHTTP_400_BAD_REQUEST	Exception)	r5   rC   rl   subjectto_emailhtml_templatetext_contentrb   es	            r6   
requestOtpr   S   s   q||(8(8(ADggEE!HEF!$%)WW	"-JJ<()Xdldudu  AE  AJ  AJ  UX  [Y  Z!-0&wh>V>VX`a  <

)GRXRdRdelq  {A  {M  {M  N  	N W)>IdIdelq  {A  {V  {V  W  	W q)Xcic~c~  GL  U[  Up  Up  q  	qqs%   D.D1 1A F23F2;,F-'F2-F2c                    | j                   j                  d      }|| j                  d   k(  r-t        dt        j
                  ddt        j
                        S t        dt        j                  ddt        j                        S )Nrl   zOTP Matchedro   Frq   zOTP Not Matched)r@   r7   rv   r   r   r|   r~   )r5   rl   s     r6   	verifyOtpr   i   sz    
,,

5
!C
gooe$$ASAST[`ioi{i{||):VE`E`ahmv|  wR  wR  S  	Sr8   c                 N   	 | j                   j                  d      }t        j                  j                  | j                  d         }|j                  |       |j                          t        dt        j                  ddt        j                        S # t        j                  $ r0 t        dt        j                  ddt        j                        cY S t        $ rB}t        |       t        d	t        j                  ddt        j                        cY d }~S d }~ww xY w)
Nr;   rm   )rw   zpassword changed succesfullyro   Frq   zUser does't existrs   )r@   r7   r   r[   rv   set_passwordsaver   r   r|   r}   r~   r   print)r5   r;   rC   r   s       r6   changePasswordr   r   s   
o<<##J/||W__Y%?@(#		'EPVPbPbcjox~  yK  yK  L  	L S':VE`E`ahmv|  wR  wR  S  	S oa'Vaga|a|}  EJ  SY  Sn  Sn  o  	oos%   BB A D$D$"7DD$D$c                       e Zd Zd Zy)
LogoutViewc                 .    t        |       t        d      S )N
adminLogin)r
   r   r3   s     r6   r7   zLogoutView.get   s    w%%r8   N)rD   rE   rF   r7   rG   r8   r6   r   r      s    &r8   r   )Lrf   django.confr   django.httpr   django.shortcutsr   r   django.viewsr   accounts.EmailBackEndr   django.contrib.authr	   r
   django.contribr   django.views.decorators.csrfr   rest_frameworkr   accounts.modelsr   django.template.loaderr   django.utils.htmlr   django.core.mailr   r   django.utils.decoratorsr   django.db.modelsr   r   r   r   r   r   r   r   r   r   r   occupations.modelsr   schemes.modelsr    r!   important_documents.modelsr"   important_portals.modelsr#   scheme_announcements.modelsr$   testimonials.modelsr%   /entrepreneurship.artificial_intelligence.modelsr&   &entrepreneurship.business_plans.modelsr'   +entrepreneurship.legal_registrations.modelsr(   !entrepreneurship.marketing.modelsr)   2entrepreneurship.organization_registrations.modelsr*   helplines.modelsr+   r/   r^   r`   r   r   r   r   rG   r8   r6   <module>r      s       $ -  . - # 4 !   3 ( > 4 l l l l * . : 6 < , S A K 7 X &+F+j j ,j*d	,N q q* S S o o& &r8   