-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into select-claim-school-form
- Loading branch information
Showing
18 changed files
with
380 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
class EmailAddressForm < Form | ||
attribute :email_address | ||
|
||
validates :email_address, | ||
presence: { | ||
message: ->(form, _) { form.i18n_errors_path("presence") } | ||
} | ||
validates :email_address, | ||
format: { | ||
with: Rails.application.config.email_regexp, | ||
message: ->(form, _) { form.i18n_errors_path("format") } | ||
}, | ||
length: { | ||
maximum: 256, | ||
message: ->(form, _) { form.i18n_errors_path("length") } | ||
}, | ||
if: -> { email_address.present? } | ||
|
||
def save | ||
return false unless valid? | ||
return true unless email_address_changed? | ||
|
||
update!( | ||
email_address: email_address, | ||
email_verified: email_verified, | ||
sent_one_time_password_at: Time.now | ||
) | ||
|
||
ClaimMailer.email_verification(claim, otp_code).deliver_now | ||
end | ||
|
||
private | ||
|
||
def email_address_changed? | ||
email_address != claim.email_address | ||
end | ||
|
||
def email_verified | ||
return nil if email_address_changed? | ||
claim.email_verified | ||
end | ||
|
||
def otp_code | ||
@otp_code ||= OneTimePassword::Generator.new.code | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class EmailVerificationForm < Form | ||
attribute :one_time_password | ||
|
||
# Required for shared partial in the view | ||
delegate :email_address, to: :claim | ||
|
||
validate :otp_validate | ||
|
||
before_validation do | ||
self.one_time_password = one_time_password.gsub(/\D/, "") | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
update!(email_verified: true) | ||
end | ||
|
||
private | ||
|
||
def otp_validate | ||
otp = OneTimePassword::Validator.new( | ||
one_time_password, | ||
claim.sent_one_time_password_at | ||
) | ||
|
||
errors.add(:one_time_password, otp.warning) unless otp.valid? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class Claim < ApplicationRecord | ||
include ::OneTimePasswordCheckable | ||
|
||
MIN_QA_THRESHOLD = 10 | ||
TRN_LENGTH = 7 | ||
NO_STUDENT_LOAN = "not_applicable" | ||
|
@@ -91,7 +89,6 @@ class Claim < ApplicationRecord | |
one_time_password: true, | ||
sent_one_time_password_at: false, | ||
mobile_verified: false, | ||
one_time_password_category: false, | ||
assigned_to_id: true, | ||
policy_options_provided: false, | ||
held: false, | ||
|
@@ -165,9 +162,7 @@ class Claim < ApplicationRecord | |
validates :student_loan_plan, on: [:"student-loan", :amendment], presence: {message: "Enter a valid student loan plan"} | ||
|
||
# TODO: remove when a form object is created for email-address | ||
validates :email_address, on: [:"email-address", :submit], presence: {message: "Enter an email address"} | ||
validates :email_address, format: {with: Rails.application.config.email_regexp, message: "Enter an email address in the correct format, like [email protected]"}, | ||
length: {maximum: 256, message: "Email address must be 256 characters or less"}, if: -> { email_address.present? } | ||
validates :email_address, on: [:submit], presence: {message: "Enter an email address"} | ||
|
||
validates :bank_sort_code, on: [:submit, :amendment], presence: {message: "Enter a sort code"} | ||
validates :bank_account_number, on: [:submit, :amendment], presence: {message: "Enter an account number"} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
class Reminder < ApplicationRecord | ||
include ::OneTimePasswordCheckable | ||
|
||
attribute :sent_one_time_password_at, :datetime | ||
attribute :one_time_password, :string, limit: 6 | ||
|
||
validates :full_name, on: [:"personal-details"], presence: {message: "Enter full name"} | ||
validates :full_name, length: {maximum: 100, message: "Full name must be 100 characters or less"} | ||
|
@@ -10,6 +9,10 @@ class Reminder < ApplicationRecord | |
validates :email_address, format: {with: Rails.application.config.email_regexp, message: "Enter an email address in the correct format, like [email protected]"}, | ||
length: {maximum: 256, message: "Email address must be 256 characters or less"}, if: -> { email_address.present? } | ||
|
||
validate :otp_validate, on: [:"email-verification"] | ||
|
||
before_save :normalise_one_time_password, if: :one_time_password_changed? | ||
|
||
scope :email_verified, -> { where(email_verified: true) } | ||
scope :not_yet_sent, -> { where(email_sent_at: nil) } | ||
scope :inside_academic_year, -> { where(itt_academic_year: AcademicYear.current.to_s) } | ||
|
@@ -36,4 +39,18 @@ def itt_academic_year | |
def add_invalid_email_error(msg) | ||
errors.add(:email_address, :invalid, message: msg) | ||
end | ||
|
||
def normalise_one_time_password | ||
self.one_time_password = one_time_password.gsub(/\D/, "") | ||
end | ||
|
||
def otp_validate | ||
return write_attribute(:email_verified, true) if otp.valid? | ||
|
||
errors.add(:one_time_password, otp.warning) | ||
end | ||
|
||
def otp | ||
@otp ||= OneTimePassword::Validator.new(one_time_password, sent_one_time_password_at) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
<% content_for(:page_title, page_title(t("questions.email_address"), journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %> | ||
<% content_for( | ||
:page_title, | ||
page_title( | ||
t("questions.email_address"), | ||
journey: current_journey_routing_name, | ||
show_error: @form.errors.any? | ||
) | ||
) %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= render("shared/error_summary", instance: current_claim) if current_claim.errors.any? %> | ||
<%= render("shared/error_summary", instance: @form) if @form.errors.any? %> | ||
|
||
<%= form_for current_claim, url: claim_path(current_journey_routing_name), html: { novalidate: false } do |form| %> | ||
<%= personal_details_caption(current_claim) %> | ||
<%= form_group_tag current_claim do %> | ||
<%= form_for @form, url: claim_path(current_journey_routing_name), html: { novalidate: false } do |f| %> | ||
<%= personal_details_caption(f.object.claim) %> | ||
<%= form_group_tag f.object do %> | ||
<h1 class="govuk-label-wrapper"> | ||
<%= form.label :email_address, t("questions.email_address"), class: "govuk-label #{label_css_class_for_journey(journey)}" %> | ||
<%= f.label :email_address, t("questions.email_address"), class: "govuk-label #{label_css_class_for_journey(f.object.journey)}" %> | ||
</h1> | ||
|
||
<%= email_govuk_hint(current_claim) %> | ||
<%= email_govuk_hint(f.object.claim) %> | ||
|
||
<%= errors_tag current_claim, :email_address %> | ||
<%= errors_tag f.object, :email_address %> | ||
|
||
<%= form.text_field :email_address, | ||
autocomplete: "email", | ||
spellcheck: "false", | ||
class: css_classes_for_input(current_claim, :email_address), | ||
"aria-describedby" => "email-address-hint" %> | ||
<%= f.text_field( | ||
:email_address, | ||
autocomplete: "email", | ||
spellcheck: "false", | ||
class: css_classes_for_input(f.object, :email_address), | ||
"aria-describedby" => "email-address-hint" | ||
) %> | ||
<% end %> | ||
<%= render "help_with_access_codes", communication_type: "Email" %> | ||
<%= form.submit "Continue", class: "govuk-button" %> | ||
<%= f.submit "Continue", class: "govuk-button" %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
<% content_for(:page_title, page_title(t("one_time_password.title"), journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %> | ||
<% content_for( | ||
:page_title, | ||
page_title( | ||
t("one_time_password.title"), | ||
journey: current_journey_routing_name, | ||
show_error: @form.errors.any? | ||
) | ||
) %> | ||
|
||
<%= render partial: "one_time_password", locals: {current_claim: current_claim, current_journey_routing_name: current_journey_routing_name, email_or_mobile: "email", email_or_text_message: "an email"} %> | ||
<%= render( | ||
partial: "one_time_password", | ||
locals: { | ||
current_claim: @form, | ||
current_journey_routing_name: current_journey_routing_name, | ||
email_or_mobile: "email", | ||
email_or_text_message: "an email" | ||
} | ||
) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,6 +265,11 @@ en: | |
select_the_school_you_teach_at: "Select the school you teach at" | ||
the_selected_school_is_closed: "The selected school is closed" | ||
school_not_found: "School not found" | ||
email_address: | ||
errors: | ||
presence: "Enter an email address" | ||
format: "Enter an email address in the correct format, like [email protected]" | ||
length: "Email address must be 256 characters or less" | ||
leadership_position: | ||
questions: | ||
leadership_position: "Were you employed in a leadership position between %{financial_year}?" | ||
|
@@ -403,6 +408,11 @@ en: | |
select_the_school_you_teach_at: "Select the school you teach at" | ||
the_selected_school_is_closed: "The selected school is closed" | ||
school_not_found: "School not found" | ||
email_address: | ||
errors: | ||
presence: "Enter an email address" | ||
format: "Enter an email address in the correct format, like [email protected]" | ||
length: "Email address must be 256 characters or less" | ||
mobile_number: | ||
errors: | ||
invalid: "Enter a mobile number, like 07700 900 982 or +44 7700 900 982" | ||
|
Oops, something went wrong.