ret=$(sudo -u diaspora psql diaspora_production -c "UPDATE invitation_codes SET count=0 WHERE user_id = (SELECT id FROM users WHERE username = '$1');")
if [[ "$ret" =~ ^UPDATE\ [1-9][0-9]*$ ]]; then
dialog --backtitle "$BT" --msgbox "Invites has been set to zero." $h $w
else
dialog --backtitle "$BT" --msgbox "An error has occured:\n\"$ret\"" $h $w
fi
}
function queryUser(){
if [[ "$1" =~ ^[0-9A-Za-z]+$ ]]; then
user=$(sudo -u diaspora psql diaspora_production -c "SELECT username FROM users WHERE username LIKE '$1' LIMIT 1;" -At)
if [ -n "$user" ]; then
return 0
else
return 1
fi
else
return 2
fi
}
function removeInvitesFromUserMenu(){
username=$(dialog --backtitle "$BT" --title "Remove invites from user" --inputbox "Here you can remove the invites from a user.\nUsername:" $h $w 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
queryUser "$username"
ret=$?
case $ret in
0)
setInvitesToZeroForUser "$username"
;;
1)
dialog --backtitle "$BT" --msgbox "Username not found." $h $w
removeInvitesFromUserMenu
;;
2)
dialog --backtitle "$BT" --msgbox "The username must be alphanumeric." $h $w