Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app-rails/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def after_sign_in_path_for(resource)
return users_mfa_preference_path
end

if resource.employer?
return dev_sandbox_path
end

users_account_path
end
end
13 changes: 4 additions & 9 deletions app-rails/app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ class Users::RegistrationsController < ApplicationController
layout "users"
skip_after_action :verify_authorized

def new_applicant
@form = Users::RegistrationForm.new(role: "applicant")
render :new
end

def new_employer
@form = Users::RegistrationForm.new(role: "employer")
def new
@form = Users::RegistrationForm.new()
render :new
end

Expand All @@ -23,7 +18,7 @@ def create
end

begin
auth_service.register(@form.email, @form.password, @form.role)
auth_service.register(@form.email, @form.password)
rescue Auth::Errors::BaseAuthError => e
flash.now[:errors] = [ e.message ]
return render :new, status: :unprocessable_entity
Expand Down Expand Up @@ -77,7 +72,7 @@ def auth_service
end

def registration_params
params.require(:users_registration_form).permit(:email, :password, :password_confirmation, :role, :spam_trap)
params.require(:users_registration_form).permit(:email, :password, :password_confirmation, :spam_trap)
end

def verify_account_params
Expand Down
4 changes: 2 additions & 2 deletions app-rails/app/forms/users/registration_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
class Users::RegistrationForm
include ActiveModel::Model

attr_accessor :email, :password, :password_confirmation, :role, :spam_trap
attr_accessor :email, :password, :password_confirmation, :spam_trap

validates :email, :password, :role, presence: true
validates :email, :password, presence: true
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, if: -> { email.present? }

validates :password, confirmation: true, if: -> { password.present? }
Expand Down
12 changes: 0 additions & 12 deletions app-rails/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,11 @@ class User < ApplicationRecord

# == Relationships ========================================================
has_many :tasks
has_one :user_role, dependent: :destroy

# == Validations ==========================================================
validates :provider, presence: true

# == Methods ==============================================================
def applicant?
user_role&.applicant?
end

def employer?
user_role&.employer?
end

def superadmin?
email.include?("+admin")
end

# Check if the access token is expired or will expire within the next `minutes` minutes.
# Access token is only stored in the session, so it needs passed in, rather than accessed from the model.
Expand Down
8 changes: 0 additions & 8 deletions app-rails/app/models/user_role.rb

This file was deleted.

9 changes: 4 additions & 5 deletions app-rails/app/services/auth_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def respond_to_auth_challenge(code, challenge = {})
handle_auth_result(response, challenge[:email])
end

def register(email, password, role)
def register(email, password)
# @TODO: Handle errors from the auth service, like when the email is already taken
# See https://github.com/navapbc/template-application-rails/issues/15
account = @auth_adapter.create_account(email, password)

create_db_user(account[:uid], email, account[:provider], role)
create_db_user(account[:uid], email, account[:provider])
end

# Verify the code sent to the user as part of their initial sign up process.
Expand Down Expand Up @@ -72,15 +72,14 @@ def disable_software_token(user)

private

def create_db_user(uid, email, provider, role = "applicant")
Rails.logger.info "Creating User uid: #{uid}, and UserRole: #{role}"
def create_db_user(uid, email, provider)
Rails.logger.info "Creating User uid: #{uid}"

user = User.create!(
uid: uid,
email: email,
provider: provider,
)
user_role = UserRole.create!(user: user, role: role)
user
end

Expand Down
71 changes: 8 additions & 63 deletions app-rails/app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,11 @@
<p class="usa-intro">
<%= t('.intro') %>
</p>

<div class="grid-row">
<ul class="usa-card-group">
<li class="usa-card grid-col-12 mobile-lg:grid-col-6">
<div class="usa-card__container">
<div class="usa-card__header">
<h2 class="usa-card__heading">
<%= t('.applicant_heading') %>
</h2>
</div>
<div class="usa-card__media">
<div class="usa-card__img">
<%= image_tag 'applicant.jpg', alt: "Man with two younger children" %>
</div>
</div>
<div class="usa-card__body">
<p>
<%= t('.applicant_body') %>
</p>
</div>
<div class="usa-card__footer">
<a href="<%= users_new_applicant_registration_path %>" class="usa-button">
<%= t('.applicant_signup') %>
</a>
<p>
<a class="usa-link" href="<%= new_user_session_path %>">
<%= t('.or_sign_in') %>
</a>
</p>
</div>
</div>
</li>
<li class="usa-card grid-col-12 mobile-lg:grid-col-6">
<div class="usa-card__container">
<div class="usa-card__header">
<h2 class="usa-card__heading">
<%= t('.employer_heading') %>
</h2>
</div>
<div class="usa-card__media">
<div class="usa-card__img">
<%= image_tag 'employer.jpg', alt: "Person at a desk using a laptop" %>
</div>
</div>
<div class="usa-card__body">
<p>
<%= t('.employer_body') %>
</p>
</div>
<div class="usa-card__footer">
<a href="<%= users_new_employer_registration_path %>" class="usa-button">
<%= t('.employer_signup') %>
</a>
<p>
<a class="usa-link" href="<%= new_user_session_path %>">
<%= t('.or_sign_in') %>
</a>
</p>
</div>
</div>
</li>
</ul>
</div>
<a href="<%= users_new_registration_path %>" class="usa-button">
<%= t('.signup') %>
</a>
<p>
<a class="usa-link" href="<%= new_user_session_path %>">
<%= t('.or_sign_in') %>
</a>
</p>
35 changes: 5 additions & 30 deletions app-rails/app/views/users/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<% content_for :title, t(".title_#{@form.role}") %>
<% icon = @form.role == "applicant" ? "local_library" : "local_library" %>
<% icon_color = @form.role == "applicant" ? "violet" : "mint" %>
<% content_for :title, t(".title") %>
<% icon = "local_library" %>
<% icon_color = "violet" %>

<div class="bg-white padding-top-3 padding-bottom-5 padding-x-5 border border-base-lighter">
<div class="text-center margin-bottom-2 padding-bottom-2 border-bottom border-base-lighter">
<svg class="usa-icon usa-icon--size-6 text-<%= icon_color %>" aria-hidden="true" focusable="false" role="img">
<use xlink:href="<%= asset_path "@uswds/uswds/dist/img/sprite.svg##{icon}" %>"></use>
</svg>

<h1 class="font-heading-xl margin-y-0"><%= t(".title_#{@form.role}") %></h1>
<h1 class="font-heading-xl margin-y-0"><%= t(".title") %></h1>
</div>

<%= us_form_with model: @form, url: users_registrations_path, local: true do |f| %>
<%= f.hidden_field :role %>
<%= f.honeypot_field %>
<%= f.email_field :email %>

Expand All @@ -29,7 +28,7 @@

<%= f.password_field :password_confirmation, autocomplete: "new-password", id: "new-password-confirmation" %>

<%= f.submit t(".title_#{@form.role}") %>
<%= f.submit t(".title") %>
<% end %>
</div>

Expand All @@ -39,27 +38,3 @@
<%= t ".login" %>
</a>
</p>

<%= content_for :sidebar do %>
<% if @form.role == "applicant" %>
<h2 class="font-heading-lg"><%= t('.are_employer_heading') %></h2>
<div class="usa-prose">
<p><%= t('.are_employer_body') %></p>
<p>
<a class="usa-button usa-button--outline" href="<%= users_new_employer_registration_path %>">
<%= t('.are_employer_action') %>
</a>
</p>
</div>
<% else %>
<h2 class="font-heading-lg"><%= t('.are_applicant_heading') %></h2>
<div class="usa-prose">
<p><%= t('.are_applicant_body') %></p>
<p>
<a class="usa-button usa-button--outline" href="<%= users_new_applicant_registration_path %>">
<%= t('.are_applicant_action') %>
</a>
</p>
</div>
<% end %>
<% end %>
4 changes: 2 additions & 2 deletions app-rails/app/views/users/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<p class="text-center">
<%= t('.no_account') %>
<a class="usa-link" href="<%= url_for users_new_applicant_registration_path %>">
<a class="usa-link" href="<%= url_for users_new_registration_path %>">
<%= t('.create_account') %>
</a>.
</p>
</p>
11 changes: 4 additions & 7 deletions app-rails/config/locales/views/home/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ en:
home:
index:
title: "Get started"
intro: "You can either apply for benefits or manage applications for an organization. If you need to do both, you will need to create separate accounts."
applicant_heading: "Applicants"
applicant_body: "I am applying for benefits."
applicant_signup: "Create an Applicant account"
employer_heading: "Employers"
employer_body: "I manage applications for my organization."
employer_signup: "Create an Employer account"
intro: "Create an account to use this application."
heading: "Users"
body: "I am using this website."
signup: "Create an account"
or_sign_in: "Or sign into an existing account"
9 changes: 1 addition & 8 deletions app-rails/config/locales/views/users/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,9 @@ en:
submit: "Submit"
registrations:
new:
are_applicant_heading: "Are you applying for benefits?"
are_applicant_body: "To apply for benefits, create an applicant account."
are_applicant_action: "Create an Applicant account"
are_employer_heading: "Are you an employer?"
are_employer_body: "To manage applications for an organization, create an employer account."
are_employer_action: "Create an Employer account"
have_existing_account: "Already have an account?"
login: "Log in"
title_applicant: "Create an Applicant account"
title_employer: "Create an Employer account"
title: "Create an account"
new_account_verification:
title: "Verify your email address"
instructions: "We sent a 6 digit verification code to your email. Enter the code to verify your email."
Expand Down
3 changes: 1 addition & 2 deletions app-rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
# Registration and account management
namespace :users do
resources :registrations, only: [ :create ]
get "registrations/applicant" => "registrations#new_applicant", as: :new_applicant_registration
get "registrations/employer" => "registrations#new_employer", as: :new_employer_registration
get "registrations" => "registrations#new", as: :new_registration

resources :mfa, only: [ :new, :create ]
get "mfa/preference" => "mfa#preference", as: :mfa_preference
Expand Down
30 changes: 8 additions & 22 deletions app-rails/spec/controllers/users/registrations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,11 @@
)
end

describe "GET new_applicant" do
it "renders with applicant content and role" do
get :new_applicant, params: { locale: "en" }
describe "GET new" do
it "renders" do
get :new, params: { locale: "en" }

expect(response.body).to have_selector("h1", text: /create an applicant account/i)
expect(response.body).to have_field("users_registration_form[role]", with: "applicant", type: :hidden)
end
end

describe "GET new_employer" do
it "renders with employer content and role" do
get :new_employer, params: { locale: "en" }

expect(response.body).to have_selector("h1", text: /create an employer account/i)
expect(response.body).to have_field("users_registration_form[role]", with: "employer", type: :hidden)
expect(response.body).to have_selector("h1", text: /create an account/i)
end
end

Expand All @@ -34,24 +24,21 @@
post :create, params: {
users_registration_form: {
email: email,
password: "password",
role: "employer"
password: "password"
},
locale: "en"
}
user = User.find_by(email: email)

expect(user).to be_present
expect(user.employer?).to be(true)
expect(response).to redirect_to(users_verify_account_path)
end

it "validates email" do
post :create, params: {
users_registration_form: {
email: "invalid",
password: "password",
role: "employer"
password: "password"
},
locale: "en"
}
Expand All @@ -63,8 +50,7 @@
post :create, params: {
users_registration_form: {
email: "UsernameExists@example.com",
password: "password",
role: "employer"
password: "password"
},
locale: "en"
}
Expand All @@ -79,7 +65,7 @@
users_registration_form: {
email: email,
password: "password",
role: "employer",

spam_trap: "I am a bot"
},
locale: "en"
Expand Down
Loading
Loading