def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: if hasattr(e, 'key') and hasattr(e, 'detail'): return sms_pb2.SmsReply(error=sms_pb2.Error( **{e.key: e.detail})) return sms_pb2.SmsReply(error=sms_pb2.Error(default=str(e)))
def Send(self, request, context): sms = Sms(tel=request.tel, msg=request.msg, sender=request.sender, type=Sms.TYPE.Ordinary) db.session.add(sms) db.session.commit() do_send_sms.apply_async(args=[sms.id]) return sms_pb2.SmsReply(uuid=sms.uuid)
def RetrievePassword(self, request, context): template = config.get('TEMPLATE_RETRIEVE_PASSWORD') msg = template.format(code=request.code, minute=request.minute) sms = Sms(tel=request.tel, msg=msg, sender=request.sender, type=Sms.TYPE.RetrievePassword) db.session.add(sms) db.session.commit() do_send_sms.apply_async(args=[sms.id]) return sms_pb2.SmsReply(uuid=sms.uuid)
def Captcha(self, request, context): template = config.get('TEMPLATE_CAPTCHA') msg = template.format(code=request.code, minute=request.minute) sms = Sms(tel=request.tel, msg=msg, sender=request.sender, type=Sms.TYPE.Captcha) db.session.add(sms) db.session.commit() do_send_sms.apply_async(args=[sms.id]) return sms_pb2.SmsReply(uuid=sms.uuid)
def VerifyPhone(self, request, context): template = config.get('TEMPLATE_VERIFY_PHONE') msg = template.format(code=request.code, minute=request.minute, company=request.company) sms = Sms(tel=request.tel, msg=msg, sender=request.sender, type=Sms.TYPE.VerifyPhone) db.session.add(sms) db.session.commit() do_send_sms.apply_async(args=[sms.id]) return sms_pb2.SmsReply(uuid=sms.uuid)