Skip to content

Instantly share code, notes, and snippets.

@SikhNerd
Created May 20, 2010 01:41
Show Gist options
  • Save SikhNerd/407089 to your computer and use it in GitHub Desktop.
Save SikhNerd/407089 to your computer and use it in GitHub Desktop.
<%= call_hook :view_account_login_top %>
<div id="login-form">
<% form_tag({:action=> "login"}) do %>
<%= back_url_hidden_field_tag %>
<table width="460">
<% if Setting.openid? %>
<script>
var
select_openid_url = '',
select_openid_provider = function( field_ns ){
var _url = field_ns.value;
select_openid_url = _url;
field_ns.form['openid_username'].value = '';
if(_url.indexOf('__USERNAME__')===-1){
document.getElementById('openid_username_tr').style.display='none';
field_ns.form['openid_username'].onkeyup = null;
}
else {
document.getElementById('openid_username_tr').style.display='table-row';
_url = _url.replace('__USERNAME__','');
field_ns.form['openid_username'].onkeyup = function(){
var _username = this.value,
_url = select_openid_url.replace('__USERNAME__',_username);
console.log(_url);
this.form['openid_url'].value = _url;
};
}
field_ns.form['openid_url'].value = _url;
},
openid_toggle = function( field_ns ){
var i=0, _tr = 'table-row', _no = 'none',
_fns = ['username_tr','password_tr','openid_radio_tr','openid_url_tr'],
_fst;
if( field_ns.checked ){
_fst = [ _no, _no, _tr, _tr, (select_openid_url.indexOf('__USERNAME__')===-1)?_no:_tr];
}
else {
_fst = [ _tr, _tr, _no, _no, _no];
}
for(; i<_fns.length; i++){
console.log(_fns[i]);
document.getElementById(_fns[i]).style.display=_fst[i];
}
};
</script>
<tr>
<td><div style="width:140px;height:1px;"></div></td>
<td align="left"><label for="openid_toggle_check"><%= check_box_tag 'openid_toggle_check', 1, false, :autocomplete => 'off', :onclick => 'openid_toggle(this);' %> Use OpenID</label><br
/><div style="width:100%;height:1px;"></div></td>
</tr>
<% end %>
<tr id="username_tr">
<td align="right"><label for="username"><%=l(:field_login)%>:</label></td>
<td align="left"><%= text_field_tag 'username', nil, :tabindex => '1' %></td>
</tr>
<tr id="password_tr">
<td align="right"><label for="password"><%=l(:field_password)%>:</label></td>
<td align="left"><%= password_field_tag 'password', nil, :tabindex => '2' %></td>
</tr>
<% if Setting.openid? %>
<tr id="openid_radio_tr" style="display:none">
<td align="right" valign="top"><label for="openid_url_radio">OpenID Provider:</label></td>
<td align="left">
<%
[ [ 'https://www.google.com/accounts/o8/id', 'Google' ], # tested
[ 'https://me.yahoo.com', 'Yahoo' ], # tested
[ 'https://openid.aol.com', 'AOL' ], # tested
[ 'https://www.myopenid.com/', 'MyOpenID' ], # tested
[ 'https://pip.verisignlabs.com/', 'Verisign' ], # untested
[ 'https://api.myspace.com/openid', 'MySpace' ], # untested
[ 'https://myid.net/', 'MyID.net' ], # untested
[ 'http://www.hyves.nl/', 'Hyves' ], # untested
[ 'https://i.mydocomo.com/', 'NTT MyDocomo' ], # untested
# [ 'https://__USERNAME__.livejournal.com/', 'LiveJournal' ], # doesn't work at least from 127.0.0.1
# add more tested url/name combinations, use '__USERNAME__' where an username needs to be entered
[ '', 'Other (enter URL manually)' ] ].each do |openid_url, openid_name|
%>
<label><%= radio_button_tag 'openid_url_radio', openid_url, openid_url=='', :autocomplete => 'off', :onclick => 'select_openid_provider(this);' %> <%= openid_name %></label><br />
<% end %>
</td>
</tr>
<tr id="openid_username_tr" style="display:none">
<td align="right"><label for="openid_username">OpenID Provider Username</label></td>
<td align="left"><%= text_field_tag "openid_username", nil, :style => 'width:300px' %></td>
</tr>
<tr id="openid_url_tr" style="display:none">
<td align="right"><label for="openid_url"><%=l(:field_identity_url)%></label></td>
<td align="left"><%= text_field_tag "openid_url", nil, :tabindex => '3', :style => 'width:300px' %></td>
</tr>
<% end %>
<tr>
<td></td>
<td align="left">
<% if Setting.autologin? %>
<label for="autologin"><%= check_box_tag 'autologin', 1, false, :tabindex => 4 %> <%= l(:label_stay_logged_in) %></label>
<% end %>
</td>
</tr>
<tr>
<td align="left">
<% if Setting.lost_password? %>
<%= link_to l(:label_password_lost), :controller => 'account', :action => 'lost_password' %>
<% end %>
</td>
<td align="right">
<input type="submit" name="login" value="<%=l(:button_login)%> &#187;" tabindex="5"/>
</td>
</tr>
</table>
<%= javascript_tag "Form.Element.focus('username');" %>
<% end %>
</div>
<%= call_hook :view_account_login_bottom %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment