From 117e63e189115191b3e80824e59b3f14a19d85c3 Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 02:26:06 +0200 Subject: [PATCH 1/2] Added requests script to not enter all the things always --- requests.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 requests.sh diff --git a/requests.sh b/requests.sh new file mode 100644 index 0000000..7836c04 --- /dev/null +++ b/requests.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +ARG=$1 +ACTIONS=(login register rcvpw username) + +print_help(){ + echo "usage: $0 [action]" + echo "available actions:" + for el in ${ACTIONS[@]}; do + echo - $el + done + exit 1 +} + +if [[ -z $1 ]]; then + print_help +fi + + +case $ARG in + "${ACTIONS[0]}") + echo "login action" + curl localhost:5050/api/login -X POST -d '{"username":"test","password":"test"}' + ;; + "${ACTIONS[1]}") + echo "register action" + curl localhost:5050/api/register -X POST -d '{"username":"test","password":"test"}' + ;; + "${ACTIONS[2]}") + echo "rcv_pw action" + ;; + *) + echo "Action not available" + print_help + ;; +esac -- 2.45.2 From fbbdbd43326925e69445080e82f38c8edc6e8dbf Mon Sep 17 00:00:00 2001 From: cami Date: Thu, 22 Jul 2021 02:37:04 +0200 Subject: [PATCH 2/2] Updated requests script --- requests.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/requests.sh b/requests.sh index 7836c04..ee90262 100644 --- a/requests.sh +++ b/requests.sh @@ -1,15 +1,17 @@ #!/bin/bash -ARG=$1 +ACTION=$1 +TOKEN=$2 ACTIONS=(login register rcvpw username) print_help(){ - echo "usage: $0 [action]" - echo "available actions:" - for el in ${ACTIONS[@]}; do - echo - $el - done - exit 1 + echo "Usage: $0 ACTION [TOKEN]" + echo + echo "available actions:" + for el in "${ACTIONS[@]}"; do + echo - "$el" + done + exit 1 } if [[ -z $1 ]]; then @@ -17,20 +19,26 @@ if [[ -z $1 ]]; then fi -case $ARG in - "${ACTIONS[0]}") +case $ACTION in + "${ACTIONS[0]}") # login echo "login action" curl localhost:5050/api/login -X POST -d '{"username":"test","password":"test"}' ;; - "${ACTIONS[1]}") + "${ACTIONS[1]}") # register echo "register action" curl localhost:5050/api/register -X POST -d '{"username":"test","password":"test"}' ;; - "${ACTIONS[2]}") + "${ACTIONS[2]}") # reveice password 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 ;; esac -- 2.45.2