summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Étienne Deparis 2020-03-17 20:24:28 +0100
committerGravatar Étienne Deparis 2020-03-17 20:24:28 +0100
commit1d834854729bc40434b08b801f14d70eb174689b (patch)
tree3c865568e3201052880b1e975ea311252b378261
parent5ada2824dd831e355cdb59125212262efaa4c1f6 (diff)
downloadstatus-sessions.tar.gz
status-sessions.tar.xz
status-sessions.zip
feat: Begin to work on sessions (WIP)sessions
-rw-r--r--.gitignore1
-rw-r--r--status.rb25
-rw-r--r--views/list.slim4
-rw-r--r--views/menu.slim4
-rw-r--r--views/status.slim8
5 files changed, 26 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index f8ba406..dde0cd2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
.ruby-gemset
.bundle
+app.yml
config.yml
coverage
data.db
diff --git a/status.rb b/status.rb
index bdc034f..dd79196 100644
--- a/status.rb
+++ b/status.rb
@@ -128,12 +128,15 @@ module AppLogic
end
def check_token
- uid = params[:id]
- token = params[:token]
+ uid = params[:id] || session[:id]
+ token = params[:token] || session[:token]
if uid && token && fetch_matching_status(uid, token)
- @auth_chain = "id=#{uid}&token=#{token}"
+ session[:id] = uid
+ session[:token] = @current_status['token']
return true
end
+ session.delete(:id)
+ session.delete(:token)
false
end
@@ -168,7 +171,14 @@ end
class Status < Sinatra::Base
configure :production, :development do
enable :logging
- disable :method_override, :sessions
+ disable :method_override
+ if File.exist?('./app.yml')
+ app_config = YAML.load_file('./app.yml')
+ enable :sessions
+ set :sessions, domain: app_config['sessions_domain']
+ secret = app_config['sessions_secret'] || SecureRandom.hex(64)
+ set :session_secret, secret
+ end
end
include MailHelper
@@ -203,12 +213,11 @@ class Status < Sinatra::Base
@db = SQLite3::Database.new './data.db'
@db.results_as_hash = true
@current_status = nil
- @auth_chain = ''
@details = {}
end
get '/' do
- redirect to("/status?#{@auth_chain}") if check_token
+ redirect to('/status') if check_token
@title = 'Status index'
slim :index
end
@@ -230,7 +239,7 @@ class Status < Sinatra::Base
details = params.select { |k, _| ['status', 'eta'].include?(k) }
update_details(details, params[:token])
send_mattermost_notification(params[:status])
- redirect to("/status?#{@auth_chain}")
+ redirect to('/status')
end
post '/details' do
@@ -238,7 +247,7 @@ class Status < Sinatra::Base
possible_keys = @config['custom_fields']&.map { |d| d['name'] } || []
details = params.select { |k, _| possible_keys.include?(k) }
update_details(details, params[:token])
- redirect to("/status?saved=&#{@auth_chain}")
+ redirect to('/status?saved=')
end
get '/list' do
diff --git a/views/list.slim b/views/list.slim
index 226edf8..80602e0 100644
--- a/views/list.slim
+++ b/views/list.slim
@@ -4,11 +4,11 @@ header
form action=url('/list') method='get'
fieldset
input type='hidden' name='id' value=params[:id]
- input type='hidden' name='token' value=params[:token]
+ input type='hidden' name='token' value=@current_status['token']
input(type='text' name='filter' placeholder='Filter…'
value=params[:filter] style='width: 50%')
input<> type='submit' value='search'
- a href=url("/list?#{@auth_chain}")
+ a href=url('/list')
| Reload
ul#presence
diff --git a/views/menu.slim b/views/menu.slim
index 0495ac9..cf5e024 100644
--- a/views/menu.slim
+++ b/views/menu.slim
@@ -1,8 +1,8 @@
nav
ul
li
- a href=url("/list?#{@auth_chain}")
+ a href=url('/list')
| List all
li
- a href=url("/status?#{@auth_chain}")
+ a href=url('/status')
| My status
diff --git a/views/status.slim b/views/status.slim
index 367e0e3..4b0a566 100644
--- a/views/status.slim
+++ b/views/status.slim
@@ -12,7 +12,7 @@ p#presence
form#statusform action=url('/status') method='post'
fieldset
input type='hidden' name='id' value=params[:id]
- input type='hidden' name='token' value=params[:token]
+ input type='hidden' name='token' value=@current_status['token']
input type='hidden' name='status' value=@next_status
- if @my_status == 'present' && @config['eta_field']
p.formgroup
@@ -39,7 +39,7 @@ hr
form. All fields are optional.
input type='hidden' name='id' value=params[:id]
- input type='hidden' name='token' value=params[:token]
+ input type='hidden' name='token' value=@current_status['token']
- @config['custom_fields'].each do |detail|
- if detail['name'] != 'eta'
p.formgroup
@@ -56,12 +56,12 @@ hr
hr
p
- a.alert.warning href=url("/revoke?#{@auth_chain}")
+ a.alert.warning href=url('/revoke')
i> class='fa fa-exclamation-triangle'
| Revoke my current token
p
- a.alert.danger href=url("/delete?#{@auth_chain}")
+ a.alert.danger href=url('/delete')
i> class='fa fa-exclamation-circle'
| Delete all data about me