Beispiel #1
0
    def login(self):
        hubclient = self.request.registry.hubclient
        response = HTTPFound()

        # redeem ticket to get user data
        ticket = self.request.GET.get('ticket', None)
        if ticket and hubclient:
            try:
                user = hubclient.get_user(
                    ticket, self.request.route_url('redirect_to_login'))
                self.request.session[USER_DATA_SESSION_KEY] = user.data
                user_id = user.get('uuid')
                headers = remember(self.request, user_id)
                response.headerlist.extend(headers)

            except HubClientException:
                # TODO: what to do when ticket is invalid?
                pass

        redirect_url = self.request.GET.get('url', None)
        if not (redirect_url and same_origin(
                redirect_url, self.request.current_route_url())):
            redirect_url = self.request.route_url(route_name='home')
        response.location = redirect_url

        return response
Beispiel #2
0
    def flag_comment(self):
        commentclient = self.request.registry.commentclient

        if None in (self.request.user, commentclient):
            raise HTTPNotFound

        flag_data = {
            'user_uuid': self.request.user.get('uuid'),
            'comment_uuid': self.request.matchdict['uuid'],
            'submit_datetime': datetime.now(pytz.utc).isoformat(),
            'app_uuid': commentclient.settings['app_id']
        }
        try:
            commentclient.create_flag(flag_data)
        except CommentServiceException as e:
            if e.response.status_code == 404:
                raise HTTPNotFound
            raise e

        query = {}
        if self.request.referrer and same_origin(
                self.request.referrer, self.request.current_route_url()):
            query = {'next': self.request.referrer}

        return HTTPFound(self.request.route_url(
            'flag_comment_success', uuid=flag_data['comment_uuid'],
            _query=query))
Beispiel #3
0
    def logout(self):
        response = HTTPFound(headers=forget(self.request))

        if self.request.referrer and same_origin(
                self.request.referrer, self.request.current_route_url()):
            response.location = self.request.referrer
        else:
            response.location = self.request.route_url(route_name='home')

        return response
Beispiel #4
0
    def flag_comment_success(self):
        if not self.request.user:
            raise HTTPNotFound

        next_url = self.request.GET.get('next')
        if next_url and not same_origin(
                next_url, self.request.current_route_url()):
            next_url = None

        return {'next': next_url}
Beispiel #5
0
    def redirect_to_login(self):
        hubclient = self.request.registry.hubclient

        if self.request.referrer and same_origin(
                self.request.referrer, self.request.current_route_url()):
            callback_url = self.request.route_url(
                route_name='login', _query={'url': self.request.referrer})
        else:
            callback_url = self.request.route_url(route_name='login')

        return HTTPFound(hubclient.get_login_redirect_url(
            callback_url, locale=self.language))
Beispiel #6
0
    def redirect_to_login(self):
        hubclient = self.request.registry.hubclient

        if self.request.referrer and same_origin(
                self.request.referrer, self.request.current_route_url()):
            callback_url = self.request.route_url(
                route_name='login', _query={'url': self.request.referrer})
        else:
            callback_url = self.request.route_url(route_name='login')

        if hubclient is None:
            # benign redirect if hubclient is not configured
            return HTTPFound(callback_url)

        return HTTPFound(hubclient.get_login_redirect_url(
            callback_url, locale=self.locale))