Skip to content

Commit

Permalink
Add validation for oauth password flow
Browse files Browse the repository at this point in the history
  • Loading branch information
MugeSo committed Nov 12, 2016
1 parent 561eb3c commit ddcb4b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/javascript/view/Oauth2Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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;
Expand Down
16 changes: 15 additions & 1 deletion src/main/javascript/view/Oauth2View.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand All @@ -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);
}
}
});

0 comments on commit ddcb4b9

Please sign in to comment.