From ddcb4b9755ea4b48ff748e730bb02f2be363328c Mon Sep 17 00:00:00 2001 From: TANAKA Koichi Date: Sat, 12 Nov 2016 22:44:27 +0900 Subject: [PATCH] Add validation for oauth password flow --- src/main/javascript/view/Oauth2Model.js | 5 +++++ src/main/javascript/view/Oauth2View.js | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/javascript/view/Oauth2Model.js b/src/main/javascript/view/Oauth2Model.js index 4dd71fc6f80..a7ceed420d8 100644 --- a/src/main/javascript/view/Oauth2Model.js +++ b/src/main/javascript/view/Oauth2Model.js @@ -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; diff --git a/src/main/javascript/view/Oauth2View.js b/src/main/javascript/view/Oauth2View.js index e55b53c8d7c..3bdd97fd8ea 100644 --- a/src/main/javascript/view/Oauth2View.js +++ b/src/main/javascript/view/Oauth2View.js @@ -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); + } } }); \ No newline at end of file