def set_password(self, user_id, password): q = self.session.query(Password).filter_by(user_id=user_id) encrypted = encrypt_password(password) with transaction.manager: try: p = q.one() except NoResultFound: p = Password(user_id, encrypted) p.password = encrypted self.session.add(p)
def populate_usergroups(session): with transaction.manager: g = Group('admin') session.add(g) g = session.merge(g) u = User('admin') password = encrypt_password('admin') session.add(u) u = session.merge(u) pw = Password(u.id, password) session.add(pw) config = UserConfig(u.id, '') session.add(config) ug = UserGroup(g.id, u.id) session.add(ug)
def populate_users(admin_username): from paella.security import encrypt_password session = DBSession() with transaction.manager: users = [admin_username] # Using id_count to presume # the user's id, which should work # when filling an empty database. id_count = 0 for uname in users: id_count += 1 user = User(uname) password = encrypt_password(uname) session.add(user) pw = Password(id_count, password) session.add(pw) config = UserConfig(id_count, '') session.add(config)