Skip to content

MGF-544-page-de-confirmation-de-compte #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
1c90cec
feat(ruby version) : 3.2.1 --> 3.3.2
fitchMitch Sep 5, 2024
d74a3b5
feat(formal code update): automatic rubocop update mostly
fitchMitch Sep 5, 2024
dc38fad
feat(registration ui updates) : skin update + phone_token resend opti…
fitchMitch Sep 5, 2024
57ef049
fix(test): test + wording + rubocop formal updates
fitchMitch Sep 5, 2024
774ed7e
fix(system test): driver_option disables search engine choice
fitchMitch Sep 5, 2024
57d8267
fix(ci config): updating image cimg/ruby:3.2.1-browsers --> cimg/ruby…
fitchMitch Sep 5, 2024
caa12a7
fix(after functional review) : typos + welcome sms withdrawal
fitchMitch Sep 6, 2024
f9832c8
Merge branch 'review' into MGF-544-page-de-confirmation-de-compte
fitchMitch Dec 6, 2024
338ab8b
fix(new registration with confirmation process): missing check_phone…
fitchMitch Dec 7, 2024
ba5ceaa
fix(delivery): removing structure changes that do not belong to this …
fitchMitch Dec 9, 2024
eeb9997
feat(tests): missing tests for reactivation now added
fitchMitch Dec 9, 2024
7abd2cb
fix(tests): 12 rue taine file updated in its query string
fitchMitch Dec 9, 2024
818e12b
Merge branch 'review' into MGF-544-page-de-confirmation-de-compte
fitchMitch Dec 18, 2024
b672dca
Merge branch 'review' into MGF-544-page-de-confirmation-de-compte
fitchMitch Jan 6, 2025
95f1d1a
Merge branch 'review' into MGF-544-page-de-confirmation-de-compte
fitchMitch Jan 7, 2025
d9d20cd
Merge branch 'review' into MGF-544-page-de-confirmation-de-compte
fitchMitch Jan 7, 2025
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
9 changes: 5 additions & 4 deletions app/controllers/concerns/phonable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ def safe_phone_param
end

def clean_phone_param
params[:user][:phone] = (by_phone? && params[:as] == 'Student') ? safe_phone_param : nil
params[:user][:phone] = by_phone? && params[:as] == 'Student' ? safe_phone_param : nil
end

def fetch_user_by_phone
return nil if safe_phone_param.blank?

@user ||= User.where(phone: safe_phone_param).first
@user ||= User.find_by(phone: safe_phone_param)
end

def split_phone_parts(user)
return [nil, nil] if user.phone.blank?

sep = 2 if user.phone.size == 13 # France métropolitaine case (+33 case)
sep = 3 if user.phone.size == 14
user.phone_prefix, user.phone_suffix = user.phone[0..sep], user.phone[(sep+1)..-1]
user.phone_prefix = user.phone[0..sep]
user.phone_suffix = user.phone[(sep + 1)..-1]
end

def french_phone_number_format(phone_number_string)
phone_number_string.split("")
phone_number_string.split('')
.each_slice(2)
.to_a
.map(&:join)
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def create
)
return
elsif by_phone? && fetch_user_by_phone
fetch_user_by_phone.reset_password_by_phone
@user.reset_password_by_phone
redirect_to phone_edit_password_path(phone: safe_phone_param)
return
end

super
end

Expand All @@ -31,17 +31,16 @@ def update
current_user.password = params['user']['password']
current_user.save
current_user.confirm if current_user.confirmed_at.nil?
redirect_to new_user_session_path, flash: { success: 'Mot de passe enregistré !' }
redirect_to new_user_session_path, flash: { success: 'Mot de passe enregistré !' }
else
super
end
end

def edit_by_phone; end


def set_up
end
end

def update_by_phone
if fetch_user_by_phone.try(:check_phone_token?, params[:phone_token])
Expand Down
50 changes: 39 additions & 11 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ def create

def phone_validation
if fetch_user_by_phone.try(:check_phone_token?, params[:phone_token])
fetch_user_by_phone.confirm_by_phone!
@user.confirm_by_phone!
message = { success: I18n.t('devise.confirmations.confirmed') }
redirect_to(
new_user_session_path(phone: fetch_user_by_phone.phone),
new_user_session_path(phone: @user.phone),
flash: message
)
else
Expand All @@ -111,6 +111,32 @@ def phone_validation
def statistician_standby
end

def resend_confirmation_phone_token
user = User.find_by(id: users_params[:id])
flash_path = 'dashboard/internship_agreements/signature/flash_new_code'
if user && !user&.confirmed? && user.phone && user.resend_confirmation_phone_token
notice = 'Votre code a été renvoyé'
respond_to do |format|
format.turbo_stream do
render turbo_stream:
turbo_stream.replace('code-request',
partial: flash_path,
locals: { notice: })
end
end
else
alert = "Une erreur est survenue et le code n'a pas été renvoyé"
respond_to do |format|
format.turbo_stream do
render turbo_stream:
turbo_stream.replace('code-request',
partial: flash_path,
locals: { alert: })
end
end
end
end

# GET /resource/edit
# def edit
# super
Expand Down Expand Up @@ -170,6 +196,10 @@ def configure_sign_up_params
)
end

def users_params
params.require(:user).permit(:id)
end

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
Expand Down Expand Up @@ -218,15 +248,13 @@ def set_default_resource(resource, params)
def merge_identity(params)
identity = Identity.find_by_token(params[:user][:identity_token])

params[:user].merge({
first_name: identity.first_name,
last_name: identity.last_name,
birth_date: identity.birth_date,
school_id: identity.school_id,
class_room_id: identity.class_room_id,
gender: identity.gender,
grade_id: identity.grade.id
})
params[:user].merge(first_name: identity.first_name,
last_name: identity.last_name,
birth_date: identity.birth_date,
school_id: identity.school_id,
class_room_id: identity.class_room_id,
gender: identity.gender,
grade_id: identity.grade.id)
end

def honey_pot_checking(params)
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def create
if by_phone? && fetch_user_by_phone.try(:valid_password?, params[:user][:password])
user = fetch_user_by_phone
if user.student?
store_targeted_offer_id(user: user)
store_targeted_offer_id(user:)
if user.confirmed?
sign_in(user)
redirect_to after_sign_in_path_for(user)
else
# TODO: something wrong about this when send_sms_token is sent at user creation time with a callback
user.send_sms_token
#--------------------
redirect_to users_registrations_phone_standby_path(phone: safe_phone_param)
end
return
Expand All @@ -54,9 +56,9 @@ def store_targeted_offer_id(user:)
Rails.logger.error("--------------\n#{params}\n--------------\n")
raise 'params[:user] is nil'
end
if user && params[:user][:targeted_offer_id].present?
user.update(targeted_offer_id: params[:user][:targeted_offer_id])
end
return unless user && params[:user][:targeted_offer_id].present?

user.update(targeted_offer_id: params[:user][:targeted_offer_id])
end

def fetch_user_by_email
Expand All @@ -65,7 +67,7 @@ def fetch_user_by_email
raise 'params[:user] is nil'
end
param_email = params[:user][:email]
return User.find_by(email: param_email) if param_email.present?
User.find_by(email: param_email) if param_email.present?
end

# If you have extra params to permit, append them to the sanitizer.
Expand Down
2 changes: 2 additions & 0 deletions app/front_assets/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import './icons/empty_heart.svg';
import './icons/disabled_heart.svg';
import './icons/file_copy_line.svg';

import './onboarding/inbox-mail.svg';

import './pages/statistics/hand_left.svg';
import './pages/statistics/hand_right.svg';
import './pages/statistics/handshake.svg';
Expand Down
396 changes: 396 additions & 0 deletions app/front_assets/images/onboarding/inbox-mail.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/front_assets/stylesheets/pages/devise.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ fieldset.registration,
body.registration {
margin: 0px 20px;
}

.with-no-confirmation-sms{
#code-request{
font-size: 1.1rem;
color: $grey-50;
font-weight: 500 !important;
}
}
7 changes: 7 additions & 0 deletions app/front_assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ a:hover {
background-color: #F5F5FF;
}

.max-md-width{
max-width: 792px;
}
.centered{
margin: auto;
}

.d-flex.ccm {
.ccm-card {
max-width: 310px;
Expand Down
3 changes: 3 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def god_abilities

def student_abilities(user:)
can :look_for_offers, User
can :resend_confirmation_phone_token, User do |user|
user.phone.present? && user.student?
end
can :sign_with_sms, User
can :show, :account
can :change, ClassRoom do |class_room|
Expand Down
5 changes: 1 addition & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ def check_phone_token?(token)
phone_confirmable? && phone_token == token
end

def after_confirmation
super
end

def send_confirmation_instructions
return if created_by_teacher || statistician?

Expand Down Expand Up @@ -251,6 +247,7 @@ def signatory_role = nil
def obfuscated_phone_number = nil
def create_default_internship_offer_area = nil
def department_name = nil
def resend_confirmation_phone_token = nil
def team = nil

def already_signed?(internship_agreement_id:) = true
Expand Down
34 changes: 17 additions & 17 deletions app/models/users/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Users
class Student < User
include StudentAdmin

BITLY_STUDENT_WELCOME_URL = 'https://bit.ly/4athP2e' # internship_offers_url in production

belongs_to :school, optional: true
belongs_to :class_room, optional: true
belongs_to :grade, optional: true
Expand All @@ -30,9 +32,9 @@ def weekly_framed
validate :validate_school_presence_at_creation

# Callbacks
after_create :welcome_new_student,
:set_reminders,
:clean_phone_or_email_when_empty
after_create :set_reminders,
:clean_phone_or_email_when_empty,
:welcome_new_student

def student? = true

Expand Down Expand Up @@ -134,6 +136,13 @@ def validate_school_presence_at_creation
errors.add(:school, :blank)
end

def resend_confirmation_phone_token
return unless phone.present?

message = "Votre code de validation : #{phone_token}"
SendSmsJob.perform_later(user: self, message:)
end

def presenter
Presenters::Student.new(self)
end
Expand Down Expand Up @@ -182,20 +191,11 @@ def log_search_history(search_params)
end

def welcome_new_student
# url_options = default_search_options.merge(host: ENV.fetch('HOST'))
# target_url = Rails.application
# .routes
# .url_helpers
# .internship_offers_url(**url_options)
# shrinked_url = UrlShrinker.short_url( url: target_url, user_id: id )
shrinked_url = 'https://bit.ly/4athP2e' # internship_offers_url in production
if phone.present?
message = I18n.t('devise.sms.welcome_student', shrinked_url:)
SendSmsJob.perform_later(user: self, message:)
else
StudentMailer.welcome_email(student: self, shrinked_url:)
.deliver_later
end
return if email.blank?
return if phone.present?

StudentMailer.welcome_email(student: self, shrinked_url: BITLY_STUDENT_WELCOME_URL)
.deliver_later
end

def set_reminders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ tr class="test-internship-offer test-internship-offer-#{employer_internship_offe
title: 'Dupliquer l\'offre',
class: 'fr-btn fr-btn--secondary test-duplicate-button' do
= inline_svg_pack_tag('media/images/icons/file_copy_line.svg',
class: 'fr-mx-n1v',
alt: 'Dupliquez cette offre de stage')
class: 'fr-mx-n1v',
alt: 'Dupliquez cette offre de stage')

Loading
Loading