aboutsummaryrefslogtreecommitdiff
path: root/src/phorkie/Login/AutologinResponse.php
blob: 9384e3b39dedfdbd1a6cb17a2ab91bb2136eb042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace phorkie;

class Login_AutologinResponse
{
    /**
     * 'error' or 'ok'
     *
     * @var string
     */
    public $status;

    /**
     * Status message
     *
     * @var string
     */
    public $message;

    public $name;
    public $identity;

    public function __construct($status = 'error', $message = null)
    {
        $this->status  = $status;
        $this->message = $message;
    }

    public function send()
    {
        if ($this->status == 'error') {
            //Cookie to prevent trying autologin again and again.
            // After 1 hour the cookie expires and autologin is tried again.
            setcookie('tried-autologin', '1', time() + 60 * 60);
        }

        $data = htmlspecialchars(json_encode($this), ENT_NOQUOTES);
        header('Content-type: text/html');
        echo <<<XML
<html>
 <head>
  <title>Autologin response</title>
  <script type="text/javascript">
    parent.notifyAutologin($data);
  </script>
 </head>
 <body></body>
</html>

XML;
    }
}
?>