Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
 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)
Esempio n. 6
0
    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))
Esempio n. 7
0
    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
Esempio n. 8
0
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))
Esempio n. 9
0
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
Esempio n. 10
0
    def test_permissionvalidationNone(self):
        from ghostwriter.User import User, UserCreationException, UserPerm

        with self.assertRaises(UserCreationException):
            u = User("test", "test", [])