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_link(cls, request, user): data = { 'ip': get_ip(request), 'user_agent': md5(request.META.get('HTTP_USER_AGENT')), } link = 'http://%s%s?data=%s' % ( Site.objects.get_current(), reverse('auth_login'), Sign().sign(data) ) send_mail( [user.email], _('Link for unlock access'), link )
def send_codes(cls, request): settings_list = cls.objects.filter(user=request.user) if settings_list.exists(): created_seconds = (now() - settings_list[0].created).seconds if created_seconds > 300: return codes = json.loads(Sign().unsign(settings_list[0].code)) codes_list = collections.OrderedDict( sorted(codes.items(), key=lambda t: int(t[0]))) message = '' for (k, v) in codes_list.items(): message += '%s. %s\n' % (k, v) send_mail( [request.user.email], CODES_SUBJECT, message ) return True