Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: appengine/swarming/elements/res/imp/common/auth-signin.html

Issue 2279903002: Make the new index page more useful (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@whoami3
Patch Set: Fix names Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved. 2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0 3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file. 4 that can be found in the LICENSE file.
5 5
6 The `auth-signin` element displays sign-in/sign-out button, user email and 6 The `auth-signin` element displays sign-in/sign-out button, user email and
7 avatar. 7 avatar.
8 It has a google-signin/google-signin-aware element under the hood that handles 8 It has a google-signin/google-signin-aware element under the hood that handles
9 the actual OAuth logic. 9 the actual OAuth logic.
10 10
11 Usage: 11 Usage:
12 12
13 <auth-signin></auth-signin> 13 <auth-signin></auth-signin>
14 14
15 Properties: 15 Properties:
16 authHeaders: Object, Use this in iron-ajax to set oauth2 headers. 16 auth_headers: Object, Use this as an argument to sk.request to set oauth2 he aders.
17 authResponse: Object, The raw gapi.auth2.AuthResponse object. 17 auth_response: Object, The raw gapi.auth2.AuthResponse object.
18 clientId: String, The client id to authenticate 18 client_id: String, The client id to authenticate
19 profile: Object, Read Only, The email address and imageurl of the logged in user. 19 profile: Object, Read Only, The email address and imageurl of the logged in user.
20 signedIn: Boolean, Read Only, if the user is logged in. 20 signed_in: Boolean, Read Only, if the user is logged in.
21 21
22 Methods: 22 Methods:
23 signIn(): Signs the user in by popping up the authorization dialog. 23 signIn(): Signs the user in by popping up the authorization dialog.
24 signOut(): Signs the user out. 24 signOut(): Signs the user out.
25 25
26 Events: 26 Events:
27 auth-signin: Fired when the oauth handshake has completed and a user has log ged in. 27 auth-signin: Fired when the oauth handshake has completed and a user has log ged in.
28 --> 28 -->
29 29
30 <link rel="import" href="/res/imp/bower_components/google-signin/google-signin-a ware.html"> 30 <link rel="import" href="/res/imp/bower_components/google-signin/google-signin-a ware.html">
31 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html"> 31 <link rel="import" href="/res/imp/bower_components/polymer/polymer.html">
32 32
33 33
34 <dom-module id="auth-signin"> 34 <dom-module id="auth-signin">
35 <template> 35 <template>
36 <style> 36 <style>
37 #avatar { 37 #avatar {
38 border-radius: 5px; 38 border-radius: 5px;
39 } 39 }
40 a { 40 a {
41 color: white; 41 color: white;
42 } 42 }
43 .center { 43 .center {
44 vertical-align: middle; 44 vertical-align: middle;
45 } 45 }
46 </style> 46 </style>
47 47
48 <google-signin-aware id="aware" 48 <google-signin-aware id="aware"
49 client-id="[[clientId]]" 49 client-id="[[client_id]]"
50 scopes="email" 50 scopes="email"
51 on-google-signin-aware-success="_onSignin" 51 on-google-signin-aware-success="_onSignin"
52 on-google-signin-aware-signed-out="_onSignout"> 52 on-google-signin-aware-signed-out="_onSignout">
53 </google-signin-aware> 53 </google-signin-aware>
54 54
55 <template is="dom-if" if="[[!signedIn]]"> 55 <template is="dom-if" if="[[!signed_in]]">
56 <div id="signinContainer"> 56 <div id="signinContainer">
57 <a on-tap="signIn" href="#">Sign in</a> 57 <a on-tap="signIn" href="#">Sign in</a>
58 </div> 58 </div>
59 </template> 59 </template>
60 60
61 <template is="dom-if" if="[[signedIn]]"> 61 <template is="dom-if" if="[[signed_in]]">
62 <img class="center" id="avatar" src="[[profile.imageUrl]]" width="30" heig ht="30"> 62 <img class="center" id="avatar" src="[[profile.imageUrl]]" width="30" heig ht="30">
63 <span class="center" >[[profile.email]]</span> 63 <span class="center" >[[profile.email]]</span>
64 <span class="center" >|</span> 64 <span class="center" >|</span>
65 <a class="center" on-tap="signOut" href="#">Sign out</a> 65 <a class="center" on-tap="signOut" href="#">Sign out</a>
66 </template> 66 </template>
67 </template> 67 </template>
68 <script> 68 <script>
69 'use strict'; 69 'use strict';
70 Polymer({ 70 Polymer({
71 is: 'auth-signin', 71 is: 'auth-signin',
72 properties: { 72 properties: {
73 authHeaders: { 73 auth_headers: {
74 type: Object, 74 type: Object,
75 computed: "_makeHeader(authResponse)", 75 computed: "_makeHeader(auth_response)",
76 notify: true, 76 notify: true,
77 }, 77 },
78 authResponse: { 78 auth_response: {
79 type: Object, 79 type: Object,
80 notify: true, 80 notify: true,
81 }, 81 },
82 clientId: { 82 client_id: {
83 type: String, 83 type: String,
84 }, 84 },
85 profile: { 85 profile: {
86 type: Object, 86 type: Object,
87 readOnly: true 87 readOnly: true
88 }, 88 },
89 signedIn: { 89 signed_in: {
90 type: Boolean, 90 type: Boolean,
91 readOnly: true, 91 readOnly: true,
92 value: false, 92 value: false,
93 notify: true, 93 notify: true,
94 } 94 }
95 }, 95 },
96 96
97 _onSignin: function(e) { 97 _onSignin: function(e) {
98 this._setSignedIn(true); 98 this._setSigned_in(true);
99 var user = gapi.auth2.getAuthInstance().currentUser.get(); 99 var user = gapi.auth2.getAuthInstance().currentUser.get();
100 var profile = user.getBasicProfile(); 100 var profile = user.getBasicProfile();
101 this._setProfile({ 101 this._setProfile({
102 email: profile.getEmail(), 102 email: profile.getEmail(),
103 imageUrl: profile.getImageUrl() 103 imageUrl: profile.getImageUrl()
104 }); 104 });
105 this.set("authResponse", user.getAuthResponse()); 105 this.set("auth_response", user.getAuthResponse());
106 this._setSignedIn(true); 106 this._setSigned_in(true);
107 this.fire("auth-signin"); 107 this.fire("auth-signin");
108 }, 108 },
109 109
110 _onSignout: function(e) { 110 _onSignout: function(e) {
111 this._setSignedIn(false); 111 this._setSigned_in(false);
112 this._setProfile(null); 112 this._setProfile(null);
113 }, 113 },
114 114
115 _makeHeader: function(authResponse) { 115 _makeHeader: function(auth_response) {
116 if (!authResponse) { 116 if (!auth_response) {
117 return {}; 117 return {};
118 } 118 }
119 return { 119 return {
120 "authorization": authResponse.token_type + " " + authResponse.access_t oken 120 "authorization": auth_response.token_type + " " + auth_response.access _token
121 }; 121 };
122 }, 122 },
123 123
124 signIn: function() { 124 signIn: function() {
125 this.$.aware.signIn(); 125 this.$.aware.signIn();
126 }, 126 },
127 127
128 signOut: function() { 128 signOut: function() {
129 this.$.aware.signOut(); 129 this.$.aware.signOut();
130 } 130 }
131 }); 131 });
132 </script> 132 </script>
133 </dom-module> 133 </dom-module>
OLDNEW
« no previous file with comments | « appengine/swarming/elements/build/elements.html ('k') | appengine/swarming/elements/res/imp/common/swarming-app.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698