Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-10 22:42:11 +02:00
Parent 3acb410af7
révision dee08850cf
5 fichiers modifiés avec 18 ajouts et 11 suppressions

Voir le fichier

@ -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))
}
}
}
}

Voir le fichier

@ -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"`

Voir le fichier

@ -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

Voir le fichier

@ -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") + "<br/>" + "<a href=\"https://" + config.WebAddress + "/verify/email/" + token + "\" target=\"_blank\">" + config.WebAddress + "/verify/email/" + token + "</a>"
//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.

Voir le fichier

@ -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"
}
]