Exemplo n.º 1
0
 def api_attach_account(self, request, name, password):
     c = CPClient()
     if c.has_account():
         self.response_forbidden()
     try:
         c.attach_account(name, password)
     except CPClient.Error, why:
         return {"status": False, "message": str(why)}
Exemplo n.º 2
0
 def api_change_password(self, request, old_password, new_password, *args, **kwargs):
     c = CPClient()
     if not c.has_account():
         return {"status": False, "message": "Account is not registred"}
     if old_password != c.account_password:
         return {"status": False, "message": "Invalid password"}
     c.change_password(new_password)
     return {"status": True, "message": "Password has been changed"}
Exemplo n.º 3
0
 def api_get(self, request):
     c = CPClient()
     data = {}
     if c.has_account():
         data["account"] = c.account_info()
         for i in data["account"].get("industries", []):
             data["account"]["ind_%s" % i] = True
     if c.has_system():
         data["system"] = c.system_info()
     return data
Exemplo n.º 4
0
 def api_save_account(
     self,
     request,
     name,
     email,
     password=None,
     org=None,
     country=None,
     language=None,
     *args,
     **kwargs,
 ):
     industries = [
         k[4:] for k in kwargs if k.startswith("ind_") and kwargs[k]
     ]
     c = CPClient()
     if c.has_account():
         try:
             c.update_account(name,
                              email,
                              country=country,
                              language=language,
                              org=org,
                              industries=industries)
         except CPClient.Error as e:
             return {"status": False, "message": str(e)}
     else:
         # Create account
         try:
             c.create_account(
                 name,
                 email,
                 password,
                 org=org,
                 country=country,
                 language=language,
                 industries=industries,
             )
         except CPClient.Error as e:
             return {"status": False, "message": str(e)}
     return {"status": True, "message": "Account saved"}