def save(self):
        staff = self.obj or Staff()
        # do not use populate_obj here, session.add will not work
        staff.full_name = self.full_name.data
        staff.title = self.title.data
        email = self.user.email.data

        if staff.user is None:
            try:
                staff.user = User.query.filter_by(email=email).one()
            except NoResultFound:
                staff.user = User(email=email,
                                  recover_token=str(uuid4()),
                                  recover_time=datetime.now())
                send_activation_mail(staff.user.email,
                                     staff.user.recover_token)
        else:
            staff.user.email = email

        if self.user.is_superuser:
            staff.user.is_superuser = self.user.is_superuser.data

        if staff.id is None:
            db.session.add(staff)
        db.session.commit()
        return staff
def create_superuser(ctx):
    email = click.prompt('Enter email', type=str)
    while not validate_email(email):
        email = click.prompt('Invalid email. Enter another email', type=str)
    password = click.prompt('Enter password', type=str, hide_input=True)
    confirm = click.prompt('Enter password again', type=str, hide_input=True)

    if password == confirm:
        app = ctx.obj['app']
        with app.app_context():
            user = User(email=email, is_superuser=True)
            user.set_password(password)
            db.session.add(user)
            staff = Staff(user=user, full_name='')
            db.session.add(staff)
            db.session.commit()
            click.echo('Superuser has been created')
    else:
        click.echo('Passwords differ')
예제 #3
0
def create_user(ctx):
    email = click.prompt('Enter email', type=str)
    while not validate_email(email):
        email = click.prompt('Invalid email. Enter another email', type=str)
    password = click.prompt('Enter password', type=str, hide_input=True)
    confirm = click.prompt('Enter password again', type=str, hide_input=True)

    if password == confirm:
        app = ctx.obj['app']
        with app.app_context():
            user = User(email=email)
            user.set_password(password)
            db.session.add(user)
            staff = Staff(user=user, full_name='')
            db.session.add(staff)
            db.session.commit()
            click.echo('User has been created')
    else:
        click.echo('Passwords differ')
예제 #4
0
 def save(self):
     user = User(email=self.email.data)
     user.set_password(self.password.data)
     db.session.add(user)
     db.session.commit()
     return user
 def save(self):
     user = User(email=self.email.data)
     user.set_password(self.password.data)
     db.session.add(user)
     db.session.commit()
     return user