-l: request a login token

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2016-03-08 00:39:48 +03:00
parent 97701825bd
commit 59fb4b81eb
1 changed files with 24 additions and 1 deletions

25
ufw
View File

@ -33,7 +33,7 @@ usage() {
-P|--page-url # Get a link to the file page instead of a direct one.
-m|--max-filesize <num>[suf] # Maximum filesize (takes K, M and G suffixes).
-a|--album-id # Add the file to an album.
-A|--album-name # Add the file to an album by name. The album will be crated, if necessary.
-A|--album-name # Add the file to an album by name. The album will be created, if necessary.
Config options (~/.config/ufw):
secret # Your personal token. Get it at https://zfh.so/settings_form
@ -221,6 +221,10 @@ get_api_status() {
read -d '' -r api_status api_status_message < <(
jshon -e status -e code -u -p -e message -u
)
if ! (( api_status == 200 )); then
return 1
fi
}
_mktemp() {
@ -253,6 +257,18 @@ get_my_ip() {
fi
}
login() {
declare api_response
api_response=$( curl -sl "$cfg_service_url/$cfg_api_path/get_login_token?login=$login&format=json" )
if get_api_status <<< "$api_response"; then
printf 'Check your email.\n'
else
printf 'Error: %s %s\n' "$api_status" "$api_status_message"
fi
}
set_argv() {
declare arg opt c
declare -g argv
@ -356,6 +372,12 @@ main() {
shift
;;
-l|--login)
action='login'
login=$2
shift
;;
-h|--help|--usage) usage; return;;
--) shift; break;;
@ -371,6 +393,7 @@ main() {
upload) upload "$1";;
url) get_shortlink "$1";;
getmyip) get_my_ip;;
login) login;;
esac
}