-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. -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). -m|--max-filesize <num>[suf] # Maximum filesize (takes K, M and G suffixes).
-a|--album-id # Add the file to an album. -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): Config options (~/.config/ufw):
secret # Your personal token. Get it at https://zfh.so/settings_form 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 < <( read -d '' -r api_status api_status_message < <(
jshon -e status -e code -u -p -e message -u jshon -e status -e code -u -p -e message -u
) )
if ! (( api_status == 200 )); then
return 1
fi
} }
_mktemp() { _mktemp() {
@ -253,6 +257,18 @@ get_my_ip() {
fi 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() { set_argv() {
declare arg opt c declare arg opt c
declare -g argv declare -g argv
@ -355,6 +371,12 @@ main() {
misc_curl_args+=( -F "description=$2" ) misc_curl_args+=( -F "description=$2" )
shift shift
;; ;;
-l|--login)
action='login'
login=$2
shift
;;
-h|--help|--usage) usage; return;; -h|--help|--usage) usage; return;;
@ -371,6 +393,7 @@ main() {
upload) upload "$1";; upload) upload "$1";;
url) get_shortlink "$1";; url) get_shortlink "$1";;
getmyip) get_my_ip;; getmyip) get_my_ip;;
login) login;;
esac esac
} }