@@ -1657,8 +1657,150 @@ def login(token, username, password):
16571657 return (None , "Could not contact the server. Error message: " + str (e ))
16581658 except Exception :
16591659 return (None , "Could not contact the server." )
1660+
1661+ jobj = json .loads (response )
1662+
1663+ if jobj == None or not ("result" in jobj ) or jobj ["result" ] == 1 :
1664+ if jobj != None :
1665+ return (None , jobj ["message" ])
1666+ else :
1667+ return (None , "Could not contact the server." )
1668+
1669+ return (jobj ["licenseKeys" ], "" )
1670+
1671+ """
1672+ The idea behind user authentication is to allow you to authenticate
1673+ users using their crendntials (i.e. username and password) to verify their
1674+ license. You can use their username and password to retrieve their
1675+ licenses instead of asking for a license key.
1676+
1677+ This is similar to obtaining all licenses assigned to a customer
1678+ using customer secret, with the difference that the user can pick both
1679+ the username and password, as well as restore a forgotten password.
1680+
1681+ For more information, please see
1682+ https://help.cryptolens.io/examples/user-verification and
1683+ https://app.cryptolens.io/docs/api/v3/UserAuth
1684+ """
1685+
1686+ @staticmethod
1687+ def register (token , username , password , email = "" , customerId = 0 ):
1688+
1689+ """
1690+ This method will register a new user. Please note that calling this
1691+ method requires a UserAuthAdmin token.
1692+
1693+ More docs: https://app.cryptolens.io/docs/api/v3/Register
1694+ """
1695+
1696+ try :
1697+ response = HelperMethods .send_request ("/userauth/Register/" ,\
1698+ {"token" :token ,\
1699+ "username" :username ,\
1700+ "password" :password ,\
1701+ "email" :email ,\
1702+ "customerid" :customerId })
1703+ except HTTPError as e :
1704+ response = e .read ()
1705+ except URLError as e :
1706+ return (None , "Could not contact the server. Error message: " + str (e ))
1707+ except Exception :
1708+ return (None , "Could not contact the server." )
1709+
1710+ jobj = json .loads (response )
1711+
1712+ if jobj == None or not ("result" in jobj ) or jobj ["result" ] == 1 :
1713+ if jobj != None :
1714+ return (None , jobj ["message" ])
1715+ else :
1716+ return (None , "Could not contact the server." )
1717+
1718+ return (jobj , "" )
1719+
1720+ @staticmethod
1721+ def associate (token , username , customer_id = 0 ):
1722+
1723+ """
1724+ Associates a user with a customer object. Please note that calling
1725+ this method requires a UserAuthAdmin token.
1726+
1727+ More docs: https://app.cryptolens.io/docs/api/v3/Associate
1728+ """
1729+
1730+ try :
1731+ response = HelperMethods .send_request ("/userauth/Associate/" ,\
1732+ {"token" :token ,\
1733+ "username" :username ,\
1734+ "customerid" :customer_id })
1735+ except HTTPError as e :
1736+ response = e .read ()
1737+ except URLError as e :
1738+ return (None , "Could not contact the server. Error message: " + str (e ))
1739+ except Exception :
1740+ return (None , "Could not contact the server." )
1741+
1742+ jobj = json .loads (response )
1743+
1744+ if jobj == None or not ("result" in jobj ) or jobj ["result" ] == 1 :
1745+ if jobj != None :
1746+ return (None , jobj ["message" ])
1747+ else :
1748+ return (None , "Could not contact the server." )
16601749
1661- print (response )
1750+ return (jobj , "" )
1751+
1752+ @staticmethod
1753+ def dissociate (token , username ):
1754+
1755+ """
1756+ Dissociates a user from a customer customer object. Please note that
1757+ calling this method requires a UserAuthAdmin token.
1758+
1759+ More docs: https://app.cryptolens.io/docs/api/v3/Dissociate
1760+ """
1761+
1762+ try :
1763+ response = HelperMethods .send_request ("/userauth/Dissociate/" ,\
1764+ {"token" :token ,\
1765+ "username" :username })
1766+ except HTTPError as e :
1767+ response = e .read ()
1768+ except URLError as e :
1769+ return (None , "Could not contact the server. Error message: " + str (e ))
1770+ except Exception :
1771+ return (None , "Could not contact the server." )
1772+
1773+ jobj = json .loads (response )
1774+
1775+ if jobj == None or not ("result" in jobj ) or jobj ["result" ] == 1 :
1776+ if jobj != None :
1777+ return (None , jobj ["message" ])
1778+ else :
1779+ return (None , "Could not contact the server." )
1780+
1781+ return (jobj , "" )
1782+
1783+
1784+ @staticmethod
1785+ def remove_user (token , username ):
1786+
1787+ """
1788+ This method removes a user. Please note that calling this method
1789+ requires a UserAuthAdmin token.
1790+
1791+ More docs: https://app.cryptolens.io/docs/api/v3/RemoveUser
1792+ """
1793+
1794+ try :
1795+ response = HelperMethods .send_request ("/userauth/RemoveUser/" ,\
1796+ {"token" :token ,\
1797+ "username" :username })
1798+ except HTTPError as e :
1799+ response = e .read ()
1800+ except URLError as e :
1801+ return (None , "Could not contact the server. Error message: " + str (e ))
1802+ except Exception :
1803+ return (None , "Could not contact the server." )
16621804
16631805 jobj = json .loads (response )
16641806
@@ -1668,4 +1810,4 @@ def login(token, username, password):
16681810 else :
16691811 return (None , "Could not contact the server." )
16701812
1671- return (jobj [ "licenseKeys" ] , "" )
1813+ return (jobj , "" )
0 commit comments