1
|
function login()
|
2
|
{
|
3
|
var user = document.getElementById("un").value;
|
4
|
var org = document.getElementById("org").value;
|
5
|
var pass = document.getElementById("pw").value;
|
6
|
var ldapUsername = 'uid=' + user + ',o=' + org + ',dc=ecoinformatics,dc=org';
|
7
|
|
8
|
$.get("metacat", {username: ldapUsername, password: pass, action:"login", qformat:"xml"},
|
9
|
function(data) {
|
10
|
//alert('user ' + ldapUsername + ' logged in. data:' + data);
|
11
|
if(data.indexOf('<sessionId>') != -1)
|
12
|
{ //login successful
|
13
|
//alert('user logged in');
|
14
|
slideUp("#loginformdiv");
|
15
|
setCookie("sms-login", true);
|
16
|
setCookie("sms-user", user);
|
17
|
setCookie("sms-org", org);
|
18
|
setLoginHeader(true);
|
19
|
}
|
20
|
else
|
21
|
{ //login not successful
|
22
|
alert('Sorry, your login failed. Please try again. If you need a username, please go to http://knb.ecoinformatics.org.');
|
23
|
setCookie("sms-login", false);
|
24
|
}
|
25
|
|
26
|
}, "XML");
|
27
|
}
|
28
|
|
29
|
function setLoginHeader(loggedin)
|
30
|
{
|
31
|
if(loggedin)
|
32
|
{
|
33
|
var user = getCookie("sms-user");
|
34
|
$('#loginheader').replaceWith("<h2 style=\"text-align:center\" id=\"loginheader\">"
|
35
|
+ user + " Logged In <a href=\"javascript:\" onclick=\"logout()\" style=\"font-size:70%\">[logout]</a></h2>");
|
36
|
slideUp("#loginformdiv");
|
37
|
$('#maindiv').css("display", "block");
|
38
|
$('#bottomimg').css("bottom", "0px");
|
39
|
$.get("metacat", {action:"getlastdocid", scope:"sms"},
|
40
|
function(data)
|
41
|
{
|
42
|
var docid = data.substring(data.indexOf("<docid>") + 7, data.indexOf("</docid>"));
|
43
|
var nextid;
|
44
|
if(docid == 'null')
|
45
|
{
|
46
|
nextid = "sms.1.1";
|
47
|
}
|
48
|
else
|
49
|
{
|
50
|
nextid = docid.substring(docid.indexOf(".") + 1, docid.lastIndexOf("."));
|
51
|
nextid++;
|
52
|
nextid = "sms." + nextid + ".1";
|
53
|
}
|
54
|
$('#docidtextfield').val(nextid);
|
55
|
},
|
56
|
"XML");
|
57
|
}
|
58
|
else
|
59
|
{
|
60
|
$('#loginheader').replaceWith("<h2 style=\"text-align:center\" id=\"loginheader\">"
|
61
|
+ "Please Log In</h2>");
|
62
|
slideDown("#loginformdiv");
|
63
|
$('#maindiv').css("display", "none");
|
64
|
$('#bottomimg').css("bottom", "15px");
|
65
|
}
|
66
|
}
|
67
|
|
68
|
function logout()
|
69
|
{
|
70
|
$.get("metacat", {action:"logout", qformat:"xml"});
|
71
|
setLoginHeader(false);
|
72
|
setCookie("sms-login", false);
|
73
|
}
|
74
|
|
75
|
function checkLogin()
|
76
|
{
|
77
|
if(getCookie("sms-login") == "true")
|
78
|
{
|
79
|
setLoginHeader(true);
|
80
|
}
|
81
|
else
|
82
|
{
|
83
|
setLoginHeader(false);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
function uploadfile()
|
88
|
{
|
89
|
if(getCookie("sms-login") != "true")
|
90
|
{
|
91
|
alert('You cannot upload. You are not logged in.');
|
92
|
return;
|
93
|
}
|
94
|
|
95
|
/*$.post("metacat", $("form").serialize(),
|
96
|
function(data)
|
97
|
{
|
98
|
alert($("form").serialize());
|
99
|
alert(data);
|
100
|
},
|
101
|
"XML");*/
|
102
|
$("form").submit();
|
103
|
}
|
104
|
|
105
|
function slideUp(id)
|
106
|
{
|
107
|
$(id).slideUp("slow");
|
108
|
}
|
109
|
|
110
|
function slideDown(id)
|
111
|
{
|
112
|
$(id).slideDown("slow");
|
113
|
}
|
114
|
|
115
|
function setCookie( name, value, expires, path, domain, secure )
|
116
|
{
|
117
|
// set time, it's in milliseconds
|
118
|
var today = new Date();
|
119
|
today.setTime( today.getTime() );
|
120
|
|
121
|
/*
|
122
|
if the expires variable is set, make the correct
|
123
|
expires time, the current script below will set
|
124
|
it for x number of days, to make it for hours,
|
125
|
delete * 24, for minutes, delete * 60 * 24
|
126
|
*/
|
127
|
if ( expires )
|
128
|
{
|
129
|
expires = expires * 1000 * 60 * 60 * 24;
|
130
|
}
|
131
|
var expires_date = new Date( today.getTime() + (expires) );
|
132
|
|
133
|
document.cookie = name + "=" +escape( value ) +
|
134
|
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
|
135
|
( ( path ) ? ";path=" + path : "" ) +
|
136
|
( ( domain ) ? ";domain=" + domain : "" ) +
|
137
|
( ( secure ) ? ";secure" : "" );
|
138
|
}
|
139
|
|
140
|
function getCookie( check_name ) {
|
141
|
// first we'll split this cookie up into name/value pairs
|
142
|
// note: document.cookie only returns name=value, not the other components
|
143
|
var a_all_cookies = document.cookie.split( ';' );
|
144
|
var a_temp_cookie = '';
|
145
|
var cookie_name = '';
|
146
|
var cookie_value = '';
|
147
|
var b_cookie_found = false; // set boolean t/f default f
|
148
|
|
149
|
for ( i = 0; i < a_all_cookies.length; i++ )
|
150
|
{
|
151
|
// now we'll split apart each name=value pair
|
152
|
a_temp_cookie = a_all_cookies[i].split( '=' );
|
153
|
|
154
|
// and trim left/right whitespace while we're at it
|
155
|
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
|
156
|
|
157
|
// if the extracted name matches passed check_name
|
158
|
if ( cookie_name == check_name )
|
159
|
{
|
160
|
b_cookie_found = true;
|
161
|
// we need to handle case where cookie has no value but exists (no = sign, that is):
|
162
|
if ( a_temp_cookie.length > 1 )
|
163
|
{
|
164
|
cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
|
165
|
}
|
166
|
// note that in cases where cookie is initialized but no value, null is returned
|
167
|
return cookie_value;
|
168
|
break;
|
169
|
}
|
170
|
a_temp_cookie = null;
|
171
|
cookie_name = '';
|
172
|
}
|
173
|
if ( !b_cookie_found )
|
174
|
{
|
175
|
return null;
|
176
|
}
|
177
|
}
|