class User(db.Model): __tablename__ = "users" uname = db.Column(db.String, primary_key=True, nullable=False, unique=True) fname = db.Column(db.String, nullable=False) lname = db.Column(db.String, nullable=False) mail = db.Column(db.String, nullable=False, unique=True) _books = db.Column(db.String, nullable=False, default='') password = db.Column(PasswordType(schemes=['pbkdf2_sha512', 'md5_crypt'], deprecated=['md5_crypt']), nullable=False) def verify_pass(self, password): return self.password == password @property def books(self): return [x.strip() for x in self._books.split(';') if x.strip()] def add_book_user(self, book_id): print(book_id, self.books) if book_id not in self.books: self._books += f'{book_id};' def __str__(self): return f'{self.uname} - {self.fname} {self.lname}: {self.mail}'
class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) last_password_updated = Column(DateTime) password = Column(PasswordType(schemes=['pbkdf2_sha512'], deprecated=[]))
def upgrade(): op.create_table( 'user', Column('id', UUID(), nullable=False), Column('created_at', DateTime(timezone=True), nullable=False), Column('email', Unicode(), nullable=False), Column('password', PasswordType(), nullable=False), PrimaryKeyConstraint('id'), UniqueConstraint('email'))
class StudentUser(db.Model): __tablename__ = 'student_user' usn = Column(String(15), ForeignKey('student.usn'), primary_key=True, nullable=False) password = Column(PasswordType(schemes=['pbkdf2_sha512'])) student = relationship('Student', foreign_keys='StudentUser.usn') def __init__(self, usn=None, passwd=None): self.usn = usn self.password = passwd def __repr__(self): return '<StudentUser %s>' % (self.usn) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): # return unicode(self.id) return self.usn
class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) email = Column(VARCHAR(length=80), unique=True) password = Column(PasswordType(schemes=[ 'bcrypt', ])) site_limit = Column(Integer, default=1) admin = Column(Boolean, default=False) deleted = Column(Boolean, default=False) sites = relationship("Site", secondary="users_sites", backref="users") @classmethod def sign_in(cls, email, password): user = DBSession.query(cls).filter(User.email == email).first() if user and user.password == password: return user return None @classmethod def get_from_id(cls, user_id): return DBSession.query(cls).filter(User.id == user_id).first()
class User(Base): email = Column(Unicode(1024), unique=True) first_name = Column(Unicode(1024)) last_name = Column(Unicode(1024)) password = Column(PasswordType(schemes=[ 'pbkdf2_sha512', ]), nullable=True)
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(200), nullable=False) mail = db.Column(db.String(200), nullable=False) photo = db.Column(db.String(500)) birth_date = db.Column(db.Date) password = db.Column(PasswordType(schemes=['pbkdf2_sha512', 'md5_crypt'], deprecated=['md5_crypt']), nullable=False) bio = db.Column(db.String(2000)) telephone = db.Column(db.String(20)) instagram = db.Column(db.String(100)) backed = db.relationship("Funded", back_populates="backed") voted = db.relationship("VotedTest", back_populates="voted") def __init__(self, name, mail, photo, birth_date, password, bio, telephone, instagram): self.name = name self.mail = mail self.photo = photo self.birth_date = birth_date self.password = password self.bio = bio self.telephone = telephone self.instagram = instagram def __repr__(self): return '<User %r>' % self.name
class User(db.Model): """ User model using sqlalchemy. id is the primary key. Email must be unique. Password is automatically encoded in the database. """ __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(128), unique=False, nullable=False) last_name = db.Column(db.String(128), unique=False, nullable=False) email = db.Column(db.String(128), unique=True, nullable=False) password = db.Column(PasswordType(schemes=['pbkdf2_sha512']), unique=False, nullable=False) wishlist = db.relationship('Book', secondary=wishlist_table) @property def json(self): """Property function that returns a json representation of the object.""" return { 'type': "user", 'id': self.id, 'first_name': self.first_name, 'last_name': self.last_name, 'email': self.email, 'wishlist': self.wishlist_json } @property def wishlist_json(self): """Property function that returns a list of all book json in User's wishlsit.""" return [book.json for book in self.wishlist]
class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) username = db.Column(db.String(80), unique=True) email = db.Column(db.String(120), unique=True) password = db.Column( PasswordType(schemes=['pbkdf2_sha512', 'md5_crypt'], deprecated=['md5_crypt'])) email_confirmed = db.Column(db.Boolean, default=False) notes = db.relationship('Note', backref='user', lazy='dynamic') def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % (self.username) def __init__(self, name, username, email, password): self.name = name self.username = username self.email = email self.password = password
class User(Base): __tablename__ = 'users' first_name = Column(Text) last_name = Column(Text) email_id = Column(Text, primary_key=True) user_category = Column(Text) password = Column(PasswordType(schemes=[ 'pbkdf2_sha512', ], )) is_active = Column(Boolean, default=True) def __init__(self, first_name, last_name, email_id, user_category, password, is_active=True): self.first_name = first_name self.last_name = last_name self.email_id = email_id self.user_category = user_category self.password = password self.is_active = is_active def check_password(self, input_password): '''Return True if we have a matching password''' return self.password == input_password
def __init__(self, *args, **kwargs): size = kwargs.pop('size', 64) crypt_context = kwargs.pop('crypt_context', {}) self.crypt_context = crypt_context kwargs.pop('type_', None) if 'foreign_key' in kwargs: raise FieldException("Column Password can not have a foreign key") self.sqlalchemy_type = PasswordType(max_length=size, **crypt_context) super(Password, self).__init__(*args, **kwargs)
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table( 'user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('email', sa.String(length=120), nullable=False), sa.Column('password', PasswordType(schemes=['pbkdf2_sha512']), nullable=False), sa.Column('is_admin', sa.Boolean(), nullable=True), sa.PrimaryKeyConstraint('id')) op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
class PlacementUser(db.Model): __tablename__ = 'placement_user' name = Column(String(20), primary_key=True, nullable=False) password = Column(PasswordType(schemes=['pbkdf2_sha512'])) def __init__(self, name=None, passwd=None): self.name = name self.password = passwd def __repr__(self): return '<PlacementUser %s>' % (self.usn)
class User(db.Model, login.UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(40), unique=True) password = db.Column( PasswordType(schemes=['bcrypt', 'plaintext'], deprecated=['plaintext'], max_length=40)) def __init__(self, username, password): self.username = username self.password = password
class User(Base, UserMixin): id = Column(UUIDType, primary_key=True, default=uuid.uuid4) created_at = Column(UtcDateTime, nullable=False, default=utcnow()) email = Column(EmailType, nullable=False, unique=True) password = Column(PasswordType(schemes=['pbkdf2_sha512']), nullable=False) __tablename__ = 'user' @typechecked def get_id(self) -> str: return str(self.id)
class User(db.Model): """ Basic user model """ id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(254), nullable=False, index=True, unique=True) password = db.Column(PasswordType(schemes=['pbkdf2_sha512'])) nick_name = db.Column(db.String(100), nullable=False) real_name = db.Column(db.String(100), nullable=False) phone = db.Column(db.String(13), nullable=False)
class User(db.Model): """ An application User. """ __tablename__ = 'user' id = Column(Integer, primary_key=True) name = Column(String) username = Column(String) password = Column(PasswordType(schemes=['pbkdf2_sha512'])) authenticated = False patients = db.relationship('Patient', backref='user') def is_active(self): """ True, as all users are active. """ return True def get_id(self): """ Return the user id. """ return str(self.id) 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 @property def default_patient_id(self): """ The default FHIR patient ID for this user. If this user is authorized for only one Patient, return that Patient's ID. Otherwise, return None. """ if len(self.patients) > 1: return None return self.patients[0].patient_id def patient(self, patient_id): """ Return a Patient by patient_id. """ for patient in self.patients: if patient_id == patient.patient_id: return patient return None
class User(Base): __tablename__ = users id = Column(Integer, primary_key=True) name = Column(String(30), unique=True) password = Column(PasswordType(schemes=['pbkdf2_sha512'])) groups = relationship("Group", secondary=usergroups_table) sacrud_detail_col = [ ('profile', [name]), ('groups', [groups]) ] def __repr__(self): return self.name
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), nullable=False) password = db.Column(PasswordType(schemes=[ 'pbkdf2_sha512', ]), nullable=False) todos = db.relationship('Todo', backref='person', lazy=True) def __repr__(self): return "User: {}".format(self.username) def to_dict(self): return {'id': self.id, 'username': self.username}
class User(db.Model): __tablename__ = 'user' __mapper_args__ = {'order_by': 'id'} id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, info={'label': 'Navn'}) username = db.Column(db.String, unique=True, info={'label': 'Brukernavn'}) password = db.Column(PasswordType(schemes=['pbkdf2_sha512']), info={'label': 'Passord'}) registered = db.Column(db.Boolean) admin = db.Column(db.Boolean) def __init__(self): self.registered = False self.admin = False def __repr__(self): return self.username
class LabelUser(Base): """Primary api user :attr int id: row id, unique :attr str username: first name of user :attr str full_name: last name of user :attr str email: user email :attr password password: hashed user password :attr bool is_superuser: boolean denoting superuser, false by default """ id = Column(Integer, primary_key=True, index=True) username = Column(String, unique=True) full_name = Column(String) email = Column(String) password = Column( PasswordType(schemes=["pbkdf2_sha512", "md5_crypt"], deprecated=["md5_crypt"])) is_superuser = Column(Boolean(), default=False)
def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table( 'command', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_on', sa.DateTime(), nullable=True), sa.Column('updated_on', sa.DateTime(), nullable=True), sa.Column('expire_on', sa.DateTime(), nullable=False), sa.Column('command_id', sa.Unicode(length=36), nullable=True), sa.Column('command_type', sa.Unicode(length=1024), nullable=True), sa.Column('command_date', sa.UnicodeText(), nullable=True), sa.Column('identity', sa.Unicode(length=1024), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('command_id')) op.create_table( 'user', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_on', sa.DateTime(), nullable=True), sa.Column('updated_on', sa.DateTime(), nullable=True), sa.Column('email', sa.Unicode(length=1024), nullable=True), sa.Column('first_name', sa.Unicode(length=1024), nullable=True), sa.Column('last_name', sa.Unicode(length=1024), nullable=True), sa.Column('password', PasswordType(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'))
class User(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), index=True, unique=True, nullable=False) password = db.Column(PasswordType(schemes=['pbkdf2_sha512']), nullable=False) is_admin = db.Column(db.Boolean, default=False) def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % (self.email)
class User(Base): __tablename__ = 'users' id = schema.Column(types.Integer, primary_key=True) name = schema.Column(types.String(191, collation='utf8mb4_general_ci'), unique=True, nullable=False, index=True) password = schema.Column(PasswordType(schemes=['pbkdf2_sha512']), unique=True, nullable=False) email = schema.Column(types.String(255), unique=True, nullable=True, index=True) public = schema.Column(types.Boolean) likes = orm.relationship('Podcast', secondary='users_to_podcasts_likes', back_populates='likers', lazy='dynamic') def __repr__(self): return '<User: {} ({})>'.format(self.name, self.email)
def setup_mappers(meta=None, engine=None): """ Setup SQLAlchemy mappers for the aggregate events database :param meta: SQLAlchemy Metadata :type meta: SQLAlchemy Metadata :returns: SQLAlchemy meta """ global _MAPPED # TODO if _MAPPED: #clear_mappers() return meta _MAPPED = True if meta is None: meta = MetaData() if engine: meta.bind = engine users_tbl = Table( 'users', meta, Column( 'id', GUID(), index=True, primary_key=True, ), Column('username', Unicode(32), index=True, unique=True), Column('first_name', Unicode(1024)), Column('last_name', Unicode(1024)), Column('email', Unicode(1024)), Column('password', PasswordType(schemes=[ 'pbkdf2_sha512', ]), nullable=True), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper( User, users_tbl, properties={ # 'passphrase': synonym("password") }) commands_tbl = Table( 'commands', meta, Column( 'id', GUID(), index=True, primary_key=True, ), Column('expire_on', DateTime, nullable=False), Column('command_id', Unicode(36), default=lambda: str(uuid4()), unique=True), Column('command_type', Unicode(1024)), Column('command_date', UnicodeText), Column('identity', Unicode(1024)), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(Command, commands_tbl, properties={}) queues_tbl = Table( 'queues', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('type', Unicode(length=255), index=True, unique=True), Column('uri', UnicodeText()), Column('label', UnicodeText()), Column('date', DateTime(), index=True, onupdate=datetime.datetime.now), Column('host', UnicodeText()), # default=$(hostname) Column('user', UnicodeText()), # default=$(whoami) Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(TaskQueue, queues_tbl) tasksources_tbl = Table( 'tasksources', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('queue_id', GUID(), ForeignKey(queues_tbl.c.id), index=True), Column('type', Unicode(length=255), index=True), # taskqueue.type # TODO Column('url', UnicodeText()), Column('label', UnicodeText()), Column('date', DateTime(), index=True, onupdate=datetime.datetime.now), Column('host', UnicodeText()), # default=$(hostname) Column('user', UnicodeText()), # default=$(whoami) Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(TaskSource, tasksources_tbl, properties={'queue': relation(TaskQueue, backref='sources')}) tasks_tbl = Table( 'tasks', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('source_id', GUID(), ForeignKey(tasksources_tbl.c.id), index=True), Column('args', MutationDict.as_mutable(JSONEncodedDict)), Column('label', UnicodeText()), Column('state', Unicode(), index=True, nullable=True), # TODO: ENUM: celery Column('statemsg', Unicode()), Column( 'date', DateTime(), index=True, onupdate=datetime.datetime.now, ), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(Task, tasks_tbl, properties={ 'source': relation(TaskSource, backref='tasks'), }) places_tbl = Table( 'places', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('url', UnicodeText(), index=True), Column('scheme', Unicode()), Column('netloc', UnicodeText(), index=True), Column( 'port', Integer(), ), Column('path', UnicodeText(), index=True), Column('query', UnicodeText(), index=True), Column('fragment', UnicodeText()), Column('eventcount', Integer()), Column('meta', MutationDict.as_mutable(JSONEncodedDict)), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(Place, places_tbl) # TODO: tags events_tbl = Table( 'events', meta, Column('id', GUID(), primary_key=True), # TODO, nullable=False), Column('source', Unicode(), index=True), Column('date', DateTime(), index=True), Column('url', UnicodeText()), Column('title', UnicodeText()), Column('meta', MutationDict.as_mutable(JSONEncodedDict)), Column('host', UnicodeText()), Column('user', UnicodeText()), Column('place_id', GUID(), ForeignKey(places_tbl.c.id), nullable=True), Column('source_id', GUID(), ForeignKey(tasksources_tbl.c.id), nullable=False), Column('task_id', GUID(), ForeignKey(tasks_tbl.c.id), nullable=False), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), # TODO: sync # UniqueConstraint('date','url','task_id', # name='uix_event_date_url_taskid'), # breaks w/ webkit history on date !? # UniqueConstraint('source','date','url', 'task_id', # name='uix_event_source_task_id'), ) mapper( Event, events_tbl, properties={ 'task': relation(Task, backref='events'), 'place': relation(Place, backref='events'), #'queue': relation(TaskQueue, backref='events'), }) report_types_tbl = Table( 'report_types', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('label', Unicode(), index=True), Column('data', MutationDict.as_mutable(JSONEncodedDict)), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(ReportType, report_types_tbl) reports_tbl = Table( 'reports', meta, Column('id', GUID(), primary_key=True, nullable=False), Column('report_type_id', GUID(), ForeignKey(report_types_tbl.c.id), nullable=False), Column('title', Unicode(), nullable=True), Column('data', MutationDict.as_mutable(JSONEncodedDict)), Column('created_on', DateTime, default=datetime.datetime.now), Column('updated_on', DateTime, onupdate=datetime.datetime.now), ) mapper(Report, reports_tbl, properties={ 'report_type': relation(ReportType, backref='reports'), }) return meta
class Monkey(db.Model): """The monkey model class.""" # Optional in Flask-SQLAlchemy, but included for clarity: __tablename__ = 'monkey' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(80), nullable=False) last_name = db.Column(db.String(80), nullable=False) password = db.Column(PasswordType(schemes=['pbkdf2_sha512', 'md5_crypt'], deprecated=['md5_crypt']), nullable=False) email = db.Column(db.String(254), unique=True, nullable=False) date_of_birth = db.Column(db.Date) best_friend_id = db.Column(db.Integer, db.ForeignKey('monkey.id', ondelete='SET NULL')) best_friend = db.relationship('Monkey', uselist=False, remote_side=[id], post_update=True, lazy='joined') friends = db.relationship( 'Monkey', secondary=friendship, primaryjoin=(id == friendship.c.left_monkey_id), secondaryjoin=(id == friendship.c.right_monkey_id), backref=db.backref('friend_of', lazy='dynamic')) def __init__(self, first_name, last_name, password, email, date_of_birth=None): self.first_name = first_name self.last_name = last_name self.password = password self.email = email if date_of_birth: self.date_of_birth = date_of_birth # False if None or empty string def age(self): """Calculate monkey's age from date of birth.""" # date_of_birth is a string before commit and a date object # afterwards, therefore: if self.date_of_birth: if type(self.date_of_birth) is str: try: bdate = parser.parse(self.date_of_birth).date() except Exception: # If age() is called on an unbound monkey with # incorrect date of birth, no age is returned: return None else: bdate = self.date_of_birth today = date.today() return today.year - bdate.year - ((today.month, today.day) < (bdate.month, bdate.day)) def __repr__(self): if self.age(): return '{0} {1} ({2})'.format(self.first_name, self.last_name, self.age()) else: return '{0} {1}'.format(self.first_name, self.last_name)
class User(db.Model, Timestamp, UserMixin): """ User database model with user authentication mixin """ id = db.Column(db.Integer, primary_key=True) username = db.Column( db.String(length=MAX_USERNAME_LENGTH), unique=True, nullable=False) password = db.Column( PasswordType(max_length=128, schemes=('bcrypt', )), nullable=False) # email = db.Column(db.String(length=120), unique=True, nullable=False) first_name = db.Column(db.String(length=30), default='', nullable=False) last_name = db.Column(db.String(length=30), default='', nullable=False) is_online = db.Column(db.Boolean(), default=False, nullable=False) is_admin = db.Column(db.Boolean(), default=False, nullable=False) settings = db.relationship('UserSettings', lazy=True, uselist=False) projects = db.relationship( 'Project', secondary=users_projects, lazy='dynamic', back_populates='users') comments = db.relationship( 'Comment', lazy='dynamic', back_populates='user') @classmethod def login(cls, username, password, remember=True): """ Attempts to login in a user with provided credentials """ found = cls.find_with_password(username, password) if not found: logger.warning(f'Failed login attempt with username {username}') return None login_user(found, remember=remember) logger.info(f'{found.username} successfully logged in') return found @classmethod def find_with_password(cls, username, password): user = cls.query\ .filter(func.lower(User.username) == func.lower(username))\ .first() if not user: return None return user if user.password == password else None @staticmethod def logout(): """ Logout current user """ if current_user.is_authenticated: logout_user() logger.info(f'{current_user.username} has logout') return True @property def tasks(self): return Task.query.join(Task.project)\ .filter(Project.users.any(User.id == self.id)) @property def created_tasks(self): return Task.query.filter_by(owner_id=self.id) @property def assigned_tasks(self): return Task.query.filter_by(assignee_id=self.id) def join_project_rooms(self): for project in self.projects: project.join_room() def leave_project_rooms(self): for project in self.projects: project.leave_room()