[auth] Added logout button

This commit is contained in:
Anna Bodnia
2016-02-24 18:42:28 +02:00
parent 0644f7611a
commit a50536693c
10 changed files with 122 additions and 34 deletions

View File

@@ -1188,6 +1188,13 @@
text-decoration: underline;
cursor: pointer;
}
.swagger-section .logout__btn {
padding-left: 15px;
}
.swagger-section .logout__btn:hover {
text-decoration: underline;
cursor: pointer;
}
.swagger-section .auth_container .basic_auth__title {
color: #547f00;
font-size: 1.2em;

View File

@@ -1188,6 +1188,13 @@
text-decoration: underline;
cursor: pointer;
}
.swagger-section .logout__btn {
padding-left: 15px;
}
.swagger-section .logout__btn:hover {
text-decoration: underline;
cursor: pointer;
}
.swagger-section .auth_container .basic_auth__title {
color: #547f00;
font-size: 1.2em;

View File

@@ -2,7 +2,8 @@
SwaggerUi.Views.AuthView = Backbone.View.extend({
events: {
'click .authorize__btn': 'authorizeBtnClick'
'click .authorize__btn': 'authorizeBtnClick',
'click .logout__btn' : 'logoutClick'
},
tpls: {
@@ -16,7 +17,7 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
},
render: function () {
this.$el.html(this.tpls.authBtn());
this.$el.html(this.tpls.authBtn(this.model));
return this;
},
@@ -25,7 +26,10 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var authsModel;
e.preventDefault();
authsModel = {title: 'Available authorizations', content: this.renderAuths()};
authsModel = {
title: 'Available authorizations',
content: this.renderAuths()
};
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
this.popup.render();
@@ -36,20 +40,33 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
var el = $('<div>');
//todo refactor, copy-pasted from MainView.js
for (name in this.model) {
auth = this.model[name];
for (name in this.model.auths) {
auth = this.model.auths[name];
if (auth.type === 'apiKey') {
authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el;
el.append(authEl);
}
if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) {
} else if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) {
authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el;
el.append(authEl);
}
}
return el;
},
logoutClick: function (e) {
var authsModel;
e.preventDefault();
authsModel = {
title: 'Logout authorizations'
};
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
this.popup.render();
console.log(window.swaggerUi.api.clientAuthorizations.authz);
}
});

View File

@@ -84,11 +84,16 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
render: function () {
// Render the outer container for resources
var authsModel;
$(this.el).html(Handlebars.templates.main(this.model));
this.model.securityDefinitions = this.model.securityDefinitions || {};
if (this.model.securityDefinitions) {
this.authView = new SwaggerUi.Views.AuthView({model: this.model.securityDefinitions, router: this.router});
if (!_.isEmpty(this.model.securityDefinitions)) {
authsModel = { auths: this.model.securityDefinitions };
authsModel.isLogout = !_.isEmpty(window.swaggerUi.api.clientAuthorizations.authz);
this.authView = new SwaggerUi.Views.AuthView({model: authsModel, router: this.router});
this.$('.authorize-wrapper').append(this.authView.render().el);
}

View File

@@ -30,6 +30,14 @@
}
}
.logout__btn {
padding-left: 15px;
&:hover {
text-decoration: underline;
cursor: pointer;
}
}
.auth_container {
.basic_auth__title {

View File

@@ -1 +1,4 @@
<a class='authorize__btn'>Click to Authorize</a>
{{#if isLogout}}
<a class='logout__btn'>Log out</a>
{{/if}}