# Path: website/utils.py
# def get_api_server_url(path):
#     """
#     Return the url for api server.
#     """
#     return "http://" + settings.API_SERVER + path
# 
# def get_url_of_monitor_iframe(type, namespace, pod_name):
#     """
#     Get the url of monitor iframe in user dashboard.
#     """
#     if type == "memory":
#         type_id = 1
#     elif type == "cpu":
#         type_id = 14
# 
#     items = pod_name.split('-')
#     container = '-'.join(items[0:-1])
#     url = 'http://{}/dashboard-solo/db/containers?panelId={}&fullscreen&\
# var-namespace={}&var-pod={}&var-container={}'.format(settings.GRAFANA_SERVER,
#     type_id, namespace, pod_name, container)
# 
#     return url


import json
import logging
import requests
from website.utils import (get_api_server_url, get_url_of_monitor_iframe)
        """
        Return cookies.
        """
        url = get_api_server_url('/api/auth/login/')
        self.client.get(url)
        data['csrfmiddlewaretoken'] = self.client.cookies['csrftoken']
        self.client.post(url, data)
        return self.client.cookies

    def logout(self):
        url = get_api_server_url('/api/auth/logout/')
        self.client.get(url)

    def is_authenticated(self):
        """
        Return (True, username) if authenticated, else return (False, None)
        """
        url = get_api_server_url('/api/auth/is_authenticated/')
        response = self.client.get(url)

        if response.status_code == 200:
            data = json.loads(response.text)
            return True, data[0], data[1]
        else:
            return False, None, None

    def registry(self, data):
        """
        User registry.
        """

# Path: website/utils.py
# def get_api_server_url(path):
#     """
#     Return the url for api server.
#     """
#     return "http://" + settings.API_SERVER + path
# 
# def get_url_of_monitor_iframe(type, namespace, pod_name):
#     """
#     Get the url of monitor iframe in user dashboard.
#     """
#     if type == "memory":
#         type_id = 1
#     elif type == "cpu":
#         type_id = 14
# 
#     items = pod_name.split('-')
#     container = '-'.join(items[0:-1])
#     url = 'http://{}/dashboard-solo/db/containers?panelId={}&fullscreen&\
# var-namespace={}&var-pod={}&var-container={}'.format(settings.GRAFANA_SERVER,
#     type_id, namespace, pod_name, container)
# 
#     return url


# Path: website/communicate.py
import json
import logging
import requests
from website.utils import (get_api_server_url, get_url_of_monitor_iframe)

        """
        Return cookies.
        """
        url = get_api_server_url('/api/auth/login/')
        self.client.get(url)
        data['csrfmiddlewaretoken'] = self.client.cookies['csrftoken']
        self.client.post(url, data)
        return self.client.cookies

    def logout(self):
        url = get_api_server_url('/api/auth/logout/')
        self.client.get(url)

    def is_authenticated(self):
        """
        Return (True, username) if authenticated, else return (False, None)
        """
        url = get_api_server_url('/api/auth/is_authenticated/')
        response = self.client.get(url)

        if response.status_code == 200:
            data = json.loads(response.text)
            return True, data[0], data[1]
        else:
            return False, None, None

    def registry(self, data):
        """
        User registry.
        """

        url = get_api_server_url('/api/registry/')