forked from osmlab/osm-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (111 loc) · 3.59 KB
/
index.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
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html>
<head>
<title>osm-auth</title>
<link rel='stylesheet' type='text/css' href='' />
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<style>
body {
width: 300px;
margin: 40px auto;
font:normal 12px/20px 'Helvetica Neue', sans-serif;
}
button {
border-radius:5px;
background:#54af29;
border-color:#2C7505;
color:#fff;
width:145px;
font-size:25px;
text-shadow:1px 1px -1px #2C7505;
padding:10px;
}
button.done {
background:#2C7505;
}
button:hover {
background: #2C7505;
}
#user {
display:none;
font:normal 15px/20px 'Helvetica Neue', sans-serif;
text-align:center;
}
h1, h2 {
margin: 10px 0;
}
p {
text-align:center;
color:#666;
}
</style>
</head>
<body>
<button id='authenticate'>login</button>
<button id='logout'>logout</button>
<div id='user'>
<h1 id='display_name'></h1>
<h2 id='id'></h2>
Changesets: <span id='count'></span>
</div>
<p><a href='https://github.com/osmlab/osm-auth'>osm-auth</a> is a minimal
example of authenticating and interacting with the
<a href='http://www.openstreetmap.org/'>openstreetmap</a>
API.</p>
<script src='osmauth.js'></script>
<script>
var auth = osmAuth({
oauth_secret: '9WfJnwQxDvvYagx1Ut0tZBsOZ0ZCzAvOje3u1TV0',
oauth_consumer_key: 'WLwXbm6XFMG7WrVnE8enIF6GzyefYIN6oUJSxG65'
});
function done(err, res) {
if (err) {
document.getElementById('user').innerHTML = 'error! try clearing your browser cache';
document.getElementById('user').style.display = 'block';
return;
}
var u = res.getElementsByTagName('user')[0];
var changesets = res.getElementsByTagName('changesets')[0];
var o = {
display_name: u.getAttribute('display_name'),
id: u.getAttribute('id'),
count: changesets.getAttribute('count')
};
for (var k in o) {
document.getElementById(k).innerHTML = o[k];
}
document.getElementById('user').style.display = 'block';
}
document.getElementById('authenticate').onclick = function() {
auth.authenticate(function() {
update();
});
};
function showDetails() {
auth.xhr({
method: 'GET',
path: '/api/0.6/user/details'
}, done);
}
function hideDetails() {
document.getElementById('user').style.display = 'none';
}
document.getElementById('logout').onclick = function() {
auth.logout();
update();
};
function update() {
if (auth.authenticated()) {
document.getElementById('authenticate').className = 'done';
document.getElementById('logout').className = '';
showDetails();
} else {
document.getElementById('authenticate').className = '';
document.getElementById('logout').className = 'done';
hideDetails();
}
}
update();
</script>
</body>
</html>