From 0ba342ca96d1873c7abd9e90d8c151ba1968a036 Mon Sep 17 00:00:00 2001 From: kunw Date: Mon, 24 Oct 2016 18:37:54 +0800 Subject: [PATCH 1/2] updates for email validations. --- .../components/validator/email.validator.js | 44 +++++++++++++++++++ .../components/validator/validator.config.js | 4 +- src/ui/views/account-settings.htm | 2 +- src/ui/views/forgot-password.htm | 2 +- src/ui/views/sections/script-include.htm | 1 + src/ui/views/sign-up.htm | 5 +-- 6 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 src/ui/static/resources/js/components/validator/email.validator.js diff --git a/src/ui/static/resources/js/components/validator/email.validator.js b/src/ui/static/resources/js/components/validator/email.validator.js new file mode 100644 index 000000000..c7421bfa8 --- /dev/null +++ b/src/ui/static/resources/js/components/validator/email.validator.js @@ -0,0 +1,44 @@ +/* + Copyright (c) 2016 VMware, Inc. All Rights Reserved. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ +(function() { + + 'use strict'; + + angular + .module('harbor.validator') + .directive('email', email); + + email.$inject = ['EMAIL_REGEXP']; + + function email(EMAIL_REGEXP) { + var directive = { + 'require' : 'ngModel', + 'link': link + }; + return directive; + + function link (scope, element, attrs, ctrl) { + + ctrl.$validators.email = validator; + + function validator(modelValue, viewValue) { + + return EMAIL_REGEXP.test(modelValue); + + } + } + } + +})(); \ No newline at end of file diff --git a/src/ui/static/resources/js/components/validator/validator.config.js b/src/ui/static/resources/js/components/validator/validator.config.js index 187f55008..08e892cdc 100644 --- a/src/ui/static/resources/js/components/validator/validator.config.js +++ b/src/ui/static/resources/js/components/validator/validator.config.js @@ -20,5 +20,7 @@ .module('harbor.validator') .constant('INVALID_CHARS', [",","~","#", "$", "%"]) .constant('PASSWORD_REGEXP', /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,20}$/) - .constant('PROJECT_REGEXP', /^[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*$/); + .constant('PROJECT_REGEXP', /^[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*$/) + .constant('EMAIL_REGEXP', /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); + })(); \ No newline at end of file diff --git a/src/ui/views/account-settings.htm b/src/ui/views/account-settings.htm index 7389ca51a..55b7c0d24 100644 --- a/src/ui/views/account-settings.htm +++ b/src/ui/views/account-settings.htm @@ -29,7 +29,7 @@
- +
// 'email_is_required' | tr // // 'email_content_illegal' | tr // diff --git a/src/ui/views/forgot-password.htm b/src/ui/views/forgot-password.htm index 389c981b1..ddbbff452 100644 --- a/src/ui/views/forgot-password.htm +++ b/src/ui/views/forgot-password.htm @@ -24,7 +24,7 @@
- +
// 'email_is_required' | tr // diff --git a/src/ui/views/sections/script-include.htm b/src/ui/views/sections/script-include.htm index f07b60649..02679c8ee 100644 --- a/src/ui/views/sections/script-include.htm +++ b/src/ui/views/sections/script-include.htm @@ -127,6 +127,7 @@ + diff --git a/src/ui/views/sign-up.htm b/src/ui/views/sign-up.htm index 4bae1a5d0..76bb5b7be 100644 --- a/src/ui/views/sign-up.htm +++ b/src/ui/views/sign-up.htm @@ -45,12 +45,11 @@
- -
+ +
// 'email_is_required' | tr // // 'email_content_illegal' | tr // // 'email_has_been_taken' | tr // - // 'email_is_too_long' | tr //

// 'email_desc' | tr //

From dbe830395ddbc7ee4c60e916514bb7d4d7aa0f6c Mon Sep 17 00:00:00 2001 From: kunw Date: Tue, 25 Oct 2016 11:12:23 +0800 Subject: [PATCH 2/2] Fixed log output. --- src/ui/api/user.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/api/user.go b/src/ui/api/user.go index d75ba7d3e..7b023b9dc 100644 --- a/src/ui/api/user.go +++ b/src/ui/api/user.go @@ -23,10 +23,10 @@ import ( "strconv" "strings" + "github.com/vmware/harbor/src/common/api" "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/common/api" ) // UserAPI handles request to /api/users/{} @@ -152,7 +152,7 @@ func (ua *UserAPI) Put() { ua.DecodeJSONReq(&user) err := commonValidate(user) if err != nil { - log.Warning("Bad request in change user profile: %v", err) + log.Warningf("Bad request in change user profile: %v", err) ua.RenderError(http.StatusBadRequest, "change user profile error:"+err.Error()) return } @@ -200,7 +200,7 @@ func (ua *UserAPI) Post() { ua.DecodeJSONReq(&user) err := validate(user) if err != nil { - log.Warning("Bad request in Register: %v", err) + log.Warningf("Bad request in Register: %v", err) ua.RenderError(http.StatusBadRequest, "register error:"+err.Error()) return }