File tree Expand file tree Collapse file tree 6 files changed +25
-10
lines changed Expand file tree Collapse file tree 6 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -35,13 +35,13 @@ def show
35
35
protected
36
36
37
37
def set_user
38
- # 处理 login 有大写字母的情况
39
- if params [ :id ] != params [ :id ] . downcase
40
- redirect_to request . path . downcase , status : 301
41
- return
38
+ @user = User . find_login! ( params [ :id ] )
39
+
40
+ # 转向正确的拼写
41
+ if @user . login != params [ :id ]
42
+ redirect_to user_path ( @user . login ) , status : 301
42
43
end
43
44
44
- @user = User . find_login! ( params [ :id ] )
45
45
@user_type = @user . user_type
46
46
if @user . deleted?
47
47
render_404
Original file line number Diff line number Diff line change @@ -212,13 +212,12 @@ def self.find_login!(slug)
212
212
213
213
def self . find_login ( slug )
214
214
return nil unless slug =~ ALLOW_LOGIN_CHARS_REGEXP
215
- slug = slug . downcase
216
- fetch_by_uniq_keys ( login : slug )
215
+ fetch_by_uniq_keys ( login : slug ) || where ( "lower(login) = ?" , slug . downcase ) . take
217
216
end
218
217
219
218
def self . find_by_login_or_email ( login_or_email )
220
219
login_or_email = login_or_email . downcase
221
- fetch_by_uniq_keys ( login : login_or_email ) || fetch_by_uniq_keys ( email : login_or_email )
220
+ find_login ( login_or_email ) || find_by_email ( login_or_email )
222
221
end
223
222
224
223
def self . find_for_database_authentication ( warden_conditions )
Original file line number Diff line number Diff line change 28
28
# Configure which authentication keys should be case-insensitive.
29
29
# These keys will be downcased upon creating or modifying a user and when used
30
30
# to authenticate or find a user. Default is :email.
31
- config . case_insensitive_keys = [ :email , :login ]
31
+ config . case_insensitive_keys = [ :email ]
32
32
33
33
# Configure which authentication keys should have whitespace stripped.
34
34
# These keys will have whitespace before and after removed upon creating or
Original file line number Diff line number Diff line change 186
186
get 'users/city/:id' => 'users#city' , as : 'location_users'
187
187
get 'users' => 'users#index' , as : 'users'
188
188
189
- constraints ( id : /[\w \- \. ]*/ ) do
189
+ constraints ( id : /[a-zA-Z0-9 \_ \- \. ]*/ ) do
190
190
resources :users , path : '' , as : 'users' do
191
191
member do
192
192
# User only
Original file line number Diff line number Diff line change 34
34
get :topics , params : { id : user . login }
35
35
expect ( response ) . to be_success
36
36
end
37
+
38
+ it 'should redirect to right spell login' do
39
+ get :topics , params : { id : user . login . upcase }
40
+ expect ( response . status ) . to eq ( 301 )
41
+ end
37
42
end
38
43
39
44
describe ':replies' do
Original file line number Diff line number Diff line change 66
66
let ( :user ) { build ( :user , login : 'aaa*11' ) }
67
67
it { expect ( user . valid? ) . to eq false }
68
68
end
69
+
70
+ describe 'Login allow upcase downcase both' do
71
+ let ( :user1 ) { create ( :user , login : 'ReiIs123' ) }
72
+
73
+ it 'should work' do
74
+ expect ( user1 . login ) . to eq ( 'ReiIs123' )
75
+ expect ( User . find_login ( 'ReiIs123' ) . id ) . to eq ( user1 . id )
76
+ expect ( User . find_login ( 'reiis123' ) . id ) . to eq ( user1 . id )
77
+ expect ( User . find_login ( 'rEIIs123' ) . id ) . to eq ( user1 . id )
78
+ end
79
+ end
69
80
end
70
81
71
82
describe '#read_topic?' do
You can’t perform that action at this time.
0 commit comments