Commit c60b6ed7 authored by Sylvain Lagrue's avatar Sylvain Lagrue
Browse files

ajout d\'un mot de passe pour l\'identification

parent be57411e
......@@ -10,7 +10,7 @@ import requests
__author__ = "Sylvain Lagrue"
__copyright__ = "Copyright 2021, Université de technologie de Compiègne"
__license__ = "LGPL-3.0"
__version__ = "0.9.0"
__version__ = "1.0.0"
__maintainer__ = "Sylvain Lagrue"
__email__ = "sylvain.lagrue@utc.fr"
__status__ = "dev"
......@@ -27,17 +27,18 @@ GridInfos = Dict[str, Any]
class CrocomineClient:
"""Cette classe permet d'accéder de façon transparente à un serveur Crocomine."""
def __init__(self, server: str, group: str, members: str, log: bool = False):
def __init__(self, server: str, group: str, members: str, password: str, log: bool = False):
self._basename = server + "/crocomine"
self._members = members
self._id = group
self._token = "Not defined"
self._password = password
self.log = log
self._session = requests.Session()
self.register()
def _format_data(self, i=None, j=None, animal=None):
def _format_data(self, i=None, j=None, animal=None, password=None):
data = {
"id": self._id,
"members": self._members,
......@@ -49,6 +50,9 @@ class CrocomineClient:
if animal:
data["animal"] = animal
if password:
data["password"] = password
return data
......@@ -75,8 +79,11 @@ class CrocomineClient:
def register(self) -> Tuple[Status, Msg]:
"""Permet de s'inscrire à un serveur Crocomine."""
data = self._format_data()
data = self._format_data(password=self._password)
res = self._request("register", data)
if "token" in res:
self._token = res["token"]
return res["status"], res["msg"]
def new_grid(self) -> Tuple[Status, Msg, GridInfos]:
......
from pprint import pprint
from crocomine_client import CrocomineClient
import time
def test():
server = "http://localhost:8000"
group = "Groupe 12"
members = "Khaled et Sylvain"
croco = CrocomineClient(server, group, members)
password = "un mot de passe introuvable mais pas trop" # ATTENTION, le mot de passe est en clair dans le fichier
croco = CrocomineClient(server, group, members, password, True)
print("new_grid")
status, msg, grid_infos = croco.new_grid()
print(status, msg)
pprint(grid_infos)
print("discover")
status, msg, infos = croco.discover(0, 0)
print(status, msg)
pprint(infos)
......@@ -23,6 +27,7 @@ def test():
print(status, msg)
pprint(infos)
status, msg, infos = croco.discover(0, 2)
print(status, msg)
pprint(infos)
......@@ -43,6 +48,10 @@ def test():
print(status, msg)
pprint(infos)
status, msg, infos = croco.guess(0, 1, "S")
print(status, msg)
pprint(infos)
status, msg, infos = croco.guess(3, 6, "T")
print(status, msg)
pprint(infos)
......@@ -51,14 +60,33 @@ def test():
print(status, msg)
pprint(grid_infos)
status, msg, infos = croco.guess(3, 6, "T")
# status, msg, infos = croco.guess(3, 6, "T")
# print(status, msg)
# pprint(infos)
status, msg, infos = croco.guess(1, 8, "C")
print(status, msg)
pprint(infos)
status, msg, grid_infos = croco.new_grid()
# status, msg, grid_infos = croco.new_grid()
# print(status, msg)
# pprint(grid_infos)
status, msg, infos = croco.chord(4, 3)
print(status, msg)
pprint(grid_infos)
pprint(infos)
status, msg, infos = croco.chord(1, 8)
print(status, msg)
pprint(infos)
status, msg, infos = croco.chord(1, 7)
print(status, msg)
pprint(infos)
status, msg, infos = croco.chord(4, 3)
print(status, msg)
pprint(infos)
if __name__ == "__main__":
test()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment