*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    
*
*     generator users k existujicim clients do datastore 
*     na zacatku stahne clients, zapise do users
*
*  2023-10-25 - 
*
*
*
*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    


*HTTP_READ_ONLY_MODE = .T.

DO ppgm_http 

ACTIVATE SCREEN 
? "writing users .."
USE (m.gcpri_path + "stravnici_karty_web") 
SCAN
     vyrob_cloveka()
ENDSCAN 
CLOSE DATABASES 


*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
FUNCTION vyrob_cloveka ()

*user:   {"id":2,"username":"1565","first_name":"AntonUn","last_name":"Admek","email":"1565@fejk.cz","is_active":true,"is_staff":false,"is_superuser":false,,"has_password":true,"groups":["clients","diners"],"client":1,"pin":null},
*{"id":1195,"username":"65507","first_name":"Michal","last_name":"Dobeö","email":"dobes.m@fejk.cz","is_active":true,"is_staff":false,"is_superuser":false,"has_password":true,"groups":["clients"],"client":1196,"pin":null},
*{"id":1196,"username":"27","first_name":"Lucie","last_name":"Dobiöov","email":"dobiasova@fejk.cz","is_active":true,"is_staff":false,"is_superuser":false,"has_password":true,"groups":["clients"],"client":1197,"pin":null},

vysledek_vyroby = .T.
cl_id = stravnici_karty_web.id

username = ALLTRIM(stravnici_karty_web.client_id)

surname   = ALLTRIM(stravnici_karty_web.surname)
firstname = ALLTRIM(stravnici_karty_web.firstname)
email     = ALLTRIM(stravnici_karty_web.email)

cl_id = stravnici_karty_web.id
cl_id = stravnici_karty_web.id
cl_id = stravnici_karty_web.id

IF ISNULL(m.email) .or. EMPTY(m.email)
    email = m.username + "@fake.cz"
ENDIF 


rq_user = '{ "username":"' + m.username + '", "last_name":"' + m.surname + '", "first_name":"' + m.firstname + '", "email":"' + m.email + '", "password":"jidlovice", "is_active":true, "is_staff":false, "is_superuser":false,"groups":["clients"], "client":' + nx(m.cl_id) + ' }'

small_log(m.rq_user, "generuj_users")

json = http_request("auth/crud/users", "POST" , m.rq_user)
IF .not. json_ok(m.json)
    MESSAGEBOX(m.json, 1+16, "Nepodarilo se zapsat stravnika - users")
    vysledek_vyroby = .F.
ENDIF 
RETURN m.vysledek_vyroby

