Login/logout buttons with basic account manager
Currently this checks to see if a user is logged in by hitting the XHR endpoint /accounts/self/detail upon initial page load. Change-Id: Ida77c60bf9fee34ddfaee85a15b68cdf85a58af7 Feature: Issue 3693
This commit is contained in:
61
polygerrit-ui/app/elements/gr-account-dropdown.html
Normal file
61
polygerrit-ui/app/elements/gr-account-dropdown.html
Normal file
@@ -0,0 +1,61 @@
|
||||
<!--
|
||||
Copyright (C) 2015 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
|
||||
<dom-module id="gr-account-dropdown">
|
||||
<template>
|
||||
<style>
|
||||
:not(.loggedIn):not(.loggedOut) .loginButton,
|
||||
:not(.loggedIn):not(.loggedOut) .logoutButton,
|
||||
.loggedIn .loginButton,
|
||||
.loggedOut .logoutButton {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
<div class$="[[_computeContainerClass(account)]]">
|
||||
<a class="loginButton" href="/login" on-tap="_loginTapHandler">Login</a>
|
||||
<a class="logoutButton" href="/logout">Logout</a>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Polymer({
|
||||
is: 'gr-account-dropdown',
|
||||
|
||||
properties: {
|
||||
account: Object,
|
||||
},
|
||||
|
||||
_loginTapHandler: function(e) {
|
||||
e.preventDefault();
|
||||
page('/login/' + encodeURIComponent(
|
||||
window.location.pathname + window.location.hash));
|
||||
},
|
||||
|
||||
_computeContainerClass: function(account) {
|
||||
if (Object.keys(account).length == 0) {
|
||||
return 'loggedOut';
|
||||
}
|
||||
return 'loggedIn';
|
||||
},
|
||||
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</dom-module>
|
||||
60
polygerrit-ui/app/elements/gr-account-manager.html
Normal file
60
polygerrit-ui/app/elements/gr-account-manager.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<!--
|
||||
Copyright (C) 2015 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
|
||||
<dom-module id="gr-account-manager">
|
||||
<template>
|
||||
<iron-ajax id="xhr"
|
||||
auto
|
||||
url="/accounts/self/detail"
|
||||
json-prefix=")]}'"></iron-ajax>
|
||||
</template>
|
||||
<script>
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
Polymer({
|
||||
is: 'gr-account-manager',
|
||||
|
||||
hostAttributes: {
|
||||
hidden: true
|
||||
},
|
||||
|
||||
properties: {
|
||||
account: {
|
||||
type: Object,
|
||||
notify: true,
|
||||
},
|
||||
},
|
||||
|
||||
listeners: {
|
||||
'xhr.response': '_handleResponse',
|
||||
'xhr.error': '_handleResponse',
|
||||
},
|
||||
|
||||
_handleResponse: function(e, req) {
|
||||
if (req.status >= 200 && req.status < 300) {
|
||||
this.account = req.response;
|
||||
} else {
|
||||
this.account = {};
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</dom-module>
|
||||
@@ -16,6 +16,8 @@ limitations under the License.
|
||||
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../styles/app-theme.html">
|
||||
<link rel="import" href="gr-account-dropdown.html">
|
||||
<link rel="import" href="gr-account-manager.html">
|
||||
<link rel="import" href="gr-change-list-view.html">
|
||||
<link rel="import" href="gr-change-view.html">
|
||||
<link rel="import" href="gr-diff-view.html">
|
||||
@@ -56,7 +58,7 @@ limitations under the License.
|
||||
.bigTitle:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.searchContainer {
|
||||
.headerRightItems {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
justify-content: flex-end;
|
||||
@@ -64,11 +66,18 @@ limitations under the License.
|
||||
gr-search-bar {
|
||||
width: 500px;
|
||||
}
|
||||
gr-account-dropdown {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
margin-left: var(--default-horizontal-margin);
|
||||
}
|
||||
</style>
|
||||
<gr-account-manager account="{{account}}"></gr-account-manager>
|
||||
<header role="banner">
|
||||
<a href="/" class="bigTitle">PolyGerrit</a>
|
||||
<div class="searchContainer">
|
||||
<div class="headerRightItems">
|
||||
<gr-search-bar value="{{params.query}}" role="search"></gr-search-bar>
|
||||
<gr-account-dropdown account="[[account]]"></gr-account-dropdown>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
@@ -92,6 +101,7 @@ limitations under the License.
|
||||
is: 'gr-app',
|
||||
|
||||
properties: {
|
||||
account: Object,
|
||||
constrained: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
|
||||
@@ -12,18 +12,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"web-component-tester": "*",
|
||||
"iron-test-helpers": "PolymerElements/iron-test-helpers#^1.0",
|
||||
"iron-test-helpers": "PolymerElements/iron-test-helpers#~1.0.6",
|
||||
"test-fixture": "PolymerElements/test-fixture#^1.0.0"
|
||||
"polymer": "Polymer/polymer#^1.2.1",
|
||||
"page": "visionmedia/page.js#~1.6.4",
|
||||
"iron-ajax": "PolymerElements/iron-ajax#~1.0.9",
|
||||
"iron-a11y-keys": "PolymerElements/iron-a11y-keys#~1.0.3",
|
||||
"iron-input": "PolymerElements/iron-input#~1.0.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"web-component-tester": "*",
|
||||
"iron-test-helpers": "PolymerElements/iron-test-helpers#~1.0",
|
||||
"test-fixture": "PolymerElements/test-fixture#^1.0.0",
|
||||
"iron-test-helpers": "PolymerElements/iron-test-helpers#~1.0.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ func handleRESTProxy(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
w.WriteHeader(res.StatusCode)
|
||||
if _, err := io.Copy(w, res.Body); err != nil {
|
||||
log.Println("Error copying response to ResponseWriter:", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user