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
|
# File 'lib/gigya/session.rb', line 31
def new
head_code = <<EOF
<script type='text/javascript' src='https://cdns.gigya.com/js/gigya.js?apikey=#{self.class.gigya_api_key}'></script>
<script type="text/javascript">
function did_login(evt, resp) {
form = document.getElementById("hidden-login-form");
gtok = document.getElementById("gigya-token");
gtok.value = resp.id_token;
form.submit();
}
var expire_time = #{self.class.gigya_token_expire_time};
gigya.accounts.showScreenSet({
screenSet: '#{self.class.gigya_screen_set}',
startScreen: '#{self.class.gigya_start_screen}',
containerID: 'gigya-screenset-container',
deviceType: 'mobile',
sessionExpiration: expire_time,
onAfterSubmit: function(evt) {
if(evt.form == 'gigya-login-form' && evt.response.errorCode == 0) {
gigya.accounts.getJWT({
fields: "#{self.class.gigya_jwt_fields}",
expiration: expire_time,
callback: function(resp) {
did_login(evt, resp);
}
});
}
}
});
</script>
EOF
body_code = <<EOF
<%= form_tag request.path.gsub('/new', ''), :id => "hidden-login-form" do %>
<%= hidden_field_tag :redirect, params[:redirect] %>
<%= hidden_field_tag :gigya_token, "", :id => "gigya-token" %>
<% end %>
<div class="gigya-screenset-class" id="gigya-screenset-container"></div>
EOF
if self.class.gigya_script_content_for.present?
head_code = "<% content_for :#{gigya_script_content_for} do %>#{head_code}<% end %>"
end
full_erb = head_code + body_code
render :inline => full_erb, :layout => true
end
|