|
1 | 1 | <link rel="import" href="../bower_components/iron-signals/iron-signals.html"> |
2 | 2 |
|
| 3 | +<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html"> |
| 4 | + |
3 | 5 | <link rel="import" href="../bower_components/google-signin/google-signin.html"> |
4 | 6 |
|
5 | 7 | <!-- |
|
20 | 22 | label-signin="SIGN IN WITH GOOGLE" |
21 | 23 | on-google-signed-out="_signedOut"></google-signin> |
22 | 24 |
|
| 25 | + <iron-ajax |
| 26 | + id = "getAccountRequest" |
| 27 | + url = "https://elite-firefly-737.appspot.com/_ah/api/expertstracking/v2.0/account/{{_googleUser.email}}" |
| 28 | + method = "GET" |
| 29 | + handle-as = "json" |
| 30 | + last-response = "{{_apiUser}}" |
| 31 | + on-response = "_handleAccountInfo" |
| 32 | + on-error = "_handleAccountError"> |
| 33 | + </iron-ajax> |
| 34 | + |
23 | 35 | </template> |
24 | 36 |
|
25 | 37 | <script> |
|
51 | 63 | * User information from Google authentication |
52 | 64 | */ |
53 | 65 | _googleUser: { |
| 66 | + type: Object |
| 67 | + }, |
| 68 | + |
| 69 | + /** |
| 70 | + * User information from Google authentication |
| 71 | + */ |
| 72 | + _apiUser: { |
54 | 73 | type: Object, |
55 | | - observer: '_userInfoChanged' |
56 | 74 | }, |
57 | 75 |
|
58 | 76 | /** |
|
91 | 109 |
|
92 | 110 | console.debug("[experts-signin] _signedIn",this._googleUser); |
93 | 111 |
|
94 | | - this.fire('iron-signal', {name: 'user', data: this._googleUser} ) |
| 112 | + this.$.getAccountRequest.generateRequest(); |
| 113 | + |
95 | 114 | }, |
96 | 115 |
|
97 | 116 | /** |
|
137 | 156 | */ |
138 | 157 | _computeAuthorized: function (user) { |
139 | 158 | return (!!user && !!user.email); |
140 | | - } |
| 159 | + }, |
| 160 | + |
| 161 | + _handleAccountInfo: function(evt, ironRequest) { |
| 162 | + console.debug("[experts-profile] _handleAccountInfo - apiUser",this._apiUser); |
| 163 | + evt.stopPropagation(); |
| 164 | + var user = this._googleUser; |
| 165 | + if (this._apiUser && this._apiUser.email) { |
| 166 | + if (this._apiUser.expert_type) { |
| 167 | + user.category = this._apiUser.expert_type; |
| 168 | + user.isExpert = (this._apiUser.expert_type !== 'deleted'); |
| 169 | + } |
| 170 | + user.skills = this._apiUser.skills; |
| 171 | + user.biography = this._apiUser.biography; |
| 172 | + user.city = this._apiUser.city; |
| 173 | + user.country = this._apiUser.country; |
| 174 | + if (this._apiUser.pic_url) { |
| 175 | + user.image = this._apiUser.pic_url; |
| 176 | + } |
| 177 | + user.product_group = this._apiUser.product_group; |
| 178 | + } |
| 179 | + this._setUser(user); |
| 180 | + console.debug("[experts-profile] _handleAccountInfo", this.user); |
| 181 | + this.fire('iron-signal', {name: 'user', data: this.user} ) |
| 182 | + }, |
| 183 | + _handleAccountError: function(evt, error) { |
| 184 | + |
| 185 | + }, |
141 | 186 | }); |
142 | 187 | })(); |
143 | 188 | </script> |
|
0 commit comments