|
1 | 1 | class RegisterController < ApplicationController |
2 | 2 | before_action :find_b_param, except: %i[new create] |
3 | | - # Step 1 carries everything it needs, so an expired token starts a registration |
4 | | - # rather than bouncing and losing the submission |
5 | | - before_action :find_or_build_b_param, only: %i[create] |
| 3 | + # An expired token starts a registration rather than bouncing and losing the |
| 4 | + # submission. assign_organization runs next, so the form's organization_id lands on it |
| 5 | + before_action -> { find_b_param(build: true) }, only: %i[create] |
6 | 6 | before_action :assign_organization, except: %i[new] |
7 | 7 | before_action :redirect_finished, only: %i[create update] |
8 | 8 | # The step shown depends on server state - a cached page could show a step |
@@ -101,25 +101,21 @@ def confirm |
101 | 101 | end |
102 | 102 | end |
103 | 103 |
|
104 | | - def find_b_param |
105 | | - @b_param = token_b_param |
106 | | - return if @b_param.present? |
107 | | - |
108 | | - flash[:info] = translation(:registration_not_found) if params[:b_param_token].present? |
109 | | - redirect_to new_register_path |
110 | | - end |
| 104 | + # build: only step 1's submission, which carries everything a registration needs |
| 105 | + def find_b_param(build: false) |
| 106 | + @b_param = BikeServices::Register.find_token(params_token: params[:b_param_token], |
| 107 | + session_token: session[:register_b_param_token], user: current_user) |
| 108 | + @b_param ||= BikeServices::Register.b_param_for(user: current_user) if build |
| 109 | + if @b_param.blank? |
| 110 | + flash[:info] = translation(:registration_not_found) if params[:b_param_token].present? |
| 111 | + return redirect_to(new_register_path) |
| 112 | + end |
111 | 113 |
|
112 | | - # assign_organization runs next, so the form's organization_id still lands on it |
113 | | - def find_or_build_b_param |
114 | | - @b_param = token_b_param || BikeServices::Register.b_param_for(user: current_user) |
| 114 | + # The session follows whichever registration the token named, so the next |
| 115 | + # tokenless request stays on it |
115 | 116 | session[:register_b_param_token] = @b_param.id_token |
116 | 117 | end |
117 | 118 |
|
118 | | - def token_b_param |
119 | | - BikeServices::Register.find_token(params_token: params[:b_param_token], |
120 | | - session_token: session[:register_b_param_token], user: current_user) |
121 | | - end |
122 | | - |
123 | 119 | # A finished registration (bike created, or awaiting the email) only shows |
124 | 120 | # the completion page - submissions redirect there too, saving nothing |
125 | 121 | def redirect_finished |
|
0 commit comments