 Chromium Code Reviews
 Chromium Code Reviews Issue 2174903002:
  Add stub pages and oauth-blessed request to /newui  (Closed) 
  Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
    
  
    Issue 2174903002:
  Add stub pages and oauth-blessed request to /newui  (Closed) 
  Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 <!-- | |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. | |
| 3 Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 that can be found in the LICENSE file. | |
| 5 | |
| 6 The `auth-signin` element displays sign-in/sign-out button, user email and | |
| 7 avatar. | |
| 8 | |
| 9 Usage: | |
| 10 | |
| 11 <auth-signin></auth-signin> | |
| 12 | |
| 13 Properties: | |
| 14 authHeaders: Object, Use this in iron-ajax to set oauth2 headers. | |
| 15 authResponse: Object, The raw gapi.auth2.AuthResponse object. | |
| 16 clientId: String, The client id to authenticate | |
| 17 profile: Object, Read Only, The email address and imageurl of the logged in user. | |
| 18 signedIn: Boolean, Read Only, if the user is logged in. | |
| 19 | |
| 20 Methods: | |
| 21 None. | |
| 22 | |
| 23 Events: | |
| 24 None. | |
| 25 --> | |
| 26 | |
| 27 <link rel="import" href="../bower_components/google-signin/google-signin-aware.h tml"> | |
| 28 <link rel="import" href="../bower_components/polymer/polymer.html"> | |
| 29 | |
| 30 | |
| 31 <dom-module id="auth-signin"> | |
| 32 <template> | |
| 33 <style> | |
| 34 #avatar { | |
| 35 border-radius: 5px; | |
| 36 } | |
| 37 #signinContainer { | |
| 38 margin-top: 14px; | |
| 39 } | |
| 40 </style> | |
| 41 | |
| 42 <google-signin-aware id="aware" | |
| 43 client-id="[[clientId]]" | |
| 44 scopes="email" | |
| 45 on-google-signin-aware-success="_onSignin" | |
| 46 on-google-signin-aware-signed-out="_onSignout"> | |
| 47 </google-signin-aware> | |
| 48 | |
| 49 <template is="dom-if" if="[[!signedIn]]"> | |
| 50 <div id="signinContainer"> | |
| 51 <a on-tap="signIn" href="#">Sign in</a> | |
| 52 </div> | |
| 53 </template> | |
| 54 | |
| 55 <template is="dom-if" if="[[signedIn]]"> | |
| 56 <img id="avatar" src="[[profile.imageUrl]]" width="30" height="30"> | |
| 57 <span>[[profile.email]]</span> | |
| 58 <span>|</span> | |
| 59 <a on-tap="signOut" href="#">Sign out</a> | |
| 60 </template> | |
| 61 </template> | |
| 62 <script> | |
| 63 'use strict'; | |
| 64 Polymer({ | |
| 65 is: 'auth-signin', | |
| 66 properties: { | |
| 67 authHeaders: { | |
| 68 type: Object, | |
| 69 computed: "_makeHeader(authResponse)", | |
| 70 notify: true, | |
| 71 }, | |
| 72 authResponse: { | |
| 73 type: Object, | |
| 74 }, | |
| 75 clientId: { | |
| 76 type: String, | |
| 77 }, | |
| 78 profile: { | |
| 79 type: Object, | |
| 80 readOnly: true | |
| 81 }, | |
| 82 signedIn: { | |
| 83 type: Boolean, | |
| 84 readOnly: true, | |
| 85 value: false | |
| 86 } | |
| 87 }, | |
| 88 _onSignin: function(e) { | |
| 
stephana
2016/07/24 21:17:07
Empty line between methods.
 
kjlubick
2016/07/25 12:45:44
Done.
 | |
| 89 this._setSignedIn(true); | |
| 90 var user = gapi.auth2.getAuthInstance().currentUser.get(); | |
| 91 var profile = user.getBasicProfile(); | |
| 92 this._setProfile({ | |
| 93 email: profile.getEmail(), | |
| 94 imageUrl: profile.getImageUrl() | |
| 95 }); | |
| 96 this.set("authResponse", user.getAuthResponse()); | |
| 97 this.fire("auth-signin"); | |
| 98 }, | |
| 99 _onSignout: function(e) { | |
| 100 this._setSignedIn(false); | |
| 101 this._setProfile(null); | |
| 102 }, | |
| 103 _makeHeader: function(authResponse) { | |
| 104 if (!authResponse) { | |
| 105 return {}; | |
| 106 } | |
| 107 return { | |
| 108 "authorization": authResponse.token_type + " " + authResponse.access_t oken | |
| 109 | |
| 110 }; | |
| 111 }, | |
| 112 signIn: function() { | |
| 
stephana
2016/07/24 21:17:07
If they are public facing functions signIn and sig
 
kjlubick
2016/07/25 12:45:44
Done.  I had also forgotten to document the auth-s
 | |
| 113 this.$.aware.signIn(); | |
| 114 }, | |
| 115 signOut: function() { | |
| 116 this.$.aware.signOut(); | |
| 117 } | |
| 118 }); | |
| 119 </script> | |
| 120 </dom-module> | |
| OLD | NEW |