-
Notifications
You must be signed in to change notification settings - Fork 38
/
dev.html
106 lines (75 loc) · 2.92 KB
/
dev.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<title>jDrupal</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Load jDrupal and configure its settings-->
<script src="jdrupal.min.js"></script>
<script type="text/javascript">
jDrupal.settings = {
sitePath: '', // The path to your Drupal site, for example: http://www.example.com
basePath: '/'
};
function start() {
(function($) {
// Connect to Drupal... if the user is anonymous show them the login form, otherwise say hello to them.
$.connect().then(function(result) {
console.log(result);
// Grab the current user.
var account = $.currentUser();
// Anonymous users.
if (!account.isAuthenticated()) {
// Show the login form.
document.getElementById('user_login_form').style.display = 'inline';
}
// Authenticated users.
else {
// Show the user dashboard and say hello.
document.getElementById('user_dashboard').style.display = 'inline';
var msg = 'Hello, ' + account.getAccountName();
console.log(msg);
}
});
}(jDrupal));
}
// Handle the login button click.
function login_click() {
// Grab the user input.
var name = document.getElementById('name').value;
var pass = document.getElementById('pass').value;
// User login.
jDrupal.userLogin(name, pass).then(
function() {
document.getElementById('user_dashboard').style.display = 'inline';
document.getElementById('user_login_form').style.display = 'none';
},
function(err) { alert(err); }
);
}
// Handle the logout button click.
function logout_click() {
// User logout.
jDrupal.userLogout().then(function(){
document.getElementById('user_dashboard').style.display = 'none';
document.getElementById('user_login_form').style.display = 'inline';
});
}
</script>
</head>
<body onload="start()">
<form id="user_login_form" style="display: none;">
<div>
<input id="name" type="text" value="" placeholder="Username"/>
</div>
<div>
<input id="pass" type="password" value="" placeholder="Password" />
</div>
<input type="button" value="Login" onclick="login_click()"/>
</form>
<div id="user_dashboard" style="display: none;">
<p>Welcome..</p>
<div><a href="#" onclick="logout_click()">Logout</a></div>
</div>
</body>
</html>