diff --git a/app/routes/index.js b/app/routes/index.js index b7e3691c29..a23920cd32 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -5,6 +5,7 @@ import { alias } from '@ember/object/computed'; export default Route.extend({ auth: service(), + cookies: service(), tabStates: service(), repositories: service(), features: service(), @@ -17,6 +18,10 @@ export default Route.extend({ if (!this.auth.signedIn && config.environment !== 'test' && pro && redirect) { window.location.replace('https://www.travis-ci.com'); } + + if (this.auth.signedIn) { + this.cookies.setSignedInCookie(true); + } }, redirect() { diff --git a/app/services/auth.js b/app/services/auth.js index 393456f7ec..499ff23395 100644 --- a/app/services/auth.js +++ b/app/services/auth.js @@ -50,6 +50,7 @@ export default Service.extend({ utm: service(), permissionsService: service('permissions'), wizardStateService: service('wizard-state'), + cookies: service(), state: STATE.SIGNED_OUT, @@ -98,6 +99,7 @@ export default Service.extend({ const stillLoggedIn = accounts.isAny('vcsId', vcsId); if (!stillLoggedIn) { + this.cookies.setSignedInCookie(false); this.router.transitionTo('signin'); } }, @@ -114,6 +116,7 @@ export default Service.extend({ signOut(runTeardown = true) { if (this.signedIn) this.api.get('/logout'); + this.cookies.setSignedInCookie(false); [this.localStorage, this.sessionStorage].forEach(storage => { storage.clearPreferencesData(); @@ -149,6 +152,7 @@ export default Service.extend({ }, signUp(provider) { + this.cookies.setSignedInCookie(false); this.set('state', STATE.SIGNING_IN); const url = new URL(this.redirectUrl || window.location.href); diff --git a/app/services/cookies.js b/app/services/cookies.js new file mode 100644 index 0000000000..001689777e --- /dev/null +++ b/app/services/cookies.js @@ -0,0 +1,11 @@ +import Service, { inject as service } from '@ember/service'; + +/** + * Service for cookies + */ +export default Service.extend({ + + setSignedInCookie(value) { + document.cookie = `travis_auth=${value? 'true':'false'}`; + } +}); diff --git a/waiter/lib/travis/web/app.rb b/waiter/lib/travis/web/app.rb index 562d5f0bc0..ba5ddd12e1 100644 --- a/waiter/lib/travis/web/app.rb +++ b/waiter/lib/travis/web/app.rb @@ -5,6 +5,7 @@ require 'rack/protection' require 'delegate' require 'time' +require 'date' require 'json' require 'travis/utils/deep_merge' require 'digest/md5' @@ -63,12 +64,12 @@ def initialize(options = {}) @server_start = options.fetch(:server_start) @root = options.fetch(:root) @age = 60 * 60 * 24 * 365 - @routers = { default: create_router } + @routers = { }#default: create_router } end def call(env) name = env['travis.alt'] || :default - routers[name] ||= create_router(alt: name) + routers[name] ||= create_router(alt: name, env: env) route = routers[name].call(env) route[1]['Date'] = Time.now.httpdate route @@ -114,6 +115,12 @@ def response_for(file, options = {}) } end + env = options[:env] || [] + cookie = env['HTTP_COOKIE'] + if cookie&.include? 'travis_auth=' + headers['Set-Cookie'] = "travis_logged_in=#{cookie.include?('travis_auth=true').to_s};Domain=travis-ci.com;Max-Age=#{86400*90};path=/;" + end + [200, headers, [content]] end