Example #1
0
class Profile(db.Document, UserMixin):
    social_id = db.StringField(unique=True)
    name = db.StringField(required=True)
    email = db.StringField(unique=True, required=True)
    role = db.StringField(required=True, default="user")
    created_at = db.DateTimeField()
    last_login = db.DateTimeField()
    api_key = db.StringField()

    meta = {'collection': 'profiles'}
Example #2
0
class Post(db.Document):
    title = db.StringField(required=True)
    tag = db.StringField(max_length=25)
    text = db.StringField()
    urls = db.ListField(db.StringField())
    posted = db.DateTimeField(default=datetime.datetime.now)
    comments = db.ListField(
        db.ReferenceField(Comment, reverse_delete_rule=mongoengine.PULL))
    user = db.ReferenceField(User)

    def __repr__(self):
        return f"Post {self.title}"
Example #3
0
class User(db.Document):
    username = db.StringField(unique=True, required=True)
    password = db.StringField(required=True)

    def asJson(self):
        return {
            "id":str(self.id),
            "username":self.username,
            "password":self.password
        }
    
    def encode_auth_token(self, user_id):
        """
        Generates the Auth Token
        :return: string
        """

        payload = {
            "username" : self.username,
            "password" : self.password
        }

        return jwt.encode(
            payload,
            config.SECRET_KEY,
            algorithm='HS256'
        )

    @staticmethod
    def generate_hash(password):
        return sha256_crypt.hash(password)    
    
    @staticmethod
    def verify_hash(password, hash):
        return sha256_crypt.verify(password, hash)


    @staticmethod
    def decode_auth_token(auth_token):
        """
        Decodes the auth token
        :param auth_token:
        :return: integer|string
        """
        try:
            payload = jwt.decode(auth_token, config.SECRET_KEY, algorithms=['HS256'])
            return payload
        except jwt.ExpiredSignatureError as e1:
            raise e1
        except jwt.InvalidTokenError as e2:
            raise e2
Example #4
0
class Todo(db.Document):
    name = db.StringField(required=True)
    description = db.StringField(required=True)
    username = db.StringField(required=True)
    created_on = db.DateTimeField(required=True)

    def asJson(self):
        return {
            "id":str(self.id),
            "name":self.name,
            "description":self.description,
            "username" : self.username,
            "created_on":self.created_on.strftime("%d/%m/%Y %H:%M:%S.%f"),
        }
Example #5
0
class TodoList(db.Document):
    name = db.StringField(required=True)
    todo_list = db.ListField(db.ReferenceField('Todo'))
    username = db.StringField(required=True)
    created_on = db.DateTimeField(required=True)

    def asJson(self):
        return {
            "id":str(self.id),
            "name":self.name,
            "todo_list" :list(map(lambda todo: todo.asJson(), self.todo_list)),
            "username" : self.username,
            "created_on":self.created_on.strftime("%d/%m/%Y %H:%M:%S.%f"),
        }
Example #6
0
class User(db.Document):
    meta = {'queryset_class': SoftDeleteQuerySet, 'collection': 'users'}

    first_name = db.StringField()
    last_name = StringField()
    date_joined = DateTimeField(required=True)
    email = EmailField(required=True, unique=True)
    password_hash = StringField(required=True, min_length=6)
    is_active = BooleanField(default=True)
    is_staff = BooleanField(default=False)
    is_superuser = BooleanField(default=False)
    deleted_at = DateTimeField(null=None)

    @property
    def full_name(self):
        if self.first_name.strip() != '' and self.last_name.strip() != '':
            return "{} {}".format(self.first_name.strip(), self.last_name.strip())
        if self.first_name.strip() != '':
            return self.first_name.strip()
        if self.last_name.strip() != '':
            return self.last_name.strip()
        return self.email.strip()

    def set_password_hash(self, password):
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password_hash, password)
Example #7
0
class Comment(db.Document):
    text = db.StringField(required=True)
    created = db.DateTimeField(default=datetime.datetime.now())
    from_user = db.ReferenceField(User, required=True)
    post = db.ReferenceField(
        'Post')  #, reverse_delete_rule=mongoengine.CASCADE)

    def __repr__(self):
        return f"Comment {self.text} by {self.from_user}"
Example #8
0
class User(db.Document, UserMixin):
    username = db.StringField(max_length=25, required=True, unique=True)
    password = db.StringField(max_length=150, required=True)
    role = db.StringField(max_length=25)
    email = db.StringField(max_length=100)

    def __repr__(self):
        return f"User {self.username}"

    def set_password(self, password):
        self.password = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(self.password, password)

    @property
    def is_admin(self):
        return self.role == "admin"
Example #9
0
class User(db.Document):
    name = db.StringField(required=True)
    state = db.StringField(required=True)
    code = db.StringField(required=True)
    active = db.BooleanField(required=True, default=True)
    password = db.StringField()
    email = db.StringField(required=True)
    rol = db.StringField(required=True)
    protected = db.BooleanField(required=True, default=False)
    deleted = db.BooleanField(required=True, default=False)

    def generate_password(self):
        """Calculate the password."""
        self.password = generate_password_hash(self.password)

    def generate_code(self):
        """Calculate the password."""
        self.code = code_generator(size=30, hexdigits=True)

    def is_active(self):
        """True, as all users are active."""
        return True

    def get_id(self):
        """Return the email address to satisfy Flask-Login's requirements."""
        return self.id.__str__()

    def is_authenticated(self):
        """Return True if the user is authenticated."""
        return self.authenticated

    def is_anonymous(self):
        """False, as anonymous users aren't supported."""
        return False
Example #10
0
class GuestBook(db.Document):
    firstName = db.ListField(db.StringField(), required=True)
    lastName = db.ListField(db.StringField(), required=True)
    fullName = db.ListField()
    email: db.ListField(required=True, unique=True)
    mobilePhone: db.ListField(required=True, unique=True)
    purpose: db.ListField(db.StringField(), required=True)
    meetWho: db.ListField(db.StringField(), required=True)
    pictureUrl: db.ListField(db.StringField(), required=True)
    captcha: db.ListField(db.StringField(), required=True)
Example #11
0
class Inventory(db.Document):
    optico = db.StringField(required=True)
    tipo = db.StringField(required=True)
    ean = db.StringField(required=True)
    deleted = db.BooleanField()