Esempio n. 1
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(
        self, email, username, password
    ):  # WIth this we can make an instance to the user ("Like a constructor of JAva")
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        return check_password_hash(
            self.password_hash, password
        )  ### Check the difference between password and password_hash

    def __repr__():
        return f"Username {self.username}"
class User(db.Model, UserMixin):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(20),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    posts = db.relationship('BlogPost', backref='author', lazy=True)

    # 'author' essentially it looks like an attribute call
    # or actually dealing with the templates
    # but ehat we actually want to call the relationship between a blog post and a user
    # so the author of the BlogPost is a user model
    # we can directly call author into the template

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

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

    def __repr__(self):
        return f"Username {self.username}"
Esempio n. 3
0
class User(db.Model, UserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default="default_profile.png")
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    # one to many relationship
    # one user can have many blog posts
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

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

    def __repr__(self):
        return f"Username {self.username}"
Esempio n. 4
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(20),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    #read more about indexs in the docs
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):  #creating the check_password method
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return f"UserName: {self.username}"
Esempio n. 5
0
class BlogPost(db.Model):

    # Связь позволяющая обращаться к атрибутам МОДЕЛИ Родительской-Связи из МОДЕЛИ Дочерней-Связи, так же просто как это делает МОДЕЛЬ Ролительской-Связи
    # обращаясь к атрибутам МОДЕЛИ Дочерней-Связи
    users = db.relationship(User)

    id = db.Column(db.Integer,primary_key= True)
    # Дата публикации
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    # Заголовок Публикации
    title = db.Column(db.String(140),nullable=False)
    # Текст Публикации
    text = db.Column(db.Text,nullable=False)

    # ДОЧЕРНЯЯ МОДЕЛЬ её атрибуты передаются по запросу от атрибута РОДИТЕЛЬСКОЙ  МОДЕЛИ(без РОДИТЕЛЬСКОЙ не создать)
    user_id = db.Column(db.Integer,db.ForeignKey('users.id'), nullable=False)



    # Конструктор. данные приходящие извне ( дата к ним не относится)
    def __init__(self,title,text,user_id):
        self.title   = title
        self.text    = text
        self.user_id = user_id


    def __repr__(self):
        return f'Post id: {sefl.id} --- Date: {self.date} --- Title: {self.title}'
Esempio n. 6
0
class BlogPost(db.Model):

    #each blogpost is connected to the user
    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    #attribute that connects blogpost to user, (nullable)-every blogpost must be associated to user id
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'),
                        nullable=False)  #tablename: users, attribute: id

    #every blogpost has to have a publish date
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    #each blogpost has a title, (nullable)-must provide title
    title = db.Column(db.String(140), nullable=False)

    text = db.Column(db.Text, nullable=False)

    #make instance of blogpost
    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
Esempio n. 7
0
class User(db.Model, UserMixin):

    # criando a tabela users
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))

    # nomeando a relação user/postagem
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        # encriptando a senha do user
        self.password_hash = generate_password_hash(password)

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

    def __repr__(self):
        return f"Username {self.username}"
Esempio n. 8
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    #link to image file that user uploads, nullable- can't get rid of user's profile_image
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default='default_profile.png')
    #must be unique email (unique=True), index-sets up index (sql)
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)

    #password
    password_hash = db.Column(db.String(128))

    #connect blogpost to user, backref- string attribute call relationship between blogpost and user (author)
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    #make instance of user
    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

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

    #string representation
    def __repr__(self):
        return f"Username: {self.username}"
Esempio n. 9
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)

    email = db.Column(db.String(64), index=True, unique=True)

    username = db.Column(db.String(64), index=True, unique=True)

    password = db.Column(db.String(128))

    profile_image = db.Column(db.String(128),
                              nullable=False,
                              default='default_profile.jpg')

    posts = db.relationship('BlogPost', backref='author', lazy=True)

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

    def check_password(self, password):
        return check_password_hash(self.password, password)
Esempio n. 10
0
class User(db.Model, UserMixin):

    # Create a table in the db
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(20),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    # This connects BlogPosts to a User Author.
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

    def check_password(self, password):
        # https://stackoverflow.com/questions/23432478/flask-generate-password-hash-not-constant-output
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return f"UserName: {self.username}"
Esempio n. 11
0
class User(db.Model, UserMixin):

    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(
        db.String(64), nullable=False,
        default="default_profile.png")  #String(num) = limit of caracters

    email = db.Column(db.String, unique=True, index=True)
    username = db.Column(db.String, unique=True, index=True)
    password_hash = db.Column(db.String)

    posts = db.relationship("BlogPost", backref="author", lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

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

    def __repr__(self):
        return f"Username {self.username}"
Esempio n. 12
0
class BlogPost(db.Model):
    # Setup the relationship to the User table
    users = db.relationship(User)

    # Model for the Blog Posts on Website
    id = db.Column(db.Integer, primary_key=True)
    # Notice how we connect the BlogPost to a particular author
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)
    category = db.Column(db.String(140), nullable=False, default='news')
    blog_image = db.Column(db.String(20), nullable=False, default='c1.jpg')
    blog_thumbnail = db.Column(db.String(20),
                               nullable=False,
                               default='stories1.jpg')

    def __init__(self, title, text, category, user_id, blog_image,
                 blog_thumbnail):
        self.title = title
        self.text = text
        self.user_id = user_id
        self.category = category
        self.blog_image = blog_image
        self.blog_thumbnail = blog_thumbnail

    def __repr__(self):
        return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title}"
Esempio n. 13
0
class BlogPost(db.Model):
    users = db.relationship(User)
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
Esempio n. 14
0
class BlogPost(db.Model):

    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(
        db.Integer, db.ForeignKey('users.id'), nullable=False
    )  ### db.ForeignKey('users.id') in this *users* is the table name above and the id is the attribute of the users table which is getting to create the relationship
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(64), nullable=False)
    text = db.Column(db.Text, nullable=False)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post ID: {self.id} -- Date: {self.date} --- {self.title}"
Esempio n. 15
0
class BlogPost(db.Model):
    # Setup the relationship to the User table
    users = db.relationship(User)
    # Model for the Blog Posts on Website
    id = db.Column(db.Integer, primary_key=True)
    # Notice how we connect the BlogPost to a particular author
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"), nullable=False)
    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    # Constructor
    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    # Repr
    def __repr__(self):
        return f"Post Id: {self.id} --- Date: {self.date} --- Title: {self.title}"
Esempio n. 16
0
class BlogPost(db.Model):

    users = db.relationship(User)

    __tablename__ = 'blogposts'

    id = db.Column(db.Integer, primary_key=True)

    title = db.Column(db.String(128), nullable=False)

    text = db.Column(db.String(128), nullable=False)

    date = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id
Esempio n. 17
0
class User(db.Model,UserMixin):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)

    # Прием аватара  как ССЫЛКИ , поэтому принимает строку
    # nullable=False - неможет быть пустой, и если пользователь аватар не загрузил то ставится дефолтная картинка
    # default='default_profile.png' - непосредственна сама Дефалтная картинка аватара(папка static/profile_pics), если пользователь не загрузил свою
    # Папка дефалт задана в users\views.py def account(): profile_image = url_for('static',filename='profile_pics/'+current_user.profile_image)
    profile_image = db.Column(db.String(64),nullable=False, default='default_profile.png')

    # unique=True - email ДОЛЖЕН быть УНИКАЛЬНЫМ
    # index=True -   создается в Колонке значения которой должны быть УНИКАЛЬНЫМИ для всей таблицы, загружает память. Нужны только в важных столбцах иначе будут тормоза
    email = db.Column(db.String(64),unique=True,index=True)

    # unique=True - email ДОЛЖЕН быть УНИКАЛЬНЫМ
    # index=True -   создается в Колонке значения которой должны быть УНИКАЛЬНЫМИ для всей таблицы, загружает память. Нужны только в важных столбцах иначе будут тормоза
    username = db.Column(db.String(64),unique=True,index=True)

    # Уже ХЭШИРОВАННЫЙ Пароль
    password_hash = db.Column(db.String(128))

    # СВЯЗЬ-колонка таблиц - Пользователя(РОДИТЕЛЬСКАЯ) с его БлогПостами(ДОЧЕРНЯЯ)
    # РОДИТЕЛЬСКАЯ МОДЕЛЬ от её атрибутов оталкиваются запросы (главная)
    posts = db.relationship('BlogPost', backref = 'author', lazy=True)

    # Конструктор класса
    def __init__(self,email,username,password):
        self.email    = email
        self.username = username

        # Хэширование вносимого в БД пароля при Регистрации нового пользователя
        self.password_hash = generate_password_hash(password)

    # Сверка хэшированого пароля из БД с ввеленым паролем при Аутентефикации Пользователя
    def check_password(self,password):
        return check_password_hash(self.password_hash,password)


    def __repr__(self):
        return f'Username {self.username}'
Esempio n. 18
0
class BlogPost(db.Model):

    # This is used in the ForeignKey lines below
    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    # This is what connects the user to the blog post
    # one to many - one user can have many blog posts
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)

    date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post id {self.id} -- Date: {self.date} -- Title: {self.title}"
Esempio n. 19
0
class BlogPost(db.Model):
    # get User object
    users = db.relationship(User)

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    date = db.Column(db.DateTime,
                     nullable=False,
                     default=datetime.now(pytz.timezone('Asia/Tokyo')))
    title = db.Column(db.String(140), nullable=False)
    text = db.Column(db.Text, nullable=False)

    # profile_image = db.Column(db.String(64), nullable=False,default='default_profile.png')

    def __init__(self, title, text, user_id):
        self.title = title
        self.text = text
        self.user_id = user_id

    def __repr__(self):
        return f"Post ID: {self.id} -- Date: {self.date} -- {self.title}"
Esempio n. 20
0
class User(db.Model, UserMixin):

    # Create a table in the db
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(20),
                              nullable=False,
                              default='default_profile.jpg')
    email = db.Column(db.String(64), unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    role = db.Column(db.String(120), nullable=False)
    # This connects BlogPosts to a User Author.
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

        if User.query.all() == []:
            self.role = 'admin'
        else:
            self.role = 'user'

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

    def __repr__(self):
        return f"UserName: {self.username}"
Esempio n. 21
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    profile_image = db.Column(db.String(64),
                              nullable=False,
                              default='default_profile.png')
    email = db.Column(
        db.String(64), unique=True, index=True
    )  #index has to do with SQL not flask, is an index we can use for the db, check the  sqlalchemy documentation
    username = db.Column(db.String(64), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    posts = db.relationship('BlogPost', backref='author', lazy=True)

    def __init__(self, email, username, password):
        self.email = email
        self.username = username
        self.password_hash = generate_password_hash(password)

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

    def __repr__(self):
        return f"Username {self.username}"
Esempio n. 22
0
class CodeNumber(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.Integer)

    def __init__(self, code):
        self.code = code
Esempio n. 23
0
class PhoneNumbers(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    number = db.Column(db.Integer)

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