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')
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')
def save(self): user = User(email=self.email.data) user.set_password(self.password.data) db.session.add(user) db.session.commit() return user