class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) user_profile_id = db.Column(db.Integer(), db.ForeignKey('user_profile.id', ondelete='CASCADE')) # Flask-User fields active = db.Column(db.Boolean(), nullable=False, server_default='0') username = db.Column(db.String(50), nullable=False, unique=True) email = db.Column(db.String(255), nullable=False, unique=True) confirmed_at = db.Column(db.DateTime()) password = db.Column(db.String(255), nullable=False, server_default='') reset_password_token = db.Column(db.String(100), nullable=False, server_default='') # Relationships user_profile = db.relationship('UserProfile', uselist=False, backref="user")
class UserAuth(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE')) # User authentication information (required for Flask-User) username = db.Column(db.String(50), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False, server_default='') reset_password_token = db.Column(db.String(100), nullable=False, server_default='') active = db.Column(db.Boolean(), nullable=False, server_default='0') # Relationships user = db.relationship('User', uselist=False)
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) # User email information (required for Flask-User) email = db.Column(db.String(255), nullable=False, unique=True) confirmed_at = db.Column(db.DateTime()) # User information active = db.Column('is_active', db.Boolean(), nullable=False, server_default='0') first_name = db.Column(db.String(50), nullable=False, server_default='') last_name = db.Column(db.String(50), nullable=False, server_default='') likes = db.relationship("Like", backref="user") # Relationships user_auth = db.relationship('UserAuth', uselist=False) roles = db.relationship('Role', secondary='user_roles', backref=db.backref('users', lazy='dynamic'))
class User(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), nullable=False, unique=True) confirmed_at = db.Column(db.DateTime) active = db.Column('is_active', db.Boolean(), nullable=False, server_default='0') first_name = db.Column(db.String(50), nullable=False, server_default='') username = db.Column(db.String(50), nullable=False, unique=True) hashed_password = db.Column(db.String) # Relationships # user has many messages # user has many storms storms = db.relationship('ThunderStorm', backref='storms', lazy='dynamic') # user has many blasts blasts = db.relationship('Blast', secondary='user_blasts', backref=db.backref('users', lazy='dynamic'), order_by='Blast.creation') conversations = db.relationship('Conversation', secondary='user_conversations', backref=db.backref('users', lazy='dynamic')) # https://flask-login.readthedocs.org/en/latest/#your-user-class def is_active(self): # a more specific type of registered user. all reg. users will be active. return True def get_id(self): return unicode(self.id) def is_authenticated(self): # activated their account via email # dont want to worry about email when testing if app.debug: return True return self.active def is_anonymous(self): # Returns True if this is an anonymous user return not self.active def get_notifications(self): return map( lambda u: Object(creater=User.query.get(u.creater).username, rest=u), self.blasts) def get_blast(self, b_id): to_check = Blast.query.get(b_id) #if self.blasts return to_check def get_pending(self): # map reduce mapped = map( lambda u: Object(creater=User.query.get(u.creater).username, rest=u), self.blasts) return filter(lambda x: x.rest.status == "Pending", mapped) def get_pending_len(self): return len(filter(lambda x: x.status == "Pending", self.blasts)) # before save hash password.. # The key needs to be different than what attribute you are changing. More specifically, # wtf forms gets all the attributes supplied in the form, it then recursivly sets attributes # while they dont match. so If we supply a password field and hash it and save it then wtf # forms is going to see its different call __setattr__ again and a infinite loops continues, #because we are setting a hash and wtf it trying to set it. so I just look when wtf forms # tries to set a field called password and set some other field I didnt supply. def __setattr__(self, key, value): super(User, self).__setattr__(key, value) if key == 'password': #pwd = self.password hashz = pbkdf2_sha256.encrypt(value, rounds=10, salt_size=16) self.hashed_password = hashz