change logo
[cas.git] / src / ftp / models.py
1 from crypt import crypt
2 from django.db import models
3 from django.contrib.messages import add_message
4 from django.utils.timezone import now
5 from .utils import generate_password
6
7
8 class FtpUser(models.Model):
9     created_at = models.DateTimeField(auto_now_add=True)
10     last_seen_at = models.DateTimeField(null=True, editable=False)
11     login = models.CharField(max_length=255, unique=True)
12     password = models.CharField(max_length=255, blank=True)
13     password_set_at = models.DateTimeField(null=True, editable=False)
14
15     def __str__(self):
16         return self.login
17
18     def set_password(self, save=True):
19         pwd = generate_password()
20         self.password = crypt(pwd)
21         self.password_set_at = now()
22         if save:
23             self.save()
24         return pwd