Пример #1
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)
    posts = db.relationship('Post', backref='author', lazy=True)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verified_reset_token(token):
        s = Serializer(app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
Пример #2
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    email = db.Column(db.String(120), nullable=False, unique=True)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default="default.jpg")
    password = db.Column(db.String(60), nullable=False)
    projects = db.relationship("Project", backref="author", lazy=True)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
Пример #3
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer)
    name = db.Column(db.String(127))
    email = db.Column(db.String(127))
    auth_token = db.Column(db.String(255))

    def __init__(self, id, name, email, auth_token):
        self.user_id = id
        self.name = name
        self.email = email
        self.auth_token = auth_token
Пример #4
0
class Device(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    version = db.Column(db.String(100), nullable=False, default="-")
    platform = db.Column(db.String(100), nullable=False, default="-")
    image_id = db.Column(db.String(100), nullable=False, default="-")
    project_id = db.Column(db.Integer,
                           db.ForeignKey("project.id"),
                           nullable=False)
    management_ip = db.Column(db.String(50), nullable=False)

    def __repr__(self):
        return f"Device('{self.name}', Project ID: '{self.project_id}', Management IP: '{self.management_ip}')"
Пример #5
0
class Project(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False, unique=True)
    description = db.Column(db.String(200))
    date_created = db.Column(db.DateTime,
                             nullable=False,
                             default=datetime.utcnow)
    config_file = db.Column(db.Text, nullable=False)
    inventory_file = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
    devices = db.relationship("Device", backref="project", lazy=True)

    def __repr__(self):
        return f"Project('{self.name}', '{self.date_created}', '{self.config_file}')"
Пример #6
0
class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime,
                            nullable=False,
                            default=datetime.utcnow)
    content = db.Column(db.Text, nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Post('{self.title}', '{self.date_posted}')"
Пример #7
0
class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer,
                   autoincrement=True,
                   primary_key=True,
                   nullable=True)
    username = db.Column(db.String(100))
    displayname = db.Column(db.String(100))
    last_ip = db.Column(db.String(50))
    last_active = db.Column(db.DateTime(), default=db.func.now())

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

    @staticmethod
    def try_login(username, password):
        if app.config['auth_mode'] == 'ldap':
            conn = ldap.initialize(app.config['LDAP_PROVIDER_URL'])
            if conn is None:
                flash('error connecting to LDAP server')
            else:
                DomainQuery.log(
                    'authentication options: certfile: %s, user=%s, password=%s, search base=%s'
                    % (app.config['LDAP_CACERT'], username, password,
                       app.config['LDAP_SEARCH_BASE']))
                conn.set_option(ldap.OPT_X_TLS, True)
                if app.config['LDAP_CACERT'] != '':
                    conn.set_option(ldap.OPT_X_TLS_CACERTFILE,
                                    app.config['LDAP_CACERT'])
                conn.simple_bind_s(
                    '%s,%s' %
                    (app.config['LDAP_BIND_USER'], app.config['LDAP_BIND_DN']),
                    app.config['LDAP_AUTHTOK'])
                #conn.simple_bind_s('uid=%s,%s' % (username, app.config['LDAP_BIND_DN']), password)

                # do a search
                query = 'uid=%s' % username
                result = conn.search_s(app.config['LDAP_SEARCH_BASE'],
                                       ldap.SCOPE_SUBTREE, query)
                DomainQuery.log('result = [%s]' % result)
                if result:
                    userdata = result[0][1]
                    displayname = userdata['cn'][0].decode('utf-8')
                    return (True, displayname, userdata)
                else:
                    flash('authentication error')
                    return (False, '', {})

        elif app.config['auth_mode'] == 'plain':
            if password == app.config[
                    'default_password'] and username == app.config[
                        'default_user']:
                displayname = app.config['default_user']
                return (True, displayname, {})

        return (False, '', {})

    def is_authenticated(self):
        return True

    def is_active(self):
        return True

    def is_anonymous(self):
        return False

    def get_displayname(self):
        return self.displayname

    def set_displayname(self, new_displayname):
        self.displayname = new_displayname
        return True

    def get_id(self):
        return self.id

    def set_id(self, new_id):
        self.id = new_id
        return True

    def get_last_ip(self):
        return self.last_ip

    def set_last_ip(self, new_last_ip):
        self.last_ip = new_last_ip
        return True