summaryrefslogtreecommitdiff
path: root/app/layout/persona.phtml
blob: 8db8d516744c73342ef310eb956a2562dbdf9660 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php if (login_is_conf ($this->conf)) { ?>
<?php
	$mail = Session::param ('mail', 'null');
	if ($mail != 'null') {
		$mail = '\'' . $mail . '\'';
	}
?>

<script type="text/javascript">
url = "<?php echo Url::display (); ?>"
login_url = "<?php echo Url::display (array ('a' => 'login')); ?>";
logout_url = "<?php echo Url::display (array ('a' => 'logout')); ?>";
currentUser = <?php echo $mail; ?>;

var signinLink = $('a#signin');
if (signinLink) {
	signinLink.click(function() {
		navigator.id.request();
		return false;
	});
};
 
var signoutLink = $('a#signout');
if (signoutLink) {
	signoutLink.click(function() {
		navigator.id.logout();
		return false;
	});
};

navigator.id.watch({
	loggedInUser: currentUser,
	onlogin: function(assertion) {
		// A user has logged in! Here you need to:
		// 1. Send the assertion to your backend for verification and to create a session.
		// 2. Update your UI.
		$.ajax ({
			type: 'POST',
			url: login_url,
			data: {assertion: assertion},
			success: function(res, status, xhr) {
				var res_obj = jQuery.parseJSON(res);
				
				if (res_obj.status == 'failure') {
					//alert (res_obj.reason);
				} else if (res_obj.status == 'okay') {
					location.href = url;
				}
			},
			error: function(res, status, xhr) {
				alert("login failure : " + res);
			}
		});
	},
	onlogout: function() {
		// A user has logged out! Here you need to:
		// Tear down the user's session by redirecting the user or making a call to your backend.
		// Also, make sure loggedInUser will get set to null on the next page load.
		// (That's a literal JavaScript null. Not false, 0, or undefined. null.)
		$.ajax ({
			type: 'POST',
			url: logout_url,
			success: function(res, status, xhr) {
				location.href = url;
			},
			error: function(res, status, xhr) {
				//alert("logout failure" + res);
			}
		});
	}
});
</script>
<?php } ?>