Add validation for oauth password flow
This commit is contained in:
@@ -38,6 +38,11 @@ SwaggerUi.Models.Oauth2Model = Backbone.Model.extend({
|
|||||||
|
|
||||||
validate: function () {
|
validate: function () {
|
||||||
var valid = false;
|
var valid = false;
|
||||||
|
if (this.get('isPasswordFlow') &&
|
||||||
|
(!this.get('username'))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var scp = this.get('scopes');
|
var scp = this.get('scopes');
|
||||||
var idx = _.findIndex(scp, function (o) {
|
var idx = _.findIndex(scp, function (o) {
|
||||||
return o.checked === true;
|
return o.checked === true;
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ SwaggerUi.Views.Oauth2View = Backbone.View.extend({
|
|||||||
|
|
||||||
template: Handlebars.templates.oauth2,
|
template: Handlebars.templates.oauth2,
|
||||||
|
|
||||||
|
cls: {
|
||||||
|
error: 'error'
|
||||||
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
this.$el.html(this.template(this.model.toJSON()));
|
this.$el.html(this.template(this.model.toJSON()));
|
||||||
|
|
||||||
@@ -23,10 +27,20 @@ SwaggerUi.Views.Oauth2View = Backbone.View.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setUsername: function (e) {
|
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) {
|
setPassword: function (e) {
|
||||||
this.model.set('password', $(e.target).val());
|
this.model.set('password', $(e.target).val());
|
||||||
|
},
|
||||||
|
|
||||||
|
highlightInvalid: function () {
|
||||||
|
if (!this.model.get('username')) {
|
||||||
|
this.$el.find('.oauth-username').addClass(this.cls.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user