|
@ -1,4 +1,8 @@ |
|
|
|
|
|
import base64 |
|
|
|
|
|
import os |
|
|
|
|
|
import uuid |
|
|
from datetime import timedelta |
|
|
from datetime import timedelta |
|
|
|
|
|
|
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
from django.contrib.auth.hashers import make_password |
|
|
from django.contrib.auth.hashers import make_password |
|
|
from django.contrib.auth.models import User |
|
|
from django.contrib.auth.models import User |
|
@ -7,7 +11,6 @@ from django.core.urlresolvers import reverse |
|
|
from django.db import models |
|
|
from django.db import models |
|
|
from django.utils import timezone |
|
|
from django.utils import timezone |
|
|
from hc.lib import emails |
|
|
from hc.lib import emails |
|
|
import uuid |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProfileManager(models.Manager): |
|
|
class ProfileManager(models.Manager): |
|
@ -28,6 +31,7 @@ class Profile(models.Model): |
|
|
reports_allowed = models.BooleanField(default=True) |
|
|
reports_allowed = models.BooleanField(default=True) |
|
|
ping_log_limit = models.IntegerField(default=100) |
|
|
ping_log_limit = models.IntegerField(default=100) |
|
|
token = models.CharField(max_length=128, blank=True) |
|
|
token = models.CharField(max_length=128, blank=True) |
|
|
|
|
|
api_key = models.CharField(max_length=128, blank=True) |
|
|
|
|
|
|
|
|
objects = ProfileManager() |
|
|
objects = ProfileManager() |
|
|
|
|
|
|
|
@ -49,6 +53,10 @@ class Profile(models.Model): |
|
|
ctx = {"set_password_link": settings.SITE_ROOT + path} |
|
|
ctx = {"set_password_link": settings.SITE_ROOT + path} |
|
|
emails.set_password(self.user.email, ctx) |
|
|
emails.set_password(self.user.email, ctx) |
|
|
|
|
|
|
|
|
|
|
|
def set_api_key(self): |
|
|
|
|
|
self.api_key = base64.urlsafe_b64encode(os.urandom(24)) |
|
|
|
|
|
self.save() |
|
|
|
|
|
|
|
|
def send_report(self): |
|
|
def send_report(self): |
|
|
# reset next report date first: |
|
|
# reset next report date first: |
|
|
now = timezone.now() |
|
|
now = timezone.now() |
|
|