Skip to content

Commit 085e987

Browse files
committed
Update methods.py
1 parent 372810e commit 085e987

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

licensing/methods.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,3 +1620,52 @@ def record_usage_to_stripe(token, product_id, key, amount=""):
16201620
return (None, "Could not contact the server.")
16211621

16221622
return (jobj, "")
1623+
1624+
class User:
1625+
1626+
"""
1627+
The idea behind user authentication is to allow you to authenticate
1628+
users using their crendntials (i.e. username and password) to verify their
1629+
license. You can use their username and password to retrieve their
1630+
licenses instead of asking for a license key.
1631+
1632+
This is similar to obtaining all licenses assigned to a customer
1633+
using customer secret, with the difference that the user can pick both
1634+
the username and password, as well as restore a forgotten password.
1635+
1636+
For more information, please see
1637+
https://help.cryptolens.io/examples/user-verification and
1638+
https://app.cryptolens.io/docs/api/v3/UserAuth
1639+
"""
1640+
1641+
@staticmethod
1642+
def login(token, username, password):
1643+
1644+
"""
1645+
This method will return all licenses that belong to the user.
1646+
This method can be called with an access token that has UserAuthNormal
1647+
and UserAuthAdmin permission.
1648+
1649+
More docs: https://app.cryptolens.io/docs/api/v3/Login
1650+
"""
1651+
1652+
try:
1653+
response = HelperMethods.send_request("/userauth/login/", {"token":token, "username":username, "password":password})
1654+
except HTTPError as e:
1655+
response = e.read()
1656+
except URLError as e:
1657+
return (None, "Could not contact the server. Error message: " + str(e))
1658+
except Exception:
1659+
return (None, "Could not contact the server.")
1660+
1661+
print(response)
1662+
1663+
jobj = json.loads(response)
1664+
1665+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
1666+
if jobj != None:
1667+
return (None, jobj["message"])
1668+
else:
1669+
return (None, "Could not contact the server.")
1670+
1671+
return (jobj["licenseKeys"], "")

0 commit comments

Comments
 (0)