Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.
Merged
4 changes: 3 additions & 1 deletion app/views/stormpath/rails/forgot_password/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
<% end %>
</div>
</div>
<%= link_to "Back to Log In", new_login_path, class: "forgot" %>
<% if Stormpath::Rails.config.web.login.enabled %>
<%= link_to "Back to Log In", new_login_path, class: "forgot" %>
<% end %>
</div>
</div>
</div>
7 changes: 6 additions & 1 deletion app/views/stormpath/rails/login/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
<% case params[:status] %>
<% when 'unverified' %>
<div class="alert alert-success">
<p>Your account verification email has been sent! Before you can log into your account, you need to activate your account by clicking the link we sent to your inbox. Didn't get the email? <%= link_to "Click Here", Stormpath::Rails.config.web.verify_email.uri %></p>
<% if Stormpath::Rails.config.web.verify_email.enabled %>
<p>
Your account verification email has been sent! Before you can log into your account, you need to activate your account by clicking the link we sent to your inbox. Didn't get the email?
<%= link_to "Click Here", new_verify_email_path %>
</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a _path helper, don't use the config uri directly.

<% end %>
</div>
<% when 'verified' %>
<div class="alert alert-success">
Expand Down
2 changes: 1 addition & 1 deletion app/views/stormpath/rails/register/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<%= render 'stormpath/rails/shared/input', form: form, input_config: Stormpath::Rails.config.web.register.form.fields.send(field), input_name: field.to_s.camelize(:lower), value: params[field.to_s.camelize(:lower)] %>
<% end %>

<%= button_tag "Create Account", :class => "btn btn-register btn-sp-green", :type => "submit" %>
<%= button_tag "Create Account", class: "btn btn-register btn-sp-green", type: "submit" %>
<% end %>
</div>
4 changes: 3 additions & 1 deletion app/views/stormpath/rails/register/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<div class="box row">
<%= render partial: 'stormpath/rails/register/form' %>
</div>
<%= link_to "Back to Log In", new_login_path, class: "to-login" %>
<% if Stormpath::Rails.config.web.login.enabled %>
<%= link_to "Back to Log In", new_login_path, class: "to-login" %>
<% end %>
</div>
</div>
</div>
4 changes: 3 additions & 1 deletion app/views/stormpath/rails/verify_email/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
<% end %>
</div>
</div>
<%= link_to "Back to Log In", new_login_path, class: "forgot" %>
<% if Stormpath::Rails.config.web.login.enabled %>
<%= link_to "Back to Log In", new_login_path, class: "forgot" %>
<% end %>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions lib/stormpath/rails/config/dynamic_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,23 @@ def change_password_enabled?
password_reset_enabled?
end

def verify_email_enabled?
return false if static_config.stormpath.web.verify_email.enabled == false
email_verification_enabled?
end

private

def password_reset_enabled?
return false if default_account_store.nil?
default_account_store.password_policy.reset_email_status == 'ENABLED'
end

def email_verification_enabled?
return false if default_account_store.nil?
default_account_store.account_creation_policy.verification_email_status == 'ENABLED'
end

def default_account_store
@default_account_store ||=
app.default_account_store_mapping && app.default_account_store_mapping.account_store
Expand Down
1 change: 1 addition & 0 deletions lib/stormpath/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def config_object
config.stormpath.application.href = dynamic_config.app.href
config.stormpath.web.forgot_password.enabled = dynamic_config.forgot_password_enabled?
config.stormpath.web.change_password.enabled = dynamic_config.change_password_enabled?
config.stormpath.web.verify_email.enabled = dynamic_config.verify_email_enabled?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/stormpath/rails/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def stormpath_rails_routes(actions: {})

# VERIFY EMAIL
if Stormpath::Rails.config.web.verify_email.enabled
get Stormpath::Rails.config.web.verify_email.uri => actions['verify_email#show']
get Stormpath::Rails.config.web.verify_email.uri => actions['verify_email#show'], as: :new_verify_email
post Stormpath::Rails.config.web.verify_email.uri => actions['verify_email#create'], as: :verify_email
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
username { Faker::Internet.user_name }
end

factory :account_without_username, class: Stormpath::Resource::Account do
sequence(:email) { |n| "dev#{n}@example.com" }
password 'Password1337'
given_name { Faker::Name.first_name }
surname { Faker::Name.last_name }
end

factory :unverified_account, parent: :account do
status 'UNVERIFIED'
end
Expand Down
11 changes: 11 additions & 0 deletions spec/features/email_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
folder."
)
end

it 'does not blow up with wrong path helpers when login is disabled' do
allow(configuration.web.login).to receive(:enabled).and_return(false)

Rails.application.reload_routes!

visit 'verify'

expect(page.status_code).to eq(200)
expect(page).not_to have_content('Back to Log In')
end
end

describe 'with invalid sptoken' do
Expand Down
12 changes: 12 additions & 0 deletions spec/features/forgot_password_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

let(:account_attrs) { FactoryGirl.attributes_for(:account) }

before { Rails.application.reload_routes! }
after { account.delete }

describe 'GET /forgot' do
Expand All @@ -19,6 +20,17 @@
visit 'forgot'
expect(find_field('email')['placeholder']).to eq('Email')
end

it 'should render the page when login is disabled' do
allow(configuration.web.login).to receive(:enabled).and_return(false)

Rails.application.reload_routes!

visit 'forgot'
expect(page.status_code).to eq(200)
expect(page).to have_content('Submit')
expect(page).not_to have_content('Back to Log In')
end
end

describe 'POST /forgot' do
Expand Down
23 changes: 23 additions & 0 deletions spec/features/login_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@
expect(page).to have_content('Log in')
end

it 'does not blow up with wrong path helpers when forgot_password is disabled' do
allow(configuration.web.forgot_password).to receive(:enabled).and_return(false)

Rails.application.reload_routes!

visit 'login'

expect(page.status_code).to eq(200)
expect(page).to have_content('Log in')
end

it 'does not blow up with wrong path helpers when verify_email is disabled' do
allow(configuration.web.verify_email).to receive(:enabled).and_return(false)

Rails.application.reload_routes!

visit 'login'

expect(page.status_code).to eq(200)
expect(page).not_to have_content('Click Here')
expect(page).to have_content('Log in')
end

xit 'shows social logins when needed' do
end

Expand Down
15 changes: 15 additions & 0 deletions spec/features/register_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
type: 'text'
)
reload_form_class
Rails.application.reload_routes!
end

after do
Expand Down Expand Up @@ -47,6 +48,17 @@
expect(find_field('password')['placeholder']).to eq('Password')
expect(find_field('confirmPassword')['placeholder']).to eq('Confirm Password')
end

it 'should render the page when login is disabled' do
allow(configuration.web.login).to receive(:enabled).and_return(false)

Rails.application.reload_routes!

visit 'register'
expect(page.status_code).to eq(200)
expect(page).to have_content('Create Account')
expect(page).not_to have_content('Back to Log In')
end
end

describe 'POST /register' do
Expand Down Expand Up @@ -126,6 +138,9 @@ def delete_test_account
end

it 'creates an account and redirects to login with status UNVERIFIED' do
allow(configuration.web.verify_email).to receive(:enabled).and_return(true)
Rails.application.reload_routes!

visit 'register'

fill_in 'givenName', with: 'Damir'
Expand Down
Loading