Updated requests script
This commit is contained in:
parent
117e63e189
commit
fbbdbd4332
1 changed files with 20 additions and 12 deletions
32
requests.sh
32
requests.sh
|
@ -1,15 +1,17 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ARG=$1
|
ACTION=$1
|
||||||
|
TOKEN=$2
|
||||||
ACTIONS=(login register rcvpw username)
|
ACTIONS=(login register rcvpw username)
|
||||||
|
|
||||||
print_help(){
|
print_help(){
|
||||||
echo "usage: $0 [action]"
|
echo "Usage: $0 ACTION [TOKEN]"
|
||||||
echo "available actions:"
|
echo
|
||||||
for el in ${ACTIONS[@]}; do
|
echo "available actions:"
|
||||||
echo - $el
|
for el in "${ACTIONS[@]}"; do
|
||||||
done
|
echo - "$el"
|
||||||
exit 1
|
done
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -z $1 ]]; then
|
if [[ -z $1 ]]; then
|
||||||
|
@ -17,20 +19,26 @@ if [[ -z $1 ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
case $ARG in
|
case $ACTION in
|
||||||
"${ACTIONS[0]}")
|
"${ACTIONS[0]}") # login
|
||||||
echo "login action"
|
echo "login action"
|
||||||
curl localhost:5050/api/login -X POST -d '{"username":"test","password":"test"}'
|
curl localhost:5050/api/login -X POST -d '{"username":"test","password":"test"}'
|
||||||
;;
|
;;
|
||||||
"${ACTIONS[1]}")
|
"${ACTIONS[1]}") # register
|
||||||
echo "register action"
|
echo "register action"
|
||||||
curl localhost:5050/api/register -X POST -d '{"username":"test","password":"test"}'
|
curl localhost:5050/api/register -X POST -d '{"username":"test","password":"test"}'
|
||||||
;;
|
;;
|
||||||
"${ACTIONS[2]}")
|
"${ACTIONS[2]}") # reveice password
|
||||||
echo "rcv_pw action"
|
echo "rcv_pw action"
|
||||||
|
curl localhost:5050/api/protected/rcv_pw
|
||||||
|
;;
|
||||||
|
"${ACTIONS[3]}") # get current username
|
||||||
|
echo "get username action"
|
||||||
|
curl localhost:5050/api/username -X GET -H "Authorization: Bearer $TOKEN"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Action not available"
|
echo "Error: Action not available"
|
||||||
|
echo
|
||||||
print_help
|
print_help
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue