~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/types/invite.py -rw-r--r-- 951 bytes
72548bd7Drew DeVault API: Updates per core-go auth changes 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sqlalchemy as sa
import sqlalchemy_utils as sau
from srht.database import Base
import base64
import os

class Invite(Base):
    __tablename__ = 'invite'
    id = sa.Column(sa.Integer, primary_key=True)
    created = sa.Column(sa.DateTime, nullable=False)
    updated = sa.Column(sa.DateTime, nullable=False)
    invite_hash = sa.Column(sa.String(128))
    sender_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))
    sender = sa.orm.relationship('User',
            backref=sa.orm.backref('invites_sent'),
            foreign_keys=[sender_id])
    recipient_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))
    recipient = sa.orm.relationship('User', foreign_keys=[recipient_id])

    def gen_invite_hash(self):
        self.invite_hash = base64.urlsafe_b64encode(os.urandom(18)) \
            .decode('utf-8')

    def __init__(self):
        self.gen_invite_hash()

    def __repr__(self):
        return '<Invite {}>'.format(self.id)