[auth] moved logout buttons into authentication view

This commit is contained in:
Anna Bodnia
2016-03-03 12:18:27 +02:00
parent 491802a6a1
commit 1861ac27ca
11 changed files with 1122 additions and 7256 deletions

7
dist/css/print.css vendored
View File

@@ -1188,13 +1188,6 @@
text-decoration: underline; text-decoration: underline;
cursor: pointer; 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 { .swagger-section .auth_container .basic_auth__title {
color: #547f00; color: #547f00;
font-size: 1.2em; font-size: 1.2em;

7
dist/css/screen.css vendored
View File

@@ -1188,13 +1188,6 @@
text-decoration: underline; text-decoration: underline;
cursor: pointer; 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 { .swagger-section .auth_container .basic_auth__title {
color: #547f00; color: #547f00;
font-size: 1.2em; font-size: 1.2em;

8141
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1188,13 +1188,6 @@
text-decoration: underline; text-decoration: underline;
cursor: pointer; 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 { .swagger-section .auth_container .basic_auth__title {
color: #547f00; color: #547f00;
font-size: 1.2em; font-size: 1.2em;

View File

@@ -1188,13 +1188,6 @@
text-decoration: underline; text-decoration: underline;
cursor: pointer; 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 { .swagger-section .auth_container .basic_auth__title {
color: #547f00; color: #547f00;
font-size: 1.2em; font-size: 1.2em;

View File

@@ -2,8 +2,7 @@
SwaggerUi.Views.AuthView = Backbone.View.extend({ SwaggerUi.Views.AuthView = Backbone.View.extend({
events: { events: {
'click .authorize__btn': 'authorizeBtnClick', 'click .authorize__btn': 'authorizeBtnClick'
'click .logout__btn' : 'logoutClick'
}, },
tpls: { tpls: {
@@ -36,61 +35,30 @@ SwaggerUi.Views.AuthView = Backbone.View.extend({
}, },
renderAuths: function (auths) { renderAuths: function (auths) {
var name, authEl, auth; var name, authEl, authModel;
var el = $('<div>'); var el = $('<div>');
var authz = window.swaggerUi.api.clientAuthorizations.authz;
//todo refactor, copy-pasted from MainView.js
for (name in auths) { for (name in auths) {
auth = auths[name]; authModel = _.extend({}, auths[name]);
if (auth.type === 'apiKey') { if (authz[name]) {
authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el; _.extend(authModel, {
isLogout: true,
value: authz[name].value
});
}
if (authModel.type === 'apiKey') {
authEl = new SwaggerUi.Views.ApiKeyButton({model: authModel, router: this.router}).render().el;
el.append(authEl); el.append(authEl);
} else if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) { } else if (authModel.type === 'basic' && el.find('.basic_auth_container').length === 0) {
authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el; authEl = new SwaggerUi.Views.BasicAuthButton({model: authModel, router: this.router}).render().el;
el.append(authEl); el.append(authEl);
} }
} }
return el; return el;
},
logoutClick: function (e) {
var authsModel;
e.preventDefault();
authsModel = {
title: 'Logout authorizations',
content: this.renderAuths(this.getAuthMap())
};
this.popup = new SwaggerUi.Views.PopupView({model: authsModel});
this.popup.render();
},
getAuthMap: function () {
var authsMap = {};
_.forEach(window.swaggerUi.api.clientAuthorizations.authz, function (value, key) {
if (key === 'basic') {
authsMap.basic = {
type: key,
isLogout: true,
name: key
};
} else {
authsMap[key] = {
type: 'apiKey',
'in': value.type,
value: value.value,
isLogout: true,
name: key
};
}
});
return authsMap;
} }
}); });

View File

@@ -25,7 +25,7 @@ SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({
event.preventDefault(); event.preventDefault();
var username = this.$('.basic_auth__username').val(); var username = this.$('.basic_auth__username').val();
var password = this.$('.basic_auth__password').val(); var password = this.$('.basic_auth__password').val();
var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password); var basicAuth = new SwaggerClient.PasswordAuthorization(username, password);
this.router.api.clientAuthorizations.add(this.model.type, basicAuth); this.router.api.clientAuthorizations.add(this.model.type, basicAuth);
this.router.load(); this.router.load();
}, },

View File

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

View File

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

View File

@@ -14,8 +14,6 @@
{{/if}} {{/if}}
</div> </div>
<div class='container' id='resources_container'> <div class='container' id='resources_container'>
<div class="auth_main_container"></div>
<div class='authorize-wrapper'></div> <div class='authorize-wrapper'></div>
<ul id='resources'></ul> <ul id='resources'></ul>