class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) posts = db.relationship('Post', backref='author', lazy='dynamic') about_me = db.Column(db.String(140)) def __repr__(self): """ Returns the User as an account on the application. """ return '<User {}>'.format(self.username) def set_password(self, password): """ Generates a hash to track the pasword for 'self' aka the user. """ self.password_hash = generate_password_hash(password) def check_password(self, password): """ Checks the hash corresponding to the pasword for 'self' aka the user. """ return check_password_hash(self.password_hash, password)
class UserCache(db.Model): """ DB Model that holds member IDs in cached. Relationship with User (1) to many """ __tablename__ = "usercache" cache_id = db.Column(db.String(16), primary_key=True) active = db.Column(db.Boolean, default=False) friendly_id = db.Column(db.Text) # We want a backref here so that any updates to user as well as UserCache are reflected on both ends user_id = db.Column(db.Integer, db.ForeignKey('users.id')) profiles = db.relationship('LinkedInRecord', secondary=Cache_Records, lazy=True, backref=db.backref('caches', lazy=True)) created = db.Column(db.DateTime, default=datetime.now()) def __init__(self): self.cache_id = self.generate_string @property def generate_string(self): """ :return: Random ascii letters (string) """ l = ascii_letters holder = [] for i in range(16): holder.append(l[random.randrange(0, len(l))]) return ''.join(holder)
class User(db.Model): """ Build in function to modify Returns: print variable in string Changelog: 4/19 Ali 5/3 Dylan: Added events relationship 5/10 Dylan: Added salt """ id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(128), index=True, unique=True) salt = db.Column(db.String(32)) password_hash = db.Column(db.String(256), default = 'fatal-error') start_time = db.Column(db.Time, default=datetime.time(9, 0)) end_time = db.Column(db.Time, default=datetime.time(22, 0)) meeting_length = db.Column(db.Integer, default=30) events = db.relationship('Event', backref='creator', lazy='dynamic') def __repr__(self): return '<User {}>'.format(self.username)
class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) text = db.Column(db.String(32), nullable=False) message_id = db.Column(db.Integer, db.ForeignKey('message.id'), nullable=False) message = db.relationship('Message', backref=db.backref('tags', lazy=True))
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) password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}')"
class User(UserMixin, db.Model): '''This class models a user of this application and will hold a users Username and password hash''' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(128), index=True, unique=True) sendEmailConfirm = db.Column(db.String(128)) password_hash = db.Column(db.String(128)) availability = db.relationship("Availability", uselist=False, backref="user") meetings = db.relationship("Meetings", uselist=False, backref="user") appointments = db.relationship("listOfMeetings", uselist=False, backref="user") usercal = db.relationship("CustomHTMLCalendar", uselist=False, backref="user") posts = db.relationship('Post', backref="user") def __repr__(self): return '<User {}>'.format(self.username) def print_username(self): return '{}'.format(self.username) def set_password(self, password): ''' This functions generates a hash based on a users account password. Args: password (String) : The password that a user chooses to associate with their account. ''' self.password_hash = generate_password_hash(password) def check_password(self, password): ''' This function checks if a input password corresponds with the hash associated with the account. Args: password (String) : The password that will be checked. Returns: True if the password corresponds with the hash associated with the users account. ''' return check_password_hash(self.password_hash, password)
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) family = db.Column(db.String(64), nullable=False) password_hash = db.Column(db.String(128)) messages = db.relationship("Message", uselist=False, backref="user") def __repr__(self): return '<User {}>'.format(self.username) def set_password(self, password): self.password_hash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password_hash, password)
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) 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 verify_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}')"
class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(128), index=True, unique=True) password_hash = db.Column(db.String(128)) emailConfirmation = db.Column(db.String(2), index=True) meetingLength = db.Column(db.String(32), index=True) availabilityStart = db.Column(db.String(32), index=True) availabilityEnd = db.Column(db.String(32), index=True) posts = db.relationship('Post', backref='author', lazy='dynamic') def __repr__(self): ''' This function will format username Returns: Will return a username. ''' return '<User {}>'.format(self.username) def set_password(self, password): ''' This function will generate a password hash. Args: password (string) : The user's password ''' self.password_hash = generate_password_hash(password) def check_password(self, password): ''' This function will check if password is valid Args: password (string) : The user's password Returns: Will return true or false depending on if the password is valid. ''' return check_password_hash(self.password_hash, password)
class OAuth(db.Model, OAuthConsumerMixin): """Contain the associated Oauth.""" provider_user_id = db.Column(db.String(256), unique=True) user_id = db.Column(db.Integer, db.ForeignKey(User.id)) user = db.relationship(User)
class LinkedInRecord(db.Model): """ DB Model for Profile Data """ __tablename__ = 'profiles' member_id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String(128)) last_name = db.Column(db.String(128)) summary = db.Column(db.Text) metro = db.Column(db.Text) postal_code = db.Column(db.Text) country_code = db.Column(db.Text) language = db.Column(db.Text) industry = db.Column(db.Text) skills = db.Column(db.Text) companyName_0 = db.Column(db.Text) companyUrl_0 = db.Column(db.Text) title_0 = db.Column(db.Text) start_date_0 = db.Column(db.Date) end_date_0 = db.Column(db.Date) summary_0 = db.Column(db.Text) companyName_1 = db.Column(db.Text) companyUrl_1 = db.Column(db.Text) title_1 = db.Column(db.Text) start_date_1 = db.Column(db.Date) end_date_1 = db.Column(db.Date) summary_1 = db.Column(db.Text) companyName_2 = db.Column(db.Text) companyUrl_2 = db.Column(db.Text) title_2 = db.Column(db.Text) start_date_2 = db.Column(db.Date) end_date_2 = db.Column(db.Date) summary_2 = db.Column(db.Text) created = db.Column(db.Date, default=date.today()) updated = db.Column(db.Date, default=None) education_school = db.Column(db.Text) education_start = db.Column(db.Date) education_end = db.Column(db.Date) education_degree = db.Column(db.Text) education_study_field = db.Column(db.Text) first_graduation_date = db.Column(db.Date) public_url = db.Column(db.Text) recruiter_url = db.Column(db.Text) isCompanyFollower = db.Column(db.Boolean) careerInterests = db.Column(db.Boolean) contacts = db.relationship("Contact") def __init__(self, LinkedInProfile): """ :param LinkedInProfile: """ for k, v in LinkedInProfile.__dict__.items(): if k[0] == '_': # Include or exclude properties based on _prop naming convention continue if v: pass # Avoids overwriting data with None else: continue try: setattr(self, k, v) except AttributeError: self._set_entry(k, v) def _set_entry(self, k, v): # Handles if Table object is intended to be internal k_ = "_" + k setattr(self, k_, v)
class User(UserMixin, db.Model): __tablename__ = "users" id = db.Column(db.Integer, primary_key=True) user_type = db.Column(db.Text, default='normal') username = db.Column(db.String(128)) password_hash = db.Column(db.Text) api_key = db.Column(db.Text) current_session_user = db.Column(db.Integer, default=0) caches = db.relationship('UserCache', backref='user', lazy='dynamic') records = db.relationship('LinkedInRecord', secondary=User_Records, lazy=True, backref=db.backref('users', lazy=True)) activities = db.relationship('UserActivity', backref='user', lazy='dynamic') allowance = db.Column(db.Integer, default=450) # New records allowed per day # Generating a random key to return to Extension after login success @staticmethod def verify_auth_token(token): s = Serializer(app_run.config['SECRET_KEY']) try: data = s.loads(token) except SignatureExpired: print("Expired Token") return None # valid token, but expired except BadSignature: print("Bad Signature") return None # invalid token user = User.query.get(data['id']) if user: token_session = data['session'] if token_session == user.current_session_user: return user else: print("Session does not match for user {}, generate new token".format(user.id)) return None else: return False def check_password(self, password): return check_password_hash(self.password_hash, password) def get_id(self): return self.id def get_activity(self): """ Queries a User for associated UserActivities. Filters to UserActivities that are active=true If UserActivity is active, but older than 1 day, it is set active=false :return: UserActivity or False if no active, UserActivity < 1 day are found """ active_trackers = self.activities.filter_by(active=True).all() if active_trackers: pass else: return False # No active tracker current_trackers = [] for t in active_trackers: if (datetime.now() - t.created).days > 0: t.active = False db.session.add(t) db.session.commit() continue else: current_trackers.append(t) if current_trackers: return current_trackers[0] else: # Will occur if 1 or more active trackers must be set inactive return False def generate_new_password(self, new_password): self.password_hash = generate_password_hash(new_password) self.current_session_user = self.current_session_user + 1