Esempio n. 1
0
 def get(self, request, format=None):
     data = IMServe.gen_token(request.user.customer.id,
                              request.user.customer.name,
                              request.user.customer.avatar_url)
     request.user.customer.im_token = data['token']
     request.user.customer.save()
     return Response(Tool.format_data(data))
Esempio n. 2
0
    def add(self, account, password, **kwargs):
        try:
            with transaction.atomic():
                user = self._add_user(account, password)
                customer = self.create(user=user, account=account, **kwargs)
                customer.im_token = IMServe.gen_token(customer.id, account)['token']
                customer.save()

                return customer
        except IntegrityError:
            raise DBException('账号已注册')
        except:
            msg = traceback.format_exc()
            raise DBException(msg)