Wiiiiiip
Cette révision appartient à :
Parent
32c51a57cb
révision
5639033370
8 fichiers modifiés avec 133 ajouts et 131 suppressions
|
@ -1,13 +0,0 @@
|
||||||
package config
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Here we config the notifications options
|
|
||||||
*/
|
|
||||||
var EnableNotifications = map[string]bool {
|
|
||||||
"new_torrent": true,
|
|
||||||
"new_comment_owner": true,
|
|
||||||
"new_comment_all": true,
|
|
||||||
"new_follower": false,
|
|
||||||
"followed": false,
|
|
||||||
}
|
|
22
config/user_settings.go
Fichier normal
22
config/user_settings.go
Fichier normal
|
@ -0,0 +1,22 @@
|
||||||
|
package config
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Here we config the notifications options
|
||||||
|
* Uses in user model for default setting
|
||||||
|
* Be aware, default values in user update form are
|
||||||
|
* in service/user/form/form_validator.go
|
||||||
|
*/
|
||||||
|
|
||||||
|
var DefaultUserSettings = map[string]bool {
|
||||||
|
"new_torrent": true,
|
||||||
|
"new_torrent_email": false,
|
||||||
|
"new_comment": true,
|
||||||
|
"new_comment_email": false,
|
||||||
|
"new_responses": true,
|
||||||
|
"new_responses_email": false,
|
||||||
|
"new_follower": false,
|
||||||
|
"new_follower_email": false,
|
||||||
|
"followed": false,
|
||||||
|
"followed_email": false,
|
||||||
|
}
|
|
@ -35,7 +35,7 @@ type User struct {
|
||||||
Notifications []Notification `gorm:"ForeignKey:UserID"`
|
Notifications []Notification `gorm:"ForeignKey:UserID"`
|
||||||
|
|
||||||
UnreadNotifications int `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
|
UnreadNotifications int `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
|
||||||
Settings *UserSettings `gorm:"-"` // We don't want to loop every notifications when accessing user unread notif
|
Settings UserSettings `gorm:"-"` // We don't want to load settings everytime, stock it as a string, parse it when needed
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserJSON struct {
|
type UserJSON struct {
|
||||||
|
@ -124,23 +124,32 @@ func (u *User) ToJSON() UserJSON {
|
||||||
|
|
||||||
/* User Settings */
|
/* User Settings */
|
||||||
|
|
||||||
func(s *UserSettings) Get(key string) interface{} {
|
func(s UserSettings) Get(key string) interface{} {
|
||||||
|
if (s.settings[key] != nil) {
|
||||||
return s.settings[key]
|
return s.settings[key]
|
||||||
|
} else {
|
||||||
|
return config.DefaultUserSettings[key]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserSettings) Set(key string, val interface{}) {
|
func (s UserSettings) GetSettings() {
|
||||||
s.settings[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UserSettings) GetSettings() {
|
|
||||||
return s.settings
|
return s.settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) SaveSettings() {
|
func (s UserSettings) Set(key string, val interface{}) {
|
||||||
|
s.settings[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s UserSettings) ToDefault() {
|
||||||
|
s.settings = config.DefaultUserSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u User) SaveSettings() {
|
||||||
u.UserSettings , _ = json.Marshal(u.Settings.GetSettings())
|
u.UserSettings , _ = json.Marshal(u.Settings.GetSettings())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) ParseSettings() {
|
func (u User) ParseSettings() {
|
||||||
if len(u.Settings.GetSettings()) == 0
|
if len(u.Settings.GetSettings()) == 0 && u.UserSettings != "" {
|
||||||
json.Unmarshal([]byte(u.UserSettings), u.Settings)
|
json.Unmarshal([]byte(u.UserSettings), u.Settings)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -251,15 +251,15 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
var uploadForm UploadForm
|
var uploadForm UploadForm
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
err := form.NewErrors()
|
messages := msg.GetMessages(r)
|
||||||
infos := form.NewInfos()
|
infos := form.NewInfos()
|
||||||
torrent, _ := torrentService.GetTorrentById(id)
|
torrent, _ := torrentService.GetTorrentById(id)
|
||||||
if torrent.ID > 0 {
|
if torrent.ID > 0 {
|
||||||
errUp := uploadForm.ExtractEditInfo(r)
|
errUp := uploadForm.ExtractEditInfo(r)
|
||||||
if errUp != nil {
|
if errUp != nil {
|
||||||
err["errors"] = append(err["errors"], "Failed to update torrent!")
|
messages.AddError("errors", "Failed to update torrent!")
|
||||||
}
|
}
|
||||||
if len(err) == 0 {
|
if !messages.HasErrors() {
|
||||||
// update some (but not all!) values
|
// update some (but not all!) values
|
||||||
torrent.Name = uploadForm.Name
|
torrent.Name = uploadForm.Name
|
||||||
torrent.Category = uploadForm.CategoryID
|
torrent.Category = uploadForm.CategoryID
|
||||||
|
@ -269,10 +269,10 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
torrent.Description = uploadForm.Description
|
torrent.Description = uploadForm.Description
|
||||||
torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)
|
torrent.Uploader = nil // GORM will create a new user otherwise (wtf?!)
|
||||||
db.ORM.Save(&torrent)
|
db.ORM.Save(&torrent)
|
||||||
infos["infos"] = append(infos["infos"], "Torrent details updated.")
|
messages.AddInfo("infos", "Torrent details updated.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
htv := PanelTorrentEdVbs{NewPanelCommonVariables(r), uploadForm, err, infos}
|
htv := PanelTorrentEdVbs{NewPanelCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
|
||||||
err_ := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
err_ := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
log.CheckError(err_)
|
log.CheckError(err_)
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,6 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
|
|
||||||
_ = form.NewErrors()
|
|
||||||
_, _ = userService.DeleteComment(id)
|
_, _ = userService.DeleteComment(id)
|
||||||
url, _ := Router.Get("mod_clist").URL()
|
url, _ := Router.Get("mod_clist").URL()
|
||||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||||
|
@ -288,7 +287,6 @@ func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
_ = form.NewErrors()
|
|
||||||
_, _ = torrentService.DeleteTorrent(id)
|
_, _ = torrentService.DeleteTorrent(id)
|
||||||
|
|
||||||
//delete reports of torrent
|
//delete reports of torrent
|
||||||
|
@ -305,7 +303,6 @@ func TorrentReportDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.URL.Query().Get("id")
|
id := r.URL.Query().Get("id")
|
||||||
fmt.Println(id)
|
fmt.Println(id)
|
||||||
idNum, _ := strconv.ParseUint(id, 10, 64)
|
idNum, _ := strconv.ParseUint(id, 10, 64)
|
||||||
_ = form.NewErrors()
|
|
||||||
_, _ = reportService.DeleteTorrentReport(uint(idNum))
|
_, _ = reportService.DeleteTorrentReport(uint(idNum))
|
||||||
|
|
||||||
url, _ := Router.Get("mod_trlist").URL()
|
url, _ := Router.Get("mod_trlist").URL()
|
||||||
|
@ -320,22 +317,22 @@ func TorrentReassignModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func TorrentPostReassignModPanel(w http.ResponseWriter, r *http.Request) {
|
func TorrentPostReassignModPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
var rForm ReassignForm
|
var rForm ReassignForm
|
||||||
err := form.NewErrors()
|
messages := msg.GetMessages(r)
|
||||||
infos := form.NewInfos()
|
infos := form.NewInfos()
|
||||||
|
|
||||||
err2 := rForm.ExtractInfo(r)
|
err2 := rForm.ExtractInfo(r)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err["errors"] = append(err["errors"], err2.Error())
|
messages.ImportFromError("errors", err2)
|
||||||
} else {
|
} else {
|
||||||
count, err2 := rForm.ExecuteAction()
|
count, err2 := rForm.ExecuteAction()
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
err["errors"] = append(err["errors"], "Something went wrong")
|
messages.AddError("errors", "Something went wrong")
|
||||||
} else {
|
} else {
|
||||||
infos["infos"] = append(infos["infos"], fmt.Sprintf("%d torrents updated.", count))
|
messages.AddInfof("infos", "%d torrents updated.", count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
htv := PanelTorrentReassignVbs{NewPanelCommonVariables(r), rForm, err, infos}
|
htv := PanelTorrentReassignVbs{NewPanelCommonVariables(r), rForm, messages.GetAllErrors(), messages.GetAllInfos()}
|
||||||
err_ := panelTorrentReassign.ExecuteTemplate(w, "admin_index.html", htv)
|
err_ := panelTorrentReassign.ExecuteTemplate(w, "admin_index.html", htv)
|
||||||
log.CheckError(err_)
|
log.CheckError(err_)
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func UploadPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10))
|
url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10))
|
||||||
|
|
||||||
if (user.ID > 0 && config.EnableNotifications["new_torrent"]) { // If we are a member and notifications for new torrents are enabled
|
if (user.ID > 0 && config.DefaultUserSettings["new_torrent"]) { // If we are a member and notifications for new torrents are enabled
|
||||||
userService.GetLikings(user) // We populate the liked field for users
|
userService.GetLikings(user) // We populate the liked field for users
|
||||||
if len(user.Likings) > 0 { // If we are followed by at least someone
|
if len(user.Likings) > 0 { // If we are followed by at least someone
|
||||||
for _, follower := range user.Likings {
|
for _, follower := range user.Likings {
|
||||||
|
|
|
@ -25,13 +25,14 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
HomeHandler(w, r)
|
HomeHandler(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
registrationForm := form.RegistrationForm{}
|
registrationForm := form.RegistrationForm{}
|
||||||
modelHelper.BindValueForm(®istrationForm, r)
|
modelHelper.BindValueForm(®istrationForm, r)
|
||||||
registrationForm.CaptchaID = captcha.GetID()
|
registrationForm.CaptchaID = captcha.GetID()
|
||||||
urtv := UserRegisterTemplateVariables{
|
urtv := UserRegisterTemplateVariables{
|
||||||
CommonTemplateVariables: NewCommonVariables(r),
|
CommonTemplateVariables: NewCommonVariables(r),
|
||||||
RegistrationForm: registrationForm,
|
RegistrationForm: registrationForm,
|
||||||
FormErrors: form.NewErrors(),
|
FormErrors: messages.GetAllErrors(),
|
||||||
}
|
}
|
||||||
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", urtv)
|
err := viewRegisterTemplate.ExecuteTemplate(w, "index.html", urtv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,13 +42,20 @@ func UserRegisterFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Getting View User Login
|
// Getting View User Login
|
||||||
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
func UserLoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, errorUser := userService.CurrentUser(r)
|
||||||
|
// User is already connected, redirect to home
|
||||||
|
if errorUser == nil {
|
||||||
|
HomeHandler(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loginForm := form.LoginForm{}
|
loginForm := form.LoginForm{}
|
||||||
modelHelper.BindValueForm(&loginForm, r)
|
modelHelper.BindValueForm(&loginForm, r)
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
ulfv := UserLoginFormVariables{
|
ulfv := UserLoginFormVariables{
|
||||||
CommonTemplateVariables: NewCommonVariables(r),
|
CommonTemplateVariables: NewCommonVariables(r),
|
||||||
LoginForm: loginForm,
|
LoginForm: loginForm,
|
||||||
FormErrors: form.NewErrors(),
|
FormErrors: messages.GetAllErrors(),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", ulfv)
|
err := viewLoginTemplate.ExecuteTemplate(w, "index.html", ulfv)
|
||||||
|
@ -61,33 +69,33 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
T := languages.GetTfuncFromRequest(r)
|
T := languages.GetTfuncFromRequest(r)
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
|
|
||||||
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
||||||
if errorUser == nil {
|
if errorUser == nil {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
follow := r.URL.Query()["followed"]
|
follow := r.URL.Query()["followed"]
|
||||||
unfollow := r.URL.Query()["unfollowed"]
|
unfollow := r.URL.Query()["unfollowed"]
|
||||||
infosForm := form.NewInfos()
|
|
||||||
deleteVar := r.URL.Query()["delete"]
|
deleteVar := r.URL.Query()["delete"]
|
||||||
|
|
||||||
if (deleteVar != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
if (deleteVar != nil) && (userPermission.CurrentOrAdmin(currentUser, userProfile.ID)) {
|
||||||
err := form.NewErrors()
|
|
||||||
_, errUser := userService.DeleteUser(w, currentUser, id)
|
_, errUser := userService.DeleteUser(w, currentUser, id)
|
||||||
if errUser != nil {
|
if errUser != nil {
|
||||||
err["errors"] = append(err["errors"], errUser.Error())
|
messages.ImportFromError("errors", errUser)
|
||||||
}
|
}
|
||||||
htv := UserVerifyTemplateVariables{NewCommonVariables(r), err}
|
htv := UserVerifyTemplateVariables{NewCommonVariables(r), messages.GetAllErrors()}
|
||||||
errorTmpl := viewUserDeleteTemplate.ExecuteTemplate(w, "index.html", htv)
|
errorTmpl := viewUserDeleteTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if errorTmpl != nil {
|
if errorTmpl != nil {
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if follow != nil {
|
if follow != nil {
|
||||||
infosForm["infos"] = append(infosForm["infos"], fmt.Sprintf(string(T("user_followed_msg")), userProfile.Username))
|
messages.AddInfof("infos", string(T("user_followed_msg")), userProfile.Username)
|
||||||
}
|
}
|
||||||
if unfollow != nil {
|
if unfollow != nil {
|
||||||
infosForm["infos"] = append(infosForm["infos"], fmt.Sprintf(string(T("user_unfollowed_msg")), userProfile.Username))
|
messages.AddInfof("infos", string(T("user_unfollowed_msg")), userProfile.Username)
|
||||||
}
|
}
|
||||||
htv := UserProfileVariables{NewCommonVariables(r), &userProfile, infosForm}
|
htv := UserProfileVariables{NewCommonVariables(r), &userProfile, messages.GetAllInfos()}
|
||||||
|
|
||||||
err := viewProfileTemplate.ExecuteTemplate(w, "index.html", htv)
|
err := viewProfileTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,10 +103,7 @@ func UserProfileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{NewCommonVariables(r)})
|
NotFoundHandler(w, r)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,23 +112,22 @@ func UserDetailsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
|
|
||||||
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
userProfile, _, errorUser := userService.RetrieveUserForAdmin(id)
|
||||||
if errorUser == nil && userPermission.CurrentOrAdmin(currentUser, userProfile.ID) {
|
if errorUser == nil && userPermission.CurrentOrAdmin(currentUser, userProfile.ID) {
|
||||||
if userPermission.CurrentOrAdmin(currentUser, userProfile.ID) {
|
if userPermission.CurrentOrAdmin(currentUser, userProfile.ID) {
|
||||||
b := form.UserForm{}
|
b := form.UserForm{}
|
||||||
modelHelper.BindValueForm(&b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
availableLanguages := languages.GetAvailableLanguages()
|
availableLanguages := languages.GetAvailableLanguages()
|
||||||
htv := UserProfileEditVariables{NewCommonVariables(r), &userProfile, b, form.NewErrors(), form.NewInfos(), availableLanguages}
|
htv := UserProfileEditVariables{NewCommonVariables(r), &userProfile, b, messages.GetAllErrors(), messages.GetAllInfos(), availableLanguages}
|
||||||
err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
|
err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{NewCommonVariables(r)})
|
NotFoundHandler(w, r)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,29 +198,30 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Post Registration controller, we do some check on the form here, the rest on user service
|
// Post Registration controller, we do some check on the form here, the rest on user service
|
||||||
func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
b := form.RegistrationForm{}
|
b := form.RegistrationForm{}
|
||||||
err := form.NewErrors()
|
messages = msg.GetMessages(r)
|
||||||
|
|
||||||
if !captcha.Authenticate(captcha.Extract(r)) {
|
if !captcha.Authenticate(captcha.Extract(r)) {
|
||||||
err["errors"] = append(err["errors"], "Wrong captcha!")
|
messages.AddError("errors", "Wrong captcha!")
|
||||||
}
|
}
|
||||||
if len(err) == 0 {
|
if !messages.HasErrors() {
|
||||||
if len(r.PostFormValue("email")) > 0 {
|
if len(r.PostFormValue("email")) > 0 {
|
||||||
_, err = form.EmailValidation(r.PostFormValue("email"), err)
|
form.EmailValidation(r.PostFormValue("email"), &messages)
|
||||||
}
|
}
|
||||||
_, err = form.ValidateUsername(r.PostFormValue("username"), err)
|
form.ValidateUsername(r.PostFormValue("username"), &messages)
|
||||||
if len(err) == 0 {
|
if !messages.HasErrors() {
|
||||||
modelHelper.BindValueForm(&b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
err = modelHelper.ValidateForm(&b, err)
|
modelHelper.ValidateForm(&b, &messages)
|
||||||
if len(err) == 0 {
|
if !messages.HasErrors() {
|
||||||
_, errorUser := userService.CreateUser(w, r)
|
_, errorUser := userService.CreateUser(w, r)
|
||||||
if errorUser != nil {
|
if errorUser != nil {
|
||||||
err["errors"] = append(err["errors"], errorUser.Error())
|
messages.ImportFromError("errors", errorUser)
|
||||||
}
|
}
|
||||||
if len(err) == 0 {
|
if !messages.HasErrors() {
|
||||||
common := NewCommonVariables(r)
|
common := NewCommonVariables(r)
|
||||||
common.User = &model.User{
|
common.User = &model.User{
|
||||||
Email: r.PostFormValue("email"), // indicate whether user had email set
|
Email: r.PostFormValue("email"), // indicate whether user had email set
|
||||||
}
|
}
|
||||||
htv := UserRegisterTemplateVariables{common, b, err}
|
htv := UserRegisterTemplateVariables{common, b, messages.GetAllErrors()}
|
||||||
errorTmpl := viewRegisterSuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
errorTmpl := viewRegisterSuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if errorTmpl != nil {
|
if errorTmpl != nil {
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||||
|
@ -225,25 +230,21 @@ func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(err) > 0 {
|
if messages.HasErrors() {
|
||||||
b.CaptchaID = captcha.GetID()
|
UserRegisterFormHandler(w, r)
|
||||||
htv := UserRegisterTemplateVariables{NewCommonVariables(r), b, err}
|
|
||||||
errorTmpl := viewRegisterTemplate.ExecuteTemplate(w, "index.html", htv)
|
|
||||||
if errorTmpl != nil {
|
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
token := vars["token"]
|
token := vars["token"]
|
||||||
err := form.NewErrors()
|
messages := msg.GetMessages(r)
|
||||||
|
|
||||||
_, errEmail := userService.EmailVerification(token, w)
|
_, errEmail := userService.EmailVerification(token, w)
|
||||||
if errEmail != nil {
|
if errEmail != nil {
|
||||||
err["errors"] = append(err["errors"], errEmail.Error())
|
messages.ImportFromError("errors", errEmail)
|
||||||
}
|
}
|
||||||
htv := UserVerifyTemplateVariables{NewCommonVariables(r), err}
|
htv := UserVerifyTemplateVariables{NewCommonVariables(r), messages.GetAllErrors()}
|
||||||
errorTmpl := viewVerifySuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
errorTmpl := viewVerifySuccessTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if errorTmpl != nil {
|
if errorTmpl != nil {
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||||
|
@ -254,13 +255,14 @@ func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
b := form.LoginForm{}
|
b := form.LoginForm{}
|
||||||
modelHelper.BindValueForm(&b, r)
|
modelHelper.BindValueForm(&b, r)
|
||||||
err := form.NewErrors()
|
messages := msg.GetAllErrors()
|
||||||
err = modelHelper.ValidateForm(&b, err)
|
|
||||||
if len(err) == 0 {
|
modelHelper.ValidateForm(&b, &messages)
|
||||||
|
if !messages.HasErrors() {
|
||||||
_, errorUser := userService.CreateUserAuthentication(w, r)
|
_, errorUser := userService.CreateUserAuthentication(w, r)
|
||||||
if errorUser != nil {
|
if errorUser != nil {
|
||||||
err["errors"] = append(err["errors"], errorUser.Error())
|
messages.ImportFromError("errors", errorUser)
|
||||||
htv := UserLoginFormVariables{NewCommonVariables(r), b, err}
|
htv := UserLoginFormVariables{NewCommonVariables(r), b, messages.GetAllErrors()}
|
||||||
errorTmpl := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
errorTmpl := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
||||||
if errorTmpl != nil {
|
if errorTmpl != nil {
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
||||||
|
@ -271,12 +273,8 @@ func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
http.Redirect(w, r, url.String(), http.StatusSeeOther)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(err) > 0 {
|
if messages.HasErrors() {
|
||||||
htv := UserLoginFormVariables{NewCommonVariables(r), b, err}
|
UserLoginFormHandler(w,r)
|
||||||
errorTmpl := viewLoginTemplate.ExecuteTemplate(w, "index.html", htv)
|
|
||||||
if errorTmpl != nil {
|
|
||||||
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,72 +56,59 @@ func PostCommentHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
|
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
|
|
||||||
if userPermission.NeedsCaptcha(currentUser) {
|
if userPermission.NeedsCaptcha(currentUser) {
|
||||||
userCaptcha := captcha.Extract(r)
|
userCaptcha := captcha.Extract(r)
|
||||||
if !captcha.Authenticate(userCaptcha) {
|
if !captcha.Authenticate(userCaptcha) {
|
||||||
http.Error(w, "bad captcha", 403)
|
messages.AddError("errors", "Bad captcha!")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content := p.Sanitize(r.FormValue("comment"))
|
content := p.Sanitize(r.FormValue("comment"))
|
||||||
|
|
||||||
if strings.TrimSpace(content) == "" {
|
if strings.TrimSpace(content) == "" {
|
||||||
http.Error(w, "comment empty", 406)
|
messages.AddError("errors", "Comment empty!")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
if !messages.HasErrors() {
|
||||||
|
idNum, err := strconv.Atoi(id)
|
||||||
|
|
||||||
idNum, err := strconv.Atoi(id)
|
userID := currentUser.ID
|
||||||
|
comment := model.Comment{TorrentID: uint(idNum), UserID: userID, Content: content, CreatedAt: time.Now()}
|
||||||
|
|
||||||
userID := currentUser.ID
|
err = db.ORM.Create(&comment).Error
|
||||||
comment := model.Comment{TorrentID: uint(idNum), UserID: userID, Content: content, CreatedAt: time.Now()}
|
if err != nil {
|
||||||
|
messages.ImportFromError("errors", err)
|
||||||
err = db.ORM.Create(&comment).Error
|
}
|
||||||
if err != nil {
|
|
||||||
util.SendError(w, err, 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
url, err := Router.Get("view_torrent").URL("id", id)
|
|
||||||
if err == nil {
|
|
||||||
http.Redirect(w, r, url.String(), 302)
|
|
||||||
} else {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
ViewHandler(w,r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id := vars["id"]
|
id := vars["id"]
|
||||||
|
messages := msg.GetMessages(r)
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if userPermission.NeedsCaptcha(currentUser) {
|
if userPermission.NeedsCaptcha(currentUser) {
|
||||||
userCaptcha := captcha.Extract(r)
|
userCaptcha := captcha.Extract(r)
|
||||||
if !captcha.Authenticate(userCaptcha) {
|
if !captcha.Authenticate(userCaptcha) {
|
||||||
http.Error(w, "bad captcha", 403)
|
messages.AddError("errors", "Bad captcha!")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !messages.HasErrors() {
|
||||||
|
idNum, err := strconv.Atoi(id)
|
||||||
|
userID := currentUser.ID
|
||||||
|
|
||||||
idNum, err := strconv.Atoi(id)
|
report := model.TorrentReport{
|
||||||
userID := currentUser.ID
|
Description: r.FormValue("report_type"),
|
||||||
|
TorrentID: uint(idNum),
|
||||||
|
UserID: userID,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
|
||||||
report := model.TorrentReport{
|
err = db.ORM.Create(&report).Error
|
||||||
Description: r.FormValue("report_type"),
|
if err != nil {
|
||||||
TorrentID: uint(idNum),
|
messages.ImportFromError("errors", err)
|
||||||
UserID: userID,
|
}
|
||||||
CreatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = db.ORM.Create(&report).Error
|
|
||||||
if err != nil {
|
|
||||||
util.SendError(w, err, 500)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
url, err := Router.Get("view_torrent").URL("id", id)
|
|
||||||
if err == nil {
|
|
||||||
http.Redirect(w, r, url.String(), 302)
|
|
||||||
} else {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
}
|
||||||
|
ViewHandler(w,r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,8 @@ func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.Use
|
||||||
}
|
}
|
||||||
user.Email = "" // unset email because it will be verified later
|
user.Email = "" // unset email because it will be verified later
|
||||||
user.CreatedAt = time.Now()
|
user.CreatedAt = time.Now()
|
||||||
|
// User settings to default
|
||||||
|
user.ToDefault()
|
||||||
// currently unused but needs to be set:
|
// currently unused but needs to be set:
|
||||||
user.ApiToken = ""
|
user.ApiToken = ""
|
||||||
user.ApiTokenExpiry = time.Unix(0, 0)
|
user.ApiTokenExpiry = time.Unix(0, 0)
|
||||||
|
|
Référencer dans un nouveau ticket