From dee08850cf0687d6633da78d4f70ca40ed2fdb61 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Wed, 10 May 2017 22:42:11 +0200 Subject: [PATCH] Fixing --- router/userHandler.go | 6 +++--- service/user/form/formValidator.go | 2 +- service/user/user.go | 11 ++++++++--- service/user/verification.go | 6 ++---- translations/en-us.all.json | 4 ++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/router/userHandler.go b/router/userHandler.go index 67a53d7b..7f72a9b3 100755 --- a/router/userHandler.go +++ b/router/userHandler.go @@ -10,7 +10,6 @@ import ( "github.com/ewhal/nyaa/service/user" "github.com/ewhal/nyaa/service/user/form" "github.com/ewhal/nyaa/service/user/permission" - "github.com/ewhal/nyaa/util/log" "github.com/ewhal/nyaa/util/languages" "github.com/ewhal/nyaa/util/modelHelper" "github.com/gorilla/mux" @@ -147,15 +146,16 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) { b.Username = currentUser.Username } err = modelHelper.ValidateForm(&b, err) - log.Info("lol") if len(err) == 0 { userProfile, _, errorUser = userService.UpdateUser(w, &b, currentUser, id) - log.Infof("xD2") if errorUser != nil { err["errors"] = append(err["errors"], errorUser.Error()) } if len(err) == 0 { infos["infos"] = append(infos["infos"], T("profile_updated")) + if (b.Email != currentUser.Email) { + infos["infos"] = append(infos["infos"], fmt.Sprintf(T("email_changed"), b.Email)) + } } } } diff --git a/service/user/form/formValidator.go b/service/user/form/formValidator.go index 9f93ce7b..10218f64 100644 --- a/service/user/form/formValidator.go +++ b/service/user/form/formValidator.go @@ -65,7 +65,7 @@ type LoginForm struct { // UserForm is used when updating a user. type UserForm struct { Username string `form:"username" needed:"true" len_min:"3" len_max:"20"` - Email string `form:"email" needed:"true"` + Email string `form:"email"` Language string `form:"language" default:"en-us"` CurrentPassword string `form:"current_password" len_min:"6" len_max:"25" omit:"true"` Password string `form:"password" len_min:"6" len_max:"25" equalInput:"Confirm_Password"` diff --git a/service/user/user.go b/service/user/user.go index 9ea26a57..582ab51a 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -98,7 +98,7 @@ func CreateUser(w http.ResponseWriter, r *http.Request) (int, error) { if usernameCandidate != registrationForm.Username { return http.StatusInternalServerError, fmt.Errorf("Username already taken, you can choose: %s", usernameCandidate) } - if CheckEmail(registrationForm.Email) { + if registrationForm.Email != "" && CheckEmail(registrationForm.Email) { return http.StatusInternalServerError, errors.New("email address already in database") } password, err := bcrypt.GenerateFromPassword([]byte(registrationForm.Password), 10) @@ -110,7 +110,9 @@ func CreateUser(w http.ResponseWriter, r *http.Request) (int, error) { if err != nil { return http.StatusInternalServerError, err } - SendVerificationToUser(user, registrationForm.Email) + if (registrationForm.Email != "") { + SendVerificationToUser(user, registrationForm.Email) + } status, err = RegisterHandler(w, r) return status, err } @@ -194,9 +196,12 @@ func UpdateUser(w http.ResponseWriter, form *formStruct.UserForm, currentUser *m form.Status = user.Status form.Username = user.Username } + if (form.Email != user.Email) { + SendVerificationToUser(user, form.Email) + form.Email = user.Email + } log.Debugf("form %+v\n", form) modelHelper.AssignValue(&user, form) - status, err := UpdateUserCore(&user) if err != nil { return user, status, err diff --git a/service/user/verification.go b/service/user/verification.go index bd53357e..619b9193 100644 --- a/service/user/verification.go +++ b/service/user/verification.go @@ -10,7 +10,7 @@ import ( "github.com/ewhal/nyaa/config" "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/model" - //"github.com/ewhal/nyaa/util/email" + "github.com/ewhal/nyaa/util/email" "github.com/ewhal/nyaa/util/timeHelper" "github.com/gorilla/securecookie" "github.com/nicksnyder/go-i18n/i18n" @@ -26,9 +26,7 @@ func SendEmailVerification(to string, token string, locale string) error { } content := T("link") + " : https://" + config.WebAddress + "/verify/email/" + token content_html := T("verify_email_content") + "
" + "" + config.WebAddress + "/verify/email/" + token + "" - //return email.SendEmailFromAdmin(to, T("verify_email_title"), content, content_html) - fmt.Printf("sending email to %s\n----\n%s\n%s\n----\n", to, content, content_html) - return nil + return email.SendEmailFromAdmin(to, T("verify_email_title"), content, content_html) } // SendVerificationToUser sends an email verification token to user. diff --git a/translations/en-us.all.json b/translations/en-us.all.json index 85048181..9d64d9ba 100644 --- a/translations/en-us.all.json +++ b/translations/en-us.all.json @@ -578,5 +578,9 @@ { "id": "mark_as_remake", "translation": "Mark as remake" + }, + { + "id": "email_changed", + "translation": "Email changed successfully! You will have, however, to confirm it by clicking to the link sent to: %s" } ]