def get(self, user_id):
        user_api = BoruvkaUserApi(self.dao)

        viewer_id = self.session['user_id']

        user = user_api.get_user(id=user_id)

        setting_query = BoruvkaSettingQuery(self.dao)

        user_settings = setting_query.get_user_settings(user_id)
        allowed_settings = setting_query.get_settings()

        viewer_settings = setting_query.get_user_settings(viewer_id)
        translation = viewer_settings['language']
        view = BoruvkaUserEditView(
            translation=translation,
        )

        view._full = not self.request.is_xhr
        view._user = user
        view._settings = allowed_settings
        view._user_settings = user_settings

        response = Response()
        response.body = view.render()
        return response
Exemplo n.º 2
0
    def get(self):
        user_id = self.session["user_id"]
        user_api = BoruvkaUserApi(self.dao)
        user = user_api.get_user(id=user_id)

        setting_query = BoruvkaSettingQuery(self.dao)
        user_settings = setting_query.get_user_settings(user_id)
        translation = user_settings["language"]
        view = BoruvkaHomeView(translation)

        view.user = user
        view._color = user_settings["color"]

        response = Response()
        response.body = view.render()
        return response
Exemplo n.º 3
0
    def register(self, payload):
        username = payload['username']
        password = payload['password']

        hashed_password = self.hash_password(
            username,
            password,
        )

        user_query = BoruvkaUserQuery(self._dao)
        user = user_query.create_user(
            username=username,
            password=hashed_password,
        )

        settings_query = BoruvkaSettingQuery(self._dao)
        settings_query.create_user_settings(
            user_id=user.id,
        )
        return True
Exemplo n.º 4
0
    def update_user(self, user_id, payload):
        user_query = BoruvkaUserQuery(self._dao)
        settings_query = BoruvkaSettingQuery(self._dao)

        user = user_query.get_user(
            id=user_id,
        )

        username = payload['username']
        password = payload['password']
        if len(password) > 0:
            user.password = BoruvkaAuthApi.hash_password(
                username,
                password,
            )

        self._dao.update(user)

        image_id = payload['image_id']
        image = payload['image']
        if isinstance(image, FieldStorage) and "image" in image.type:
            if image_id == '':
                # TODO: use random string
                image_id = user_id

            with open('webroot/img/user/' + user_id, 'wb') as fout:
                copyfileobj(image.file, fout, 100000)

        # TODO, make setting options more generic
        options = {
            'language': payload['language'],
            'color': payload['color'],
            'image': image_id,
        }

        settings_query.set_user_settings(
            user_id=user_id,
            options=options,
        )

        return
    def get(self):
        api = BoruvkaUserApi(self.dao)
        users = api.list_users()

        setting_query = BoruvkaSettingQuery(self.dao)
        users_settings = {}
        for user in users:
            users_settings[user.id] = setting_query.get_user_settings(user.id)


        # TODO: move translations handling to BaseController
        translation = list(self.request.accept_language)[0]
        view = BoruvkaUserListView(
            translation=translation,
        )

        view._full = not self.request.is_xhr
        view._users = users
        view._users_settings = users_settings

        response = Response()
        response.body = view.render()
        return response
        try:
            user_api.update_user(
                user_id=user_id,
                payload=response_dict,
            )
        except BoruvkaApiException, e:
            error = e
        else:
            message = "Saved"

        user = user_api.get_user(
            id=user_id,
        )

        setting_query = BoruvkaSettingQuery(self.dao)
        user_settings = setting_query.get_user_settings(user_id)
        allowed_settings = setting_query.get_settings()

        viewer_settings = setting_query.get_user_settings(viewer_id)
        translation = viewer_settings['language']
        view = BoruvkaUserEditView(
            translation=translation,
        )

        view._full = not self.request.is_xhr
        view._user = user
        view._settings = allowed_settings
        view._user_settings = user_settings

        view.message = message