O
O
OrangeXD2017-07-09 17:58:03
FTP
OrangeXD, 2017-07-09 17:58:03

How to set default user role when registering with Flask-User?

Can't figure out how to set the default role? It is necessary for sampling when displaying users in the admin panel.

DB Schema:

class Role(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    description = db.Column(db.Text(255))

    def __repr__(self):
        return self.id


class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), nullable=False, unique=True)
    password = db.Column(db.String(150), nullable=False)
    email = db.Column(db.String(30))
    is_enabled = db.Column(db.Boolean(), nullable=False, default=True)
    roles = db.relationship('Role', secondary='user_roles',
                            backref=db.backref('users', lazy='dynamic'))

    def is_active(self):
        return self.is_enabled


class UserRoles(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    user_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'))
    role_id = db.Column(db.Integer(), db.ForeignKey('role.id', ondelete='CASCADE'))


I tried this way, but the role is not added:
@user_registered.connect_via(app)
def user_registered_sighandler(app, user, confirm_token):
    default_role = user_datastore.find_role("user")
    user_datastore.add_role_to_user(user, default_role)
    db.session.commit()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slav2, 2019-01-02
@Slav2

I did not particularly suffer from the choice, I installed the FTP server according to the first manual for CentOS that came across. There were no problems.
Of course, it is more convenient to immediately upload files to the server. Any client will do, such as FileZilla .

S
Saboteur, 2019-01-03
@saboteur_kiev

Upload via scp.
FTP is not secure - all data is in clear text, all passwords are in clear text.
Set up ssh keys and send files via scp or rsync

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question