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
|
# File 'lib/devise_yauth_token/devise_yauth_token_helper.rb', line 6
def yauth_auto_login(auth_url = "")
unless user_signed_in?
%Q{<script type='text/javascript'>
function post_to_url(path, params, method) {
method = method || 'post'; // Set method to post by default, if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement('form');
form.setAttribute('method', method);
form.setAttribute('action', path);
for(var key in params) {
var hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', key);
hiddenField.setAttribute('value', params[key]);
form.appendChild(hiddenField);
}
document.body.appendChild(form); // Not entirely sure if this is necessary
form.submit();
}
$(document).ready(function(){
var data = {};
$.getJSON('http://#{current_account.yauth_host}/api/auth/yauth_token.json?auth_host=#{self.request.host}&callback=?', data, function(jsonp){
if(jsonp.status == 200){
post_to_url('#{auth_url}', {'yauth_token': jsonp.data.token});
}
else if (jsonp.status == 401){
document.location.href = 'http://#{current_account.yauth_host}/users/sign_in?continue=#{self.request.url}';
}
else if (jsonp.status == 400){
document.location.href = 'http://#{current_account.yauth_host}/users/sign_out';
}
else if (jsonp.data.status == "locked") {
$.ajax({url:"/locked.html?a",success:function(d){$("body").html(d)}})
}
});
});
</script>}.html_safe
end
end
|