Example #1
0
class UserDetails(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True)
    pwdhash = db.Column(db.String(54))

    def __init__(self, username, password):
        self.username = username
        self.set_password(password)

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

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

    def generate_auth_token(self, expiration=600):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def validate_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None
        except BadSignature:
            return None
        return UserDetails.query.get(data['id'])
Example #2
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), unique=True)
    pwdhash = db.Column(db.String(54))
    machines = db.relationship('Machine',
                               secondary=machine_users,
                               backref=db.backref('machines', lazy='dynamic'))

    def __init__(self, username, password):
        self.username = username
        self.set_password(password)

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

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

    def generate_auth_token(self, expiration=600):
        s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def validate_auth_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except SignatureExpired:
            return None
        except BadSignature:
            return None
        return User.query.get(data['id'])

    def __eq__(self, user):
        return self.hostname == user.hostname
Example #3
0
class UserPdus(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    userid = db.Column(db.Integer, db.ForeignKey('user_details.id'))
    pduid = db.Column(db.Integer, db.ForeignKey('pdu_details.id'))

    def __init__(self, userid, pduid):
        self.userid = userid
        self.pduid = pduid
Example #4
0
class UserOutletsGroups(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    userid = db.Column(db.Integer, db.ForeignKey('user_details.id'))
    outletgroupid = db.Column(db.Integer, db.ForeignKey('group.id'))

    def __init__(self, userid, outletgroupid):
        self.userid = userid
        self.outletgroupid = outletgroupid
Example #5
0
class GroupOutlets(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    group_id = db.Column(db.Integer, db.ForeignKey('group.id'))
    outlet_id = db.Column(db.Integer, db.ForeignKey('outlets.id'))

    def __init__(self, group_id, outlet_id):
        self.group_id = group_id
        self.outlet_id = outlet_id
Example #6
0
class Outlets(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    pdu_id = db.Column(db.Integer, db.ForeignKey('pdu_details.id'))
    towername = db.Column(db.String(2))
    outlet = db.Column(db.Integer)

    def __init__(self, pdu_id, towername, outlet):
        self.pdu_id = pdu_id
        self.towername = towername
        self.outlet = outlet
Example #7
0
class PduDetails(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ip = db.Column(db.String(70), unique=True)
    fqdn = db.Column(db.String(70), unique=True)
    access_string = db.Column(db.String(70))

    def __init__(self, ip, fqdn, access_string):
        self.ip = ip
        self.fqdn = fqdn
        self.access_string = access_string
Example #8
0
class Machine(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    hostname = db.Column(db.String(100), unique=True)
    fqdn = db.Column(db.String(100), unique=True)
    username = db.Column(db.String(100))
    password = db.Column(db.String(54))
    users = db.relationship('User', secondary=machine_users,
                            backref=db.backref('users', lazy='dynamic'))

    def __init__(self, hostname, fqdn, username, password):
        self.hostname = hostname
        self.fqdn = fqdn
        self.username = username
        self.password = password

    def __eq__(self, machine):
        return self.hostname == machine.hostname
Example #9
0
class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), unique=True)

    def __init__(self, name):
        self.name = name