# -*- coding: utf-8 -*-
# Copyright (c) 2020, JINGROW
# For license information, please see license.txt

import jingrow
from jcloud.saas.api import whitelist_saas_api


@whitelist_saas_api
def generate_access_token():
	from jcloud.saas.pagetype.site_access_token.site_access_token import SiteAccessToken

	return SiteAccessToken.generate(jingrow.local.site_name)


@jingrow.whitelist(allow_guest=True)
def is_access_token_valid(token: str):
	split = token.split(":")
	if len(split) != 2:
		return False
	actual_token = jingrow.db.get_value("Site Access Token", split[0], "token")
	return actual_token == split[1]
