def notify(cls, request, message=None, force=False): obj = cls.objects.filter(user=request.user) if (obj.exists() and obj[0].enabled) or force: obj = UserAuthPhone.objects.filter(user=request.user) message = message if message else SMS_NOTIFICATION_MESSAGE if obj.exists(): send_sms(SMS_FROM, Sign().unsign(obj[0].phone), message) elif request.user.email: send_mail( [request.user.email], MAIL_DEFAULT_SUBJECT, message)
def send_sms(self): code = str(RandomPassword().get(SMS_CODE_LEN, SMS_ASCII)).lower() send_sms(SMS_FROM, Sign().unsign(self.phone), SMS_MESSAGE % code) self.code = Sign().sign(code) self.save()