Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d0cb37

Browse files
committed
Changes to allow user to connect with previously received User authToken
1. Modified AnonUser logout method to only logout if the user was truly anonymous. Otherwise other user sessions get killed and token immediately expires. 2. Modified User class init to accept password and authToken as optional.
1 parent e788241 commit 4d0cb37

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

clearblade/Users.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ def authenticate(self):
5454
cbLogs.info("Successfully authenticated!")
5555

5656
def logout(self):
57-
restcall.post(self.url + "/logout", headers=self.headers, sslVerify=self.system.sslVerify)
5857
if self in self.system.users:
5958
self.system.users.remove(self)
60-
try:
61-
cbLogs.info(self.credentials["email"], "has been logged out.")
62-
except AttributeError:
59+
# Only logging out Anonymous Users
60+
if "email" not in self.credentials:
61+
restcall.post(self.url + "/logout", headers=self.headers, sslVerify=self.system.sslVerify)
6362
cbLogs.info("Anonymous user has been logged out.")
6463

6564
def checkAuth(self):
@@ -71,12 +70,16 @@ def checkAuth(self):
7170

7271

7372
class User(AnonUser):
74-
def __init__(self, system, email, password):
73+
def __init__(self, system, email, password="", authToken=""):
7574
super(User, self).__init__(system)
7675
self.credentials = {
7776
"email": email,
7877
"password": password
7978
}
79+
self.token = authToken
80+
self.headers.pop("ClearBlade-UserToken", None)
81+
self.headers["ClearBlade-UserToken"] = self.token
82+
8083

8184
class ServiceUser(AnonUser):
8285
def __init__(self, system, email, token):
@@ -87,9 +90,9 @@ def __init__(self, system, email, token):
8790
self.token = token
8891
self.headers.pop("ClearBlade-UserToken", None)
8992
self.headers["ClearBlade-UserToken"] = self.token
90-
93+
9194
def authenticate(self):
9295
cbLogs.warn("Method 'authenticate' is not applicable for service users")
9396

9497
def logout(self):
95-
cbLogs.warn("Method 'logout' is not applicable for service users")
98+
cbLogs.warn("Method 'logout' is not applicable for service users")

0 commit comments

Comments
 (0)