From 6b02c05a999e332fbab94fa18b1eead6b1837a1b Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 29 Aug 2025 13:54:43 -0500 Subject: [PATCH] Make work on Fedora M1 and use faye on http for development --- app/models/user.rb | 20 +++++++--- app/views/layouts/obtain_token.html.slim | 18 --------- app/views/layouts/user/obtain_token.html.slim | 21 +++++++---- config/initializers/mozo_settings.rb | 2 +- faye/Gemfile.lock | 37 +++++++++++-------- faye/config.ru | 1 + faye/rebuild-docker.sh | 2 +- faye/thin_config.yml | 9 +++++ 8 files changed, 61 insertions(+), 49 deletions(-) delete mode 100644 app/views/layouts/obtain_token.html.slim create mode 100644 faye/thin_config.yml diff --git a/app/models/user.rb b/app/models/user.rb index d02caf1c..d62ef005 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,11 +36,9 @@ class User #view :by_provider, key: [:provider, :uid] view :by_provider_and_uid, key: [:provider, :uid] - def self.find_for_oauth(auth_data, user) + def self.find_for_oauth(auth_data, controller_current_user) #user = database.view(self.by_provider(key: [auth_data.provider, auth_data.uid], limit: 1)).first - user = find_by_provider_and_uid(auth_data.provider, auth_data.uid) - - user || create( + attributes = { provider: auth_data.provider, uid: auth_data.uid, name: auth_data.info.nickname, @@ -49,7 +47,19 @@ class User oauth_token: auth_data.credentials.token, oauth_expires_at: auth_data.credentials.expires ? Time.at(auth_data.credentials.expires_at) : nil, auth_data: auth_data - ) + } + + if user = find_by_email(attributes[:email]) + # Update the provider attributes to keep the email unique and valid. This means that + # if two people from other providers, with the same e-mail, can hijack the mozo account. + # probability: around zero + unless user.provider == attributes[:provider] and user.uid == attributes[:uid] + user.update attributes + end + else + user = create attributes + end + user end # needed for cmtool diff --git a/app/views/layouts/obtain_token.html.slim b/app/views/layouts/obtain_token.html.slim deleted file mode 100644 index 46ba4bc9..00000000 --- a/app/views/layouts/obtain_token.html.slim +++ /dev/null @@ -1,18 +0,0 @@ -doctype html -html lang="en" - head - meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" - meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" - title= application_title - / = stylesheet_link_tag 'obtain_token/application' - / = csrf_meta_tags - body - - if flash[:alert].present? - .alert.alert-error - a.close data-dismiss="alert" × - div= flash[:alert] - - if flash[:notice].present? - .alert.alert-success - a.close data-dismiss="alert" × - div= flash[:notice] - #obtain-token-container= yield diff --git a/app/views/layouts/user/obtain_token.html.slim b/app/views/layouts/user/obtain_token.html.slim index a74ecdfc..46ba4bc9 100644 --- a/app/views/layouts/user/obtain_token.html.slim +++ b/app/views/layouts/user/obtain_token.html.slim @@ -1,13 +1,18 @@ doctype html html lang="en" head - meta charset="utf-8" meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" - meta name="viewport" content="width=device-width, initial-scale=1.0" - title Qwaiter - = stylesheet_link_tag "user/foundation/application" - = javascript_include_tag "vendor/modernizr" - javascript: - var Qstorage = localStorage; + meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" + title= application_title + / = stylesheet_link_tag 'obtain_token/application' + / = csrf_meta_tags body - = yield + - if flash[:alert].present? + .alert.alert-error + a.close data-dismiss="alert" × + div= flash[:alert] + - if flash[:notice].present? + .alert.alert-success + a.close data-dismiss="alert" × + div= flash[:notice] + #obtain-token-container= yield diff --git a/config/initializers/mozo_settings.rb b/config/initializers/mozo_settings.rb index e3fe9edb..d8c8c734 100644 --- a/config/initializers/mozo_settings.rb +++ b/config/initializers/mozo_settings.rb @@ -1,5 +1,5 @@ if Rails.env.development? - Qwaiter.event_host = "https://localhost:9296/faye" + Qwaiter.event_host = "http://localhost:9296/faye" else Qwaiter.event_host = "https://events.mozo.bar:9296/faye" end diff --git a/faye/Gemfile.lock b/faye/Gemfile.lock index 21b42dfe..7dce3c7b 100644 --- a/faye/Gemfile.lock +++ b/faye/Gemfile.lock @@ -1,10 +1,11 @@ GEM remote: https://rubygems.org/ specs: - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + base64 (0.3.0) coderay (1.1.3) - cookiejar (0.3.3) + cookiejar (0.3.4) daemons (1.4.1) em-http-request (1.1.7) addressable (>= 2.3.4) @@ -12,10 +13,11 @@ GEM em-socksify (>= 0.3) eventmachine (>= 1.0.3) http_parser.rb (>= 0.6.0) - em-socksify (0.3.2) + em-socksify (0.3.3) + base64 eventmachine (>= 1.0.0.beta.4) eventmachine (1.2.7) - faye (1.4.0) + faye (1.4.1) cookiejar (>= 0.3.0) em-http-request (>= 1.1.6) eventmachine (>= 0.12.0) @@ -23,22 +25,25 @@ GEM multi_json (>= 1.0.0) rack (>= 1.0.0) websocket-driver (>= 0.5.1) - faye-websocket (0.11.1) + faye-websocket (0.12.0) eventmachine (>= 0.12.0) - websocket-driver (>= 0.5.1) + websocket-driver (>= 0.8.0) http_parser.rb (0.8.0) - method_source (1.0.0) - multi_json (1.15.0) - pry (0.14.1) + logger (1.7.0) + method_source (1.1.0) + multi_json (1.17.0) + pry (0.15.2) coderay (~> 1.1) method_source (~> 1.0) - public_suffix (4.0.6) - rack (2.2.3) - thin (1.8.1) + public_suffix (6.0.2) + rack (3.2.0) + thin (2.0.1) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) - rack (>= 1, < 3) - websocket-driver (0.7.5) + logger + rack (>= 1, < 4) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -51,4 +56,4 @@ DEPENDENCIES thin BUNDLED WITH - 2.1.4 + 2.7.1 diff --git a/faye/config.ru b/faye/config.ru index d4208422..01889d44 100644 --- a/faye/config.ru +++ b/faye/config.ru @@ -1,4 +1,5 @@ require 'faye' +require 'pry' #require 'pry' # started using (with extra server contexts of cours like full paths): # thin start -d -R faye/config.ru -p 9296 --pid tmp/pids/faye.pid diff --git a/faye/rebuild-docker.sh b/faye/rebuild-docker.sh index 98917db1..63898c60 100644 --- a/faye/rebuild-docker.sh +++ b/faye/rebuild-docker.sh @@ -6,7 +6,7 @@ pwd_dirname=$(basename $(pwd)) script_dirname="faye" arch=$(uname) if [ $arch == "Darwin" ]; then - certs_dir="/Users/bj/Library/Application Support/mkcert" + certs_dir="~/.mkcert" else certs_dir="/etc/letsencrypt/live/mozo.bar" fi diff --git a/faye/thin_config.yml b/faye/thin_config.yml new file mode 100644 index 00000000..911d1fbb --- /dev/null +++ b/faye/thin_config.yml @@ -0,0 +1,9 @@ +# run using: thin start -C thin_config.yml +--- +port: 9296 +rackup: config.ru +# ssl: true +# ssl-disable-verify: true +# ssl-key-file: /home/bj/.mkcerts/localhost-key.pem +# ssl-cert-file: /home/bj/.mkcerts/localhost.pem +