-
Notifications
You must be signed in to change notification settings - Fork 0
/
initialize_users.ps1
43 lines (37 loc) · 1.52 KB
/
initialize_users.ps1
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Endpoint and credentials for sign-in
$signInUrl = "https://localhost:7283/users-module/users/sign-in"
$signInPayload = @{
email = "[email protected]"
password = "garageGenius"
} | ConvertTo-Json
# Use Invoke-RestMethod to sign in and extract the bearer token
# Note: Adding -SkipCertificateCheck for ignoring SSL errors on localhost. Remove in production.
$response = Invoke-RestMethod -Uri $signInUrl -Method Post -Body $signInPayload -ContentType "application/json"
$token = $response.accessToken
if (-not $token) {
Write-Host "Failed to get token"
exit 1
}
# Function to sign up users with different roles
Function SignUpUser($url, $email, $role) {
$signUpPayload = @{
email = $email
password = "garageGenius"
role = $role
} | ConvertTo-Json
# Use Invoke-RestMethod to sign up using the obtained bearer token
try {
$response = Invoke-RestMethod -Uri $url -Method Post -Body $signUpPayload -ContentType "application/json" -Headers @{Authorization = "Bearer $token" }
Write-Output $response.customerId
}
catch {
Write-Error $_.Exception.Message
}
}
# Endpoint for sign-up
$signUpUrl = "https://localhost:7283/users-module/users/sign-up"
# Sign up users with different roles
SignUpUser $signUpUrl "[email protected]" "administrator"
SignUpUser $signUpUrl "[email protected]" "manager"
SignUpUser $signUpUrl "[email protected]" "employee"
SignUpUser $signUpUrl "[email protected]" "customer"