Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login cookie #2845

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { alias } from '@ember/object/computed';

export default Route.extend({
auth: service(),
cookies: service(),
tabStates: service(),
repositories: service(),
features: service(),
Expand All @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions app/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default Service.extend({
utm: service(),
permissionsService: service('permissions'),
wizardStateService: service('wizard-state'),
cookies: service(),

state: STATE.SIGNED_OUT,

Expand Down Expand Up @@ -98,6 +99,7 @@ export default Service.extend({
const stillLoggedIn = accounts.isAny('vcsId', vcsId);

if (!stillLoggedIn) {
this.cookies.setSignedInCookie(false);
this.router.transitionTo('signin');
}
},
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions app/services/cookies.js
Original file line number Diff line number Diff line change
@@ -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'}`;
}
});
11 changes: 9 additions & 2 deletions waiter/lib/travis/web/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'rack/protection'
require 'delegate'
require 'time'
require 'date'
require 'json'
require 'travis/utils/deep_merge'
require 'digest/md5'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down