def getUserbyUsername(self, uname): mu = MUser.query.filter_by(username=uname).first() if mu is None: return None u = User(mu.username, mu.name) u._id = mu.id return u
def getUserbyID(self, uid): mu = MUser.query.get(uid) if mu is None: return None u = User(mu.username, mu.name, self._castNumberToPermission(mu.security_flags)) u._id = mu.id return u
def create_user(self, username, password): from ghostwriter.User import User from ghostwriter.UserManager import UserManager u = User(username) umng = UserManager() umng.addUser(u, password) return u
def create_user(self, name, pwd): from ghostwriter.User import User, UserPerm from ghostwriter.UserManager import UserManager u = User(name, name, [UserPerm.ADMIN]) umng = UserManager() umng.addUser(u, pwd) return u
def create_user(self): from ghostwriter.User import User from ghostwriter.UserManager import UserManager self.username = '******' self.password = '******' u = User(self.username) umng = UserManager() umng.addUser(u, self.password)
def test_permissionvalidationPartial(self): from ghostwriter.User import User, UserPerm u = User("test", "Test", [UserPerm.MANAGEPOSTS, UserPerm.VIEWUSERS]) self.assertTrue(u.checkPermission(UserPerm.CREATEPOST)) self.assertTrue(u.checkPermission(UserPerm.MANAGEPOSTS)) self.assertTrue(u.checkPermission(UserPerm.VIEWUSERS)) self.assertFalse(u.checkPermission(UserPerm.CREATEUSER)) self.assertFalse(u.checkPermission(UserPerm.MANAGEUSERS)) self.assertFalse(u.checkPermission(UserPerm.ADMIN))
def getAllUsers(self, start=0, end=None): """ Get all posts by IDorder, from start to start+end. If none found, return empty list """ us = [] muq = MUser.query.order_by(MUser.id).offset(start) if not (end is None): muq = muq.limit(end) mu = muq.all() if mu is None: return [] for muitem in mu: u = User(muitem.username, muitem.name, self._castNumberToPermission(muitem.security_flags)) u._id = muitem.id us.append(u) return us
def initdb(): """ Initialise the database """ print('Creating database') try: mm.create() from ghostwriter.User import User from ghostwriter.UserManager import UserManager um = UserManager() um.addUser(User('admin', 'Administrator'), 'admin') print('Database created') except Exception as e: print('Error') app.logger.error('Error while creating database: {}'.format(e))
def user_list_manage(): """ Manages users GET: Gets all users POST: Creates an user username: login name password: the password name: the user true name. Optional Return an 200 OK if all OK """ from ghostwriter.User import User from ghostwriter.UserManager import UserManager um = UserManager() if request.method == 'GET': userlist = um.getAllUsers() if len(userlist) <= 0: return jsonify({'error': 'No users'}), 404 juser = [] for user in userlist: jdata = { 'id': user.uid, 'username': user.username, 'name': user.name } juser.append(jdata) return jsonify(juser), 200 elif request.method == 'POST': login = request.form['username'] password = request.form['password'] try: name = request.form['name'] except KeyError: name = login user = User(login, name) um.addUser(user, password) jdata = {'id': user.uid, 'username': user.username, 'name': user.name} return jsonify(jdata), 200 else: return "", 405
def test_permissionvalidationNone(self): from ghostwriter.User import User, UserCreationException, UserPerm with self.assertRaises(UserCreationException): u = User("test", "test", [])