This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
gemini-auth/public/cgi/account/rename.gmi

42 lines
1.1 KiB
Plaintext
Executable File

#!/usr/bin/python3
import os
import sys
os.chdir('..')
sys.path.append('lib')
hash = os.environ.get('TLS_CLIENT_HASH')
if (not hash):
# no CC
print('60 Authentication is required\r\n')
exit()
cert_name = os.environ.get('REMOTE_USER')
from auth import auth
auth = auth('data/data.db')
auth.pass_key(hash, cert_name)
if (not auth.username):
# mismatch
print('61 Unknown key\r\n')
else:
# match
name = os.environ.get('QUERY_STRING')
if (not name):
# empty
if (auth.user_info('request_rename')):
# TODO: tell which key are you renaming
print('10 Choose new name for your key\r\n')
else:
print('30 rename-request.gmi\r\n')
else:
# string
res = auth.rename_key(name)
if (res == auth.SUCCESS):
print('30 index.gmi\r\n')
elif (res == auth.NOT_FOUND):
print('20 text/gemini\r\n')
print('Failed to rename non-existing key, or key which does not belong to you.')
print('=> index.gmi back to home')
else:
print('40 Unknown error\r\n')