tracks/app/views/login/login.html.erb

137 lines
5 KiB
Text

<% auth_schemes = Tracks::Config.auth_schemes
show_database_form = auth_schemes.include?('database') || auth_schemes.include?('ldap')
show_openid_form = auth_schemes.include?('open_id')
show_cas_form = auth_schemes.include?('cas')
-%>
<div title="Account login" id="loginform" class="form">
<%= render_flash %>
<h3>Please log in to use Tracks:</h3>
<% if show_database_form %>
<div id="database_auth_form" style="display:<%=(@prefered_auth.eql?('database')) ? "block" : "none"%>">
<% form_tag :action=> 'login' do %>
<table>
<tr>
<td><label for="user_login">Login:</label></td>
<td><input type="text" name="user_login" id="user_login" value="" class="login_text" /></td>
</tr>
<tr>
<td><label for="user_password">Password:</label></td>
<td><input type="password" name="user_password" id="user_password" class="login_text" /></td>
</tr>
<tr>
<td><label for="user_noexpiry">Stay logged in:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Sign In &#187;" class="primary" /></td>
</tr>
</table>
<% end %>
</div>
<% end %>
<% if show_openid_form %>
<div id="openid_auth_form" style="display:<%=(@prefered_auth.eql?('openid')) ? "block" : "none"%>">
<% form_tag :action=> 'login' do %>
<table>
<tr>
<td><label for="openid_url">Identity URL:</label></td>
<td><input type="text" name="openid_url" id="openid_url" value="<%= @openid_url %>" class="login_text open_id" /></td>
</tr>
<tr>
<td><label for="user_noexpiry">Stay logged in:</label></td>
<td><input type="checkbox" name="user_noexpiry" id="user_noexpiry" checked /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Sign In &#187;" class="primary" /></td>
</tr>
</table>
<% end %>
</div>
<% end %>
<% if show_cas_form %>
<div id="cas_auth_form" style="display:<%=(@prefered_auth.eql?('cas')) ? "block" : "none"%>">
<table>
<tr>
<td>
<% if @username && @user%>
<p>Hello, <%= @username %>! You are authenticated.</p>
<% elsif @username %>
<p>Hello, <%= @username %>! You do not have an account on Tracks.
<%if SITE_CONFIG['open_signups']%>
If you like to request on please go here to <%= link_to "Request Account" , signup_url %>
<%end%>
</p>
<% else %>
<p><%= link_to("CAS Login", login_cas_url) %> </p>
<% end %>
</td>
</tr>
</table>
</div>
<% end %>
</div>
<% if show_openid_form %><p id="alternate_auth_openid" class="alternate_auth">or, <a href="#" onclick="Login.showOpenid();return false;">login with an OpenId</a></p><% end %>
<% if show_database_form %><p id="alternate_auth_database" class="alternate_auth">or, <a href="#" onclick="Login.showDatabase();return false;">go back to the standard login</a></p><% end %>
<% if show_cas_form %><p id="alternate_auth_cas" class="alternate_auth">or, <a href="#" onclick="Login.showCAS();return false;">go to the CAS</a></p><% end %>
<script type="text/javascript">
function showPreferredAuth() {
var preferredAuth = $.cookie('preferred_auth');
var casEnabled = <%= show_cas_form ? 'true' : 'false' %>;
var databaseEnabled = <%= show_database_form ? 'true' : 'false' %>;
var openidEnabled = <%= show_openid_form ? 'true' : 'false' %>;
if (preferredAuth && preferredAuth == 'openid' && openidEnabled) {
Login.showOpenid();
}
else if (preferredAuth && preferredAuth == 'database' && databaseEnabled) {
Login.showDatabase();
}
else if (preferredAuth && preferredAuth == 'cas' && casEnabled) {
Login.showCAS();
}
}
$(document).ready(showPreferredAuth);
var Login = {
showOpenid: function() {
$('#database_auth_form').hide();
$('#openid_auth_form').show();
$('#alternate_auth_openid').hide();
$('#alternate_auth_database').show(); ;
$('#alternate_auth_cas').show();
$('#openid_url').focus();
$('#openid_url').select();
$.cookie('preferred_auth', 'openid');
},
showDatabase: function(container) {
$('#openid_auth_form').hide();
$('#database_auth_form').show();
$('#alternate_auth_database').hide();
$('#alternate_auth_openid').show();
$('#alternate_auth_cas').show();
$('#user_login').focus();
$('#user_login').select();
$.cookie('preferred_auth', 'database');
},
showCAS: function(container) {
$('#database_auth_form').hide();
$('#openid_auth_form').hide();
$('#cas_auth_form').show();
$('#alternate_auth_cas').hide();
$('#alternate_auth_openid').show();
$('#alternate_auth_database').show();
$.cookie('preferred_auth', 'cas');
}
}
</script>