Added ability to login with a username that is case insensitive

Added some missing translations
Small CSS tweaks
This commit is contained in:
Luke Barratt 2014-04-04 20:38:44 +01:00
parent 2021af051c
commit 1e6d3efc14
12 changed files with 54 additions and 12 deletions

View file

@ -18,8 +18,10 @@ div
> h1
@include shaded-top
box-sizing: border-box
padding: 8px
margin: 0
width: 100%
height: 35px
font-size: 140%
h1 a
color: #ffffff

View file

@ -13,5 +13,6 @@ div
&.flashMsg
background-color: green
color: white
margin-bottom: 20px
&.flashError
background-color: red

View file

@ -80,7 +80,7 @@ class UsersController < ApplicationController
def login
return unless request.post?
if u = User.authenticate(params[:login][:username], params[:login][:password])
if u = User.authenticate(params[:login][:username].downcase, params[:login][:password])
raise Error, t(:accounts_locked) if u.banned? Ban::TYPE_SITE
flash[:notice] = t(:login_successful)

View file

@ -258,8 +258,8 @@ class User < ActiveRecord::Base
cuser and cuser.admin?
end
def self.authenticate username, password
User.first :conditions => {:username => username, :password => Digest::MD5.hexdigest(password)}
def self.authenticate(username, password)
where("LOWER(username) = LOWER(?)", username).where(:password => Digest::MD5.hexdigest(password)).first
end
def self.get id

View file

@ -1,7 +1,7 @@
<div id="indexBanner">
<div id="indexLinks">
<% if cuser %>
<span>Logged in as: <%= namelink cuser %></span> |
<span><%= t('login_status') %>: <%= namelink(cuser) %></span> |
<% end %>
<% if cuser and cuser.admin? %>
<%= link_to "/about/adminpanel", :style => "color: #CC0000" do %>

View file

@ -39,7 +39,7 @@
</div>
<div class="indexBox">
<div class="header">Shoutbox & Match search</div>
<div class="header"><%= t('widget.shoutbox') %></div>
<div class="body">
<div class="content">
<%= render :partial => "widgets/shoutbox" %>

View file

@ -1,4 +1,4 @@
<div class="header">Match Schedule</div>
<div class="header"><%= t('widget.schedule') %></div>
<div class="widget-content-wrapper">
<% upcoming_matches.group_by{ |e| e.start.month }.each do |month, events| %>
@ -13,4 +13,3 @@
<% end %>
<% end %>
</div>

View file

@ -1,4 +1,4 @@
<div class="header">Highlights</div>
<div class="header"><%= t('widget.highlights') %></div>
<div class="body">
<div class="content">

View file

@ -1,4 +1,4 @@
<div class="header">Latest Posts</div>
<div class="header"><%= t('widget.posts') %></div>
<div class="body">
<div class="content">
<h3>
@ -7,7 +7,7 @@
<ol>
<% Topic.basic.recent.latest_page(1).each do |topic| %>
<li>
<%= link_to shorten(topic, 30), lastpost(topic) %>
<%= link_to shorten(topic, 35), lastpost(topic) %>
</li>
<% end %>
</ol>
@ -19,7 +19,7 @@
<% Comment.recent.filtered.each do |comment| %>
<li>
<%= namelink comment.commentable, 15 %>
by <%= namelink comment.user, 8 %>
by <%= namelink comment.user, 15 %>
</li>
<% end %>
</ol>

View file

@ -74,6 +74,7 @@ en:
login_successful: "Login Successful"
login_unsuccessful: "Login Unsuccessful"
login_out: "Logged out."
login_status: "Logged in as"
passwords_sent: "Password has been sent."
incorrect_information: "Incorrect Information."
weeks_create: "Week was successfully created."
@ -81,6 +82,11 @@ en:
votes_success: "Voted successfully."
error: "error"
prohibited: "prohibited"
widget:
schedule: "Match Schedule"
shoutbox: "Shoutbox & Match search"
highlights: "Highlights"
posts: "Latest Posts"
profile:
locals: "Locals"
sessions:

View file

@ -0,0 +1,34 @@
require 'spec_helper'
feature 'Case insensitive login' do
let(:username) { "CaSe_InSeNsItIvE" }
let(:password) { "passwordABC123" }
let!(:user) { create(:user, username: username, raw_password: password) }
before do
visit root_path
end
feature 'when a user with mixed-case username signs in' do
scenario 'with a matching case allows the user to sign in' do
fill_login_form(username)
click_button submit(:user, :login)
expect(page).to have_content(I18n.t('login_successful'))
expect(page).to have_content("Logged in as: #{username}")
end
scenario 'with a non-matching case allows the user to sign in' do
fill_login_form("CASE_INSENSITIVE")
click_button submit(:user, :login)
expect(page).to have_content(I18n.t('login_successful'))
expect(page).to have_content("Logged in as: #{username}")
end
end
def fill_login_form(username)
fill_in "login_username", with: username
fill_in "login_password", with: password
end
end