def s00_new_bot_submit(): # if data bot data already exist, ignore and go back setup if futsu.storage.is_blob_exist(env.SETUP_TG_AUTH_BOT_DATA_PATH): return fk.redirect('/setup') token = flask.request.form['token'] try: # get bot data bot = telegram.Bot(token) bot_user = bot.get_me() setup_tg_auth_bot_data = { 'USER_TOKEN': token, 'USER_ID': bot_user.id, 'USER_USERNAME': bot_user.username, } # write bot data futsu.json.data_to_path(env.SETUP_TG_AUTH_BOT_DATA_PATH, setup_tg_auth_bot_data) # redirect setup return fk.redirect('/setup') except Exception as e: traceback.print_exc() return s00_new_bot(err_msg=str(e))
def s02_th_owner_login_telegram_auth_callback(): check_ret = tg.check_telegram_auth_callback() if check_ret != 'OK': return s02_th_owner_login(check_ret) tguser_id = flask.request.args.get('id') db_user.set_user_role(tguser_id, 'OWNER') db_user.set_user_api_token(tguser_id, th.generate_user_token()) return fk.redirect('/setup')
def s02_th_owner_login_telegram_auth_bypass(): conf_data = env.get_conf_data() if not conf_data['TELEGRAM_AUTH_BYPASS_USER_ID']: fk.e400('CAYIGVGS bad TELEGRAM_AUTH_BYPASS_USER_ID') db_user.set_user_role(str(conf_data['TELEGRAM_AUTH_BYPASS_USER_ID']), 'OWNER') return fk.redirect('/setup')
def endpoint_login_telegram_auth_bypass(): conf_data = env.get_conf_data() if not conf_data['TELEGRAM_AUTH_BYPASS_USER_ID']: fk.e400('BOQMQIAV bad TELEGRAM_AUTH_BYPASS_USER_ID') TELEGRAM_AUTH_BYPASS_USER_ID = str( conf_data['TELEGRAM_AUTH_BYPASS_USER_ID']) flask_login.login_user(User(TELEGRAM_AUTH_BYPASS_USER_ID)) return fk.redirect('/')
def unauthorized_handler(): return fk.redirect('/login')
def endpoint_logout(): flask_login.logout_user() return fk.redirect('/')
def endpoint_login_telegram_auth_callback(): check_ret = tg.check_telegram_auth_callback() if check_ret != 'OK': return endpoint_login(check_ret) tguser_id = flask.request.args.get('id') flask_login.login_user(User(tguser_id)) return fk.redirect('/')
def s00_new_bot_clean(): futsu.storage.rm(env.SETUP_TG_AUTH_BOT_DATA_PATH) futsu.storage.rm(env.SETUP_SET_DOMAIN_DONE_PATH) return fk.redirect('/setup')
def redirect_index(): return fk.redirect('/')
def s01_bot_set_domain_clean(): futsu.storage.rm(env.SETUP_SET_DOMAIN_DONE_PATH) return fk.redirect('/setup')
def s01_bot_set_domain_submit(): futsu.storage.bytes_to_path(env.SETUP_SET_DOMAIN_DONE_PATH, b'') return fk.redirect('/setup')