Commit 610e35523c3a926bcfee3e4b8637fd028d6ab9bc
Committed by
Daniela Feitosa
1 parent
c1c0091d
Exists in
master
and in
29 other branches
[Stoa] login with USP Id
Showing
4 changed files
with
55 additions
and
3 deletions
Show diff stats
plugins/stoa/lib/stoa_plugin.rb
... | ... | @@ -42,6 +42,23 @@ class StoaPlugin < Noosfero::Plugin |
42 | 42 | } if context.profile.person? && context.profile.usp_id.blank? |
43 | 43 | end |
44 | 44 | |
45 | + def login_extra_contents | |
46 | + lambda { | |
47 | + content_tag('div', labelled_form_field(_('USP number / Username'), text_field_tag('usp_id_login', '', :id => 'stoa_field_login')) + | |
48 | + labelled_form_field(_('Password'), password_field_tag('password', '', :id => 'stoa_field_password')), :id => 'stoa-login-fields') | |
49 | + } | |
50 | + end | |
51 | + | |
52 | + def alternative_authentication | |
53 | + person = Person.find_by_usp_id(context.params[:usp_id_login]) | |
54 | + if person | |
55 | + user = User.authenticate(person.user.login, context.params[:password]) | |
56 | + else | |
57 | + user = User.authenticate(context.params[:usp_id_login], context.params[:password]) | |
58 | + end | |
59 | + user | |
60 | + end | |
61 | + | |
45 | 62 | def account_controller_filters |
46 | 63 | block = lambda do |
47 | 64 | params[:profile_data] ||= {} | ... | ... |
plugins/stoa/public/style.css
... | ... | @@ -64,3 +64,16 @@ |
64 | 64 | .controller-profile_editor div.checking { |
65 | 65 | background: transparent url(/images/loading-small.gif) 153px center no-repeat; |
66 | 66 | } |
67 | + | |
68 | +.login-box #main_user_login, | |
69 | +.login-box .formlabel[for=main_user_login], | |
70 | +.login-box #user_login, | |
71 | +.login-box .formlabel[for=user_login], | |
72 | +.login-box #user_password, | |
73 | +.login-box .formlabel[for=user_password] { | |
74 | + display:none; | |
75 | +} | |
76 | + | |
77 | +#stoa-login-fields{ | |
78 | + margin-top: -10px; | |
79 | +} | ... | ... |
plugins/stoa/test/functional/account_controller_test.rb
... | ... | @@ -24,6 +24,8 @@ class AccountControllerTest < ActionController::TestCase |
24 | 24 | ActiveRecord::Base.establish_connection(:test) |
25 | 25 | StoaPlugin::UspUser.create!(:codpes => 12345678, :cpf => Digest::MD5.hexdigest(SALT+'12345678'), :birth_date => '1970-01-30') |
26 | 26 | Environment.default.enable_plugin(StoaPlugin.name) |
27 | + @user = create_user('joao-stoa', {:password => 'pass', :password_confirmation => 'pass'},:usp_id=>'87654321') | |
28 | + @user.activate | |
27 | 29 | end |
28 | 30 | |
29 | 31 | def teardown |
... | ... | @@ -47,4 +49,21 @@ class AccountControllerTest < ActionController::TestCase |
47 | 49 | assert assigns(:person).invitation_code == '12345678' |
48 | 50 | end |
49 | 51 | |
52 | + should 'authenticate with usp id' do | |
53 | + post :login, :usp_id_login => '87654321', :password => 'pass' | |
54 | + assert session[:user] | |
55 | + assert_equal @user.login, assigns(:current_user).login | |
56 | + end | |
57 | + | |
58 | + should 'not authenticate with wrong password' do | |
59 | + post :login, :usp_id_login => '87654321', :password => 'pass123' | |
60 | + assert_nil session[:user] | |
61 | + end | |
62 | + | |
63 | + should 'authenticate with username' do | |
64 | + post :login, :usp_id_login => 'joao-stoa', :password => 'pass' | |
65 | + assert session[:user] | |
66 | + assert_equal @user.login, assigns(:current_user).login | |
67 | + end | |
68 | + | |
50 | 69 | end | ... | ... |
plugins/stoa/test/functional/profile_editor_controller_test.rb
... | ... | @@ -23,20 +23,23 @@ class StoaPluginProfileEditorControllerTest < ActionController::TestCase |
23 | 23 | |
24 | 24 | should 'show usp_id field if person did not filled it' do |
25 | 25 | get :edit, :profile => person.identifier |
26 | - assert_match /USP number/, @response.body | |
26 | + assert_tag_in_string @response.body, :tag => 'label', :content => /USP number/, :attributes => { :for => 'usp_id_field' } | |
27 | + assert_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'usp_id_field' } | |
27 | 28 | end |
28 | 29 | |
29 | 30 | should 'not show usp_id field if person already filled it' do |
30 | 31 | person.usp_id = 12345 |
31 | 32 | person.save |
32 | 33 | get :edit, :profile => person.identifier |
33 | - assert_no_match /USP number/, @response.body | |
34 | + assert_no_tag_in_string @response.body, :tag => 'label', :content => /USP number/, :attributes => { :for => 'usp_id_field' } | |
35 | + assert_no_tag_in_string @response.body, :tag => 'input', :attributes => { :id => 'usp_id_field' } | |
34 | 36 | end |
35 | 37 | |
36 | 38 | should 'not display field if profile is an organization' do |
37 | 39 | organization = fast_create(Organization) |
40 | + organization.add_admin @person | |
38 | 41 | get :edit, :profile => organization.identifier |
39 | - assert_no_match /USP number/, @response.body | |
42 | + assert_no_tag_in_string @response.body, :tag => 'label', :content => /USP number/, :attributes => { :for => 'usp_id_field' } | |
40 | 43 | end |
41 | 44 | |
42 | 45 | should 'display error if usp_id does not match with supplied confirmation' do | ... | ... |