
    wh                         d dl Z d dl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mZ ddlmZ e	d        Ze	d        Zd Ze	d        Ze	d        Ze	d        Zy)    N)JsonResponse)render)status)csrf_exempt)settings   )send_otp_to_phone)generate_access_tokenverify_token)DriverPartnersUser)DriverSerializerc                    	 t        j                  | j                        }t        j                  j                  |d   d      }dj                  d t        d      D              }d}t        |d   |      }|rN|| j                  d<   |d   | j                  d<   t        d	t        j                  d
dt        j                        S 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)Nmobile   )r   	user_type c              3   F   K   | ]  }t        j                  d         yw)
1234567890N)randomchoice).0is     T/mnt/ACDE16A4DE16673C/PROJECTS/DRIVERZZ/DRIVERZZ_DRIVER_APIS/authentication/views.py	<genexpr>zrequestOtp.<locals>.<genexpr>   s     Eqv}}\2Es   !   1234otpzOTP sent to registered Mobilemessager   Fsafer   z-Something went wrong. Please try again later.zMobile no. doesn't exists)jsonloadsbodyr   objectsgetjoinranger	   sessionr   r   HTTP_200_OKHTTP_400_BAD_REQUESTDoesNotExist	Exceptionprint)requestrequest_datauserr   responsees         r   
requestOtpr5      s   qzz',,/||h)?QOggEE!HEF$\(%;SA%(GOOE"(4X(>GOOH%-LW]WiWi jqv  @F  @R  @R  S  S-\gm  hC  hC  !D  KP  Y_  Yt  Yt  u  u ])DvOjOjkrw  AG  A\  A\  ]  	] qa)Xcic~c~  GL  U[  Up  Up  q  	qqs+   CC4 ,C4 4A F 6F >7E;5F ;F c                 "   t        j                  | j                        }|d   }|| j                  d   k(  rg	 t        j
                  j                  | j                  d         }t        |      }t        d|t        j                  ddt        j                        S t        d
t        j                  d	dt        j                        S # t        j                  $ r0 t        dt        j                  d	dt        j                        cY S w xY w)Nr   r   )r   zOtp Matched successfully)r    tokenr   Fr!   zUser doesn't exists.r   zOtp not Matched)r#   r$   r%   r*   r   r&   r'   r
   r   r   r+   r-   r,   )r0   r1   r   r2   r7   s        r   	verifyOtpr8   %   s   ::gll+L
u
C
gooe$$	Y<<##W__X-F#GD)$/E,FRWbhbtbt u  }B  KQ  K]  K]  ^  ^ (96C^C^_ejsy  tO  tO  P  	P    	Y,BFLgLg hns  }C  }X  }X  Y  Y	Ys   A%C A DDc                 x    t        t        j                  t        j                  ddt        j                        S )N)show_deleter   Fr!   )r   r   SHOW_DELETEr   r+   )r0   s    r   
showDeleter<   4   s8    )=)=HZHZ[bgpv  qC  qC  D  D    c                 v   t        |       }|d k(  r-t        dt        j                  ddt        j                        S 	 t        j
                  j                  |      j                          t        dt        j                  ddt        j                        S # t        $ r}t        |       Y d }~Fd }~ww xY w)NUser not logged in.r   Fr!   idzAccount deleted successfully.)r   r   r   HTTP_401_UNAUTHORIZEDr   r&   r'   deleter.   r/   r+   )r0   user_idr4   s      r   deleteAccountrE   8   s    7#G$)>IeIefns  }C  }Y  }Y  Z  	Z	LL'*113 )HSYSeSefns  }C  }O  }O  P  	P  	!HH	s   .B 	B8#B33B8c                    t        |       }|d k(  r-t        dt        j                  ddt        j                        S 	 t        j
                  j                  |      }t        d|j                  |j                  |j                  t        j                  ddt        j                        S # t        j                  $ r0 t        dt        j                  ddt        j                        cY S w xY w)Nr?   r   Fr!   r@   zuser is verified.)r    nameemailr   r   )r   r   r   rB   r   r&   r'   rG   rH   r   r+   r-   )r0   rD   r2   s      r   
verifyUserrI   E   s   7#G$)>IeIefns  }C  }Y  }Y  Z  	Z	^<<###1D-@499`d`j`jw{  xC  xC  NT  N`  N`  !a  in  w}  wI  wI  J  J   	^-BVMiMi jrw  AG  A]  A]  ^  ^	^s   A-B- -A C0/C0c                    t        |       }|d k(  r-t        dt        j                  ddt        j                        S 	 t        j
                  j                  |      }t        |d      }t        |j                  dt        j                  ddt        j                        S # t        j                  $ r0 t        dt        j                  ddt        j                        cY S w xY w)	Nr?   r   Fr!   )rD   )manyzProfile updated successfully.)driverr    r   )r   r   r   rB   r   r&   r'   r   datar+   r   r-   )r0   rD   rL   
serializers       r   profilerO   S   s
   7#G$)>IeIefns  }C  }Y  }Y  Z  	Z	^#++//'/BF)&u=JJOOIhsy  tF  tF  !G  OT  ]c  ]o  ]o  p  p   	^-BVMiMi jrw  AG  A]  A]  ^  ^	^s   A$B$ $A C'&C')r#   r   django.httpr   django.shortcutsr   rest_frameworkr   django.views.decorators.csrfr   DRIVERZZ_DRIVER_APISr   helpersr	   authr
   r   modelsr   r   serializersr   r5   r8   r<   rE   rI   rO    r=   r   <module>rZ      s      $ # ! 4 ) & 5 ( ) q q( P PD 	P 	P 	^ 	^ 
^ 
^r=   