From 8c1d5fbe8375cfa3b9ab1dece0d3f8892a843473 Mon Sep 17 00:00:00 2001 From: Gonzalo Vidal <35148159+Gonza10V@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:24:15 -0700 Subject: [PATCH] Update flapjack.py with a register function register was done following the pattern on Log in and https://flapjacksynbio.github.io/flapjack_api/#authentication --- src/flapjack/flapjack.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/flapjack/flapjack.py b/src/flapjack/flapjack.py index 9846231..08ad030 100644 --- a/src/flapjack/flapjack.py +++ b/src/flapjack/flapjack.py @@ -57,7 +57,26 @@ def __del__(self): def handle_response(self, s): return True - + + def register(self, username, password, password2, email): + try: + s = requests.post( + self.http_url_base+'/api/auth/register/', + data={ + 'username':username, + 'password':password, + 'password2':password2, + 'email':email + } + ) + except: + print(f'Register failed.') + else: + if self.handle_response(s): + self.username = username + data = s.json() + self.access_token = data['access'] + self.refresh_token = data['refresh'] def log_in(self, username, password): try: