mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 16:42:46 +08:00
Merge pull request #1247 from sir-pinecone/strip-spaces-from-login
Strip leading/trailing spaces from login
This commit is contained in:
commit
cb5ce3aab9
|
@ -9,7 +9,7 @@ class SessionController < ApplicationController
|
|||
params.require(:login)
|
||||
params.require(:password)
|
||||
|
||||
login = params[:login]
|
||||
login = params[:login].strip
|
||||
login = login[1..-1] if login[0] == "@"
|
||||
|
||||
if login =~ /@/
|
||||
|
|
|
@ -13,7 +13,7 @@ describe SessionController do
|
|||
end
|
||||
|
||||
it "raises an error when the login isn't present" do
|
||||
lambda { xhr :post, :create }.should raise_error(ActionController::ParameterMissing)
|
||||
lambda { xhr :post, :create }.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
describe 'invalid password' do
|
||||
|
@ -72,6 +72,21 @@ describe SessionController do
|
|||
end
|
||||
end
|
||||
|
||||
context 'login has leading and trailing space' do
|
||||
let(:username) { " #{user.username} " }
|
||||
let(:email) { " #{user.email} " }
|
||||
|
||||
it "strips spaces from the username" do
|
||||
xhr :post, :create, login: username, password: 'myawesomepassword'
|
||||
::JSON.parse(response.body)['error'].should_not be_present
|
||||
end
|
||||
|
||||
it "strips spaces from the email" do
|
||||
xhr :post, :create, login: email, password: 'myawesomepassword'
|
||||
::JSON.parse(response.body)['error'].should_not be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe "when the site requires approval of users" do
|
||||
before do
|
||||
SiteSetting.expects(:must_approve_users?).returns(true)
|
||||
|
|
Loading…
Reference in New Issue
Block a user