1<?php
2/**
3 * Sends an authentication failure response to the HordeCore JS framework.
4 *
5 * Copyright 2012-2017 Horde LLC (http://www.horde.org/)
6 *
7 * See the enclosed file COPYING for license information (LGPL). If you
8 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
9 *
10 * @author   Michael Slusarz <slusarz@horde.org>
11 * @category Horde
12 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
13 * @package  Core
14 */
15class Horde_Core_Ajax_Response_HordeCore_NoAuth extends Horde_Core_Ajax_Response_HordeCore
16{
17    /**
18     * App of the last JSON request.
19     *
20     * @var string
21     */
22    protected $_app;
23
24    /**
25     * The authentication error.
26     *
27     * @var integer
28     */
29    protected $_error;
30
31    /**
32     * Constructor.
33     *
34     * @param string $app  App of the last JSON request.
35     */
36    public function __construct($app, $error = Horde_Auth::REASON_FAILED)
37    {
38        $this->_app = $app;
39        $this->_error = $error;
40    }
41
42    /**
43     */
44    public function send()
45    {
46        global $registry;
47
48        if (!empty($registry->authException)) {
49            $registry->getApiInstance($this->_app, 'application')->appInitFailure($registry->authException);
50        }
51
52        parent::send();
53    }
54
55    /**
56     */
57    protected function _jsonData()
58    {
59        $msg = new stdClass;
60        $msg->message = strval($GLOBALS['registry']->getLogoutUrl(array(
61            'reason' => $this->_error
62        ))->add('url', Horde::url('', false, array(
63            'app' => $this->_app,
64            'append_session' => -1
65        ))));
66        $msg->type = 'horde.noauth';
67
68        $ob = new stdClass;
69        $ob->msgs = array($msg);
70        $ob->response = false;
71
72        return $ob;
73    }
74
75}
76