diff --git a/.env.development b/.env.development index 85e81807e2..910785e85c 100644 --- a/.env.development +++ b/.env.development @@ -30,3 +30,6 @@ OIDC_SECRET_KEY=oidc-development-secret PAYPAL_BASE_URL=https://api-m.sandbox.paypal.com WCA_REGISTRATIONS_URL=http://localhost:8000 WCA_REGISTRATIONS_BACKEND_URL=http://wca_registration_handler:3000 +STAGING_OAUTH_URL=https://staging.worldcubeassociation.org +STAGING_OAUTH_CLIENT=example-application-id +STAGING_OAUTH_SECRET=example-secret diff --git a/.env.test b/.env.test index dd3ee973cf..1fa573efcf 100644 --- a/.env.test +++ b/.env.test @@ -29,3 +29,6 @@ PAYPAL_CLIENT_SECRET=EIknLp919Gbuj2CYmEWECyKH5HwJTWQNuqFuCr1qFMrGNzwkF8dD0VkwzwI PAYPAL_ATTRIBUTION_CODE=FLAVORsb-noyt529176316_MP PAYPAL_BASE_URL=https://api-m.sandbox.paypal.com WCA_REGISTRATIONS_BACKEND_URL=http://wca_registration_handler:3000 +STAGING_OAUTH_URL=https://staging.worldcubeassociation.org +STAGING_OAUTH_CLIENT=example-application-id +STAGING_OAUTH_SECRET=example-secret diff --git a/app/assets/stylesheets/wca.scss b/app/assets/stylesheets/wca.scss index 39b885a534..3055c308ce 100644 --- a/app/assets/stylesheets/wca.scss +++ b/app/assets/stylesheets/wca.scss @@ -2,6 +2,10 @@ font-family: monospace; } +.watermark { + background-image: url("data:image/svg+xml;utf8,"); +} + table.table { // From http://stackoverflow.com/a/10688485 &.table-nonfluid { diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 967a6c9e1e..e5b6f9c162 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -8,6 +8,43 @@ class SessionsController < Devise::SessionsController # Make sure this happens always before any before_action protect_from_forgery with: :exception, prepend: true + def staging_oauth_login + return if EnvConfig.WCA_LIVE_SITE? + + client = OAuth2::Client.new(AppSecrets.STAGING_OAUTH_CLIENT, AppSecrets.STAGING_OAUTH_SECRET, + site: EnvConfig.STAGING_OAUTH_URL) + redirect_uri = staging_login_url + + unless params[:code].present? + return redirect_to client.auth_code.authorize_url( + redirect_uri: redirect_uri, + ), allow_other_host: true + end + + access_token = client.auth_code.get_token( + params[:code], redirect_uri: redirect_uri + ).token + + # Get /me to figure out which user we are + connection = Faraday.new( + url: EnvConfig.STAGING_OAUTH_URL, + headers: { + 'Authorization' => "Bearer #{access_token}", + 'Content-Type' => 'application/json', + }, + ) + + results = connection.get("/api/v0/me").body + + user = User.find(results["me"]["id"]) + if user + sign_in(user) + redirect_to root_url, notice: "Successfully logged in as #{user.wca_id}" + else + redirect_to root_url, alert: "Your user is not yet imported into our Staging Website, please try again later" + end + end + def new super # Remove any lingering user data from previous login attempt diff --git a/app/views/devise/sessions/_live_login.html.erb b/app/views/devise/sessions/_live_login.html.erb new file mode 100644 index 0000000000..df3def63a1 --- /dev/null +++ b/app/views/devise/sessions/_live_login.html.erb @@ -0,0 +1,9 @@ +
+ Hint! It looks like you are using the + developer export + <% unless DbDumpHelper.use_staging_password? %> + , every user's password is "wca" + <% end %> + . You can find email addresses to log in with over on + <%= link_to "the delegates page", delegates_path %>. +
+ <% end %> +- Hint! It looks like you are using the - developer export - <% unless DbDumpHelper.use_staging_password? %> - , every user's password is "wca" - <% end %> - . You can find email addresses to log in with over on - <%= link_to "the delegates page", delegates_path %>. -
- <% end %> -