addUsers.sh 1.01 KB
Newer Older
Marcos Viera's avatar
Marcos Viera committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /bin/bash

#todas las filas tienen que terminar con enter
INPUT=users.csv

SERVER=https://www.fing.edu.uy/proyectos/matefun/servicios
ROLE=docente #alumno

token=$(curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"cedula":"invitado","password":"invitado"}' \
  "$SERVER/login" | \
    python3 -c "import sys, json; print(json.load(sys.stdin)['token'])") 

while IFS=, read -r user name surname code; do
    echo "user: $user"
    hcode=$(echo -n "$code" | sha1sum | awk '{print $1}')
    echo "pass: $hcode"
    echo "token: $token"
    data='{ "rol": "'$ROLE'","cedula": "'$user'", "nombre": "'$name'","apellido": "'$surname'","password": "'$hcode'","configuracion": { "themeEditor": "dracula","fontSizeEditor": 12,"argumentoI": true,"argumentoF": true},"gruposAsignados": [],"archivos": []}'
    echo $data
    curl -H "Content-Type: application/json" -H "Authorization: Bearer $token" \
         --request POST \
         --data "$data" \
         "$SERVER/usuario/$ROLE/restore" 

done < $INPUT