mirror of https://github.com/gophish/gophish
Fix to raise error when trying to register a duplicate username (#926)
This corrects a minor error from recent changes in which registering an existing username didn't throw an error.pull/919/merge
parent
405bc5effe
commit
d7810ddd2b
|
@ -41,6 +41,9 @@ var ErrEmptyPassword = errors.New("Password cannot be blank")
|
||||||
// ErrPasswordMismatch is thrown when a user provides passwords that do not match
|
// ErrPasswordMismatch is thrown when a user provides passwords that do not match
|
||||||
var ErrPasswordMismatch = errors.New("Passwords must match")
|
var ErrPasswordMismatch = errors.New("Passwords must match")
|
||||||
|
|
||||||
|
// ErrUsernameTaken is thrown when a user attempts to register a username that is taken.
|
||||||
|
var ErrUsernameTaken = errors.New("Username already taken")
|
||||||
|
|
||||||
// Login attempts to login the user given a request.
|
// Login attempts to login the user given a request.
|
||||||
func Login(r *http.Request) (bool, models.User, error) {
|
func Login(r *http.Request) (bool, models.User, error) {
|
||||||
username, password := r.FormValue("username"), r.FormValue("password")
|
username, password := r.FormValue("username"), r.FormValue("password")
|
||||||
|
@ -63,11 +66,17 @@ func Register(r *http.Request) (bool, error) {
|
||||||
newPassword := r.FormValue("password")
|
newPassword := r.FormValue("password")
|
||||||
confirmPassword := r.FormValue("confirm_password")
|
confirmPassword := r.FormValue("confirm_password")
|
||||||
u, err := models.GetUserByUsername(username)
|
u, err := models.GetUserByUsername(username)
|
||||||
|
// If the given username already exists, throw an error and return false
|
||||||
|
if err == nil {
|
||||||
|
return false, ErrUsernameTaken
|
||||||
|
}
|
||||||
|
|
||||||
// If we have an error which is not simply indicating that no user was found, report it
|
// If we have an error which is not simply indicating that no user was found, report it
|
||||||
if err != nil && err != gorm.ErrRecordNotFound {
|
if err != nil && err != gorm.ErrRecordNotFound {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
u = models.User{}
|
u = models.User{}
|
||||||
// If we've made it here, we should have a valid username given
|
// If we've made it here, we should have a valid username given
|
||||||
// Check that the passsword isn't blank
|
// Check that the passsword isn't blank
|
||||||
|
|
Loading…
Reference in New Issue