Commit e517ef4a authored by Cool Fire's avatar Cool Fire

Added some logic + error page with redirect back

parent f8b3f23c
Pipeline #326 failed with stages
in 2 minutes and 1 second
---
error_message: The invite code does not appear to be valid. Please go back and try again.
......@@ -12,14 +12,13 @@ class SignupSite < Sinatra::Base
end
post '/check-code' do
if (!params.key? :input_invite) ||
params[:input_invite].empty? ||
params[:input_invite] !~ /^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/
@header = 'Insomnia 24/7 shells signup'
@body = 'Invite code appears to be invalid. Please try again.'
@progress = 25
erb :index
if params[:input_invite] !~ /^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/
cc = YAML.load_file('content/check-code.yaml')
session[:error_message] = cc['error_message']
session[:error_location] = '/enter-code'
session[:error_progress] = 25
session[:error_data] = Rack::Utils.escape_html(params[:input_invite])
redirect '/error', 302
else
session[:invite] = Rack::Utils.escape_html(params[:input_invite])
redirect '/enter-details', 302
......
......@@ -13,6 +13,6 @@ class SignupSite < Sinatra::Base
end
post '/check-details' do
# Some checking stuff
'Not yet implemented.'
end
end
# frozen_string_literal: true
# Invite code handling
class SignupSite < Sinatra::Base
get '/error' do
@header = 'Oh no!'
@body = session[:error_message]
@form = erb :error
@progress = session[:error_progress]
session[:error_reload_form] = true
erb :index
end
end
......@@ -21,3 +21,4 @@ end
require_relative 'routes/code'
require_relative 'routes/details'
require_relative 'routes/error'
......@@ -3,7 +3,12 @@
<div class="form-group">
<label for="input_invite" class="col-lg-2 control-label">Invite code</label>
<div class="col-lg-10">
<% if session[:error_reload_form] %>
<input type="text" class="form-control" id="input_invite" name="input_invite" value="<%= session[:error_data] %>">
<% session[:error_reload_form] = false %>
<% else %>
<input type="text" class="form-control" id="input_invite" name="input_invite" placeholder="1234abcd-1234-5678-9abc-432abc987def">
<% end%>
</div>
</div>
<div class="form-group">
......
<form class="form-horizontal">
<form class="form-horizontal" method="POST" action="/check-details">
<fieldset>
<div class="form-group">
<label for="input_username" class="col-lg-2 control-label">User name</label>
......
<form class="form-horizontal" method="GET" action="<%= session[:error_location] %>">
<fieldset>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-info">Go back</button>
</div>
</div>
</fieldset>
</form>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment