Add validation for oauth password flow

This commit is contained in:
TANAKA Koichi
2016-11-12 22:44:27 +09:00
parent 7cdf83a932
commit f2a1caa379
2 changed files with 20 additions and 1 deletions

View File

@@ -38,6 +38,11 @@ SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
validate: function () {
var valid = false;
if (this.get('isPasswordFlow') &&
(!this.get('username'))) {
return false;
}
var scp = this.get('scopes');
var idx = _.findIndex(scp, function (o) {
return o.checked === true;

View File

@@ -9,6 +9,10 @@ SwaggerUi.Views.Oauth2View = Backbone.View.extend({
template: Handlebars.templates.oauth2,
cls: {
error: 'error'
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
@@ -23,10 +27,20 @@ SwaggerUi.Views.Oauth2View = Backbone.View.extend({
},
setUsername: function (e) {
this.model.set('username', $(e.target).val());
var val= $(e.target).val();
this.model.set('username', val);
if (val) {
$(e.target).removeClass(this.cls.error);
}
},
setPassword: function (e) {
this.model.set('password', $(e.target).val());
},
highlightInvalid: function () {
if (!this.model.get('username')) {
this.$el.find('.oauth-username').addClass(this.cls.error);
}
}
});