-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By extract user validation into separate file. Also update mocks.
- Loading branch information
1 parent
8fba890
commit c616f9b
Showing
6 changed files
with
33 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package service | ||
|
||
import ( | ||
"github.com/jessicatarra/greenlight/internal/password" | ||
"github.com/jessicatarra/greenlight/internal/utils" | ||
"github.com/jessicatarra/greenlight/ms/auth/domain" | ||
) | ||
|
||
func ValidateUser(input domain.CreateUserRequest, existingUser *domain.User) { | ||
input.Validator.CheckField(input.Name != "", "name", "must be provided") | ||
input.Validator.CheckField(len(input.Name) <= 500, "name", "must not be more than 500 bytes long") | ||
|
||
ValidateEmail(input, existingUser) | ||
|
||
ValidatePassword(input) | ||
} | ||
|
||
func ValidatePassword(input domain.CreateUserRequest) { | ||
input.Validator.CheckField(input.Password != "", "Password", "Password is required") | ||
input.Validator.CheckField(len(input.Password) >= 8, "Password", "Password is too short") | ||
input.Validator.CheckField(len(input.Password) <= 72, "Password", "Password is too long") | ||
input.Validator.CheckField(utils.NotIn(input.Password, password.CommonPasswords...), "Password", "Password is too common") | ||
} | ||
|
||
func ValidateEmail(input domain.CreateUserRequest, existingUser *domain.User) { | ||
input.Validator.CheckField(input.Email != "", "Email", "Email is required") | ||
input.Validator.CheckField(utils.Matches(input.Email, utils.RgxEmail), "Email", "Must be a valid email address") | ||
input.Validator.CheckField(existingUser == nil, "Email", "Email is already in use") | ||
} |