def run(self, username, password=None): with self.app_context(): if not password: wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) password = xp.generate_xkcdpassword(mywords, acrostic="ambit") print("generated password: '******'" % password) assert not User.query.filter_by( username=username).scalar(), "user already exists" user = User(username=username) user.password = self.app_bcrypt.generate_password_hash( password, 10) if user.password is not str: user.password = user.password.decode('utf-8') user.active = True db.session.add(user) db.session.commit() print("created user '%s' in '%s'" % (user.username, db.engine.url))
def run(self, username, password=None): with self.app_context(): if not password: wordfile = xp.locate_wordfile() mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8) password = xp.generate_xkcdpassword(mywords, acrostic="ambit") print("generated password: '******'" % password) assert not User.query.filter_by(username=username).scalar(), "user already exists" user = User(username=username) user.password = self.app_bcrypt.generate_password_hash(password, 10) user.active = True db.session.add(user) db.session.commit() print("created user '%s' in '%s'" % (user.username, db.engine.url))
gbr=Image() x=gbr.query.filter_by(path='beranda.jpeg').first() if x is None: gbr.path='beranda.jpeg' db.session.add(gbr) db.session.commit() role = Role() x=role.query.filter_by(name='admin').first() # db.session.delete(x) # db.session.commit() if x is None : role.name='admin' role.description='admin' db.session.add(role) db.session.commit() user = User() y=user.query.filter_by(email='*****@*****.**').first() if y is None: user.email='*****@*****.**' user.password='******' user.active=True user.roles.append(role) # bagian ini yg beda db.session.add(user) db.session.commit()