Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-21 20:20:40 +02:00
Parent 5639033370
révision a4c23dda1f
8 fichiers modifiés avec 27 ajouts et 25 suppressions

Voir le fichier

@ -1,6 +1,7 @@
package model
import (
"encoding/json"
"time"
"github.com/NyaaPantsu/nyaa/config"
@ -102,7 +103,7 @@ type UserUploadsOld struct {
}
type UserSettings struct {
settings map[string]interface{} `json:"settings"`
settings map[string]bool`json:"settings"`
}
func (c UserUploadsOld) TableName() string {
@ -124,19 +125,19 @@ func (u *User) ToJSON() UserJSON {
/* User Settings */
func(s UserSettings) Get(key string) interface{} {
if (s.settings[key] != nil) {
return s.settings[key]
func(s UserSettings) Get(key string) bool {
if val, ok:= s.settings[key]; ok {
return val
} else {
return config.DefaultUserSettings[key]
}
}
func (s UserSettings) GetSettings() {
func (s UserSettings) GetSettings() map[string]bool {
return s.settings
}
func (s UserSettings) Set(key string, val interface{}) {
func (s UserSettings) Set(key string, val bool) {
s.settings[key] = val
}
@ -145,7 +146,8 @@ func (s UserSettings) ToDefault() {
}
func (u User) SaveSettings() {
u.UserSettings , _ = json.Marshal(u.Settings.GetSettings())
byteArray, _ := json.Marshal(u.Settings.GetSettings())
u.UserSettings = string(byteArray[:])
}
func (u User) ParseSettings() {

Voir le fichier

@ -16,7 +16,6 @@ import (
"github.com/NyaaPantsu/nyaa/service/torrent"
"github.com/NyaaPantsu/nyaa/service/user"
"github.com/NyaaPantsu/nyaa/service/user/permission"
form "github.com/NyaaPantsu/nyaa/service/user/form"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/search"
@ -235,6 +234,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id)
messages:= msg.GetMessages(r)
torrentJson := torrent.ToJSON()
uploadForm := NewUploadForm()
@ -243,7 +243,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
uploadForm.Status = torrentJson.Status
uploadForm.WebsiteLink = string(torrentJson.WebsiteLink)
uploadForm.Description = string(torrentJson.Description)
htv := PanelTorrentEdVbs{NewPanelCommonVariables(r), uploadForm, form.NewErrors(), form.NewInfos()}
htv := PanelTorrentEdVbs{NewPanelCommonVariables(r), uploadForm, messages.GetAllErrors(), messages.GetAllInfos()}
err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv)
log.CheckError(err)
}
@ -252,7 +252,6 @@ func TorrentPostEditModPanel(w http.ResponseWriter, r *http.Request) {
var uploadForm UploadForm
id := r.URL.Query().Get("id")
messages := msg.GetMessages(r)
infos := form.NewInfos()
torrent, _ := torrentService.GetTorrentById(id)
if torrent.ID > 0 {
errUp := uploadForm.ExtractEditInfo(r)
@ -310,7 +309,8 @@ func TorrentReportDeleteModPanel(w http.ResponseWriter, r *http.Request) {
}
func TorrentReassignModPanel(w http.ResponseWriter, r *http.Request) {
htv := PanelTorrentReassignVbs{NewPanelCommonVariables(r), ReassignForm{}, form.NewErrors(), form.NewInfos()}
messages := msg.GetMessages(r)
htv := PanelTorrentReassignVbs{NewPanelCommonVariables(r), ReassignForm{}, messages.GetAllErrors(), messages.GetAllInfos()}
err := panelTorrentReassign.ExecuteTemplate(w, "admin_index.html", htv)
log.CheckError(err)
}
@ -318,7 +318,6 @@ func TorrentReassignModPanel(w http.ResponseWriter, r *http.Request) {
func TorrentPostReassignModPanel(w http.ResponseWriter, r *http.Request) {
var rForm ReassignForm
messages := msg.GetMessages(r)
infos := form.NewInfos()
err2 := rForm.ExtractInfo(r)
if err2 != nil {

Voir le fichier

@ -6,6 +6,7 @@ import (
"strconv"
"time"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/db"
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service/captcha"
@ -84,7 +85,7 @@ func UploadPostHandler(w http.ResponseWriter, r *http.Request) {
if len(user.Likings) > 0 { // If we are followed by at least someone
for _, follower := range user.Likings {
follower.ParseSettings() // We need to call it before checking settings
if follower.Settings.Get("notifications.new_torrent"] {
if follower.Settings.Get("notifications.new_torrent") {
T, _, _ := languages.TfuncAndLanguageWithFallback(user.Language, user.Language) // We need to send the notification to every user in their language
notifierService.NotifyUser(&follower, torrent.Identifier(), fmt.Sprintf(T("new_torrent_uploaded"), torrent.Name, user.Username), url.String())

Voir le fichier

@ -1,7 +1,6 @@
package router
import (
"fmt"
"net/http"
"strconv"
@ -198,7 +197,7 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
// Post Registration controller, we do some check on the form here, the rest on user service
func UserRegisterPostHandler(w http.ResponseWriter, r *http.Request) {
b := form.RegistrationForm{}
messages = msg.GetMessages(r)
messages := msg.GetMessages(r)
if !captcha.Authenticate(captcha.Extract(r)) {
messages.AddError("errors", "Wrong captcha!")
@ -255,7 +254,7 @@ func UserVerifyEmailHandler(w http.ResponseWriter, r *http.Request) {
func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
b := form.LoginForm{}
modelHelper.BindValueForm(&b, r)
messages := msg.GetAllErrors()
messages := msg.GetMessages(r)
modelHelper.ValidateForm(&b, &messages)
if !messages.HasErrors() {

Voir le fichier

@ -12,7 +12,6 @@ import (
"github.com/NyaaPantsu/nyaa/service/notifier"
"github.com/NyaaPantsu/nyaa/service/torrent"
"github.com/NyaaPantsu/nyaa/service/user/permission"
"github.com/NyaaPantsu/nyaa/util"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/gorilla/mux"

Voir le fichier

@ -5,6 +5,7 @@ import (
"github.com/NyaaPantsu/nyaa/db"
"github.com/NyaaPantsu/nyaa/model"
formStruct "github.com/NyaaPantsu/nyaa/service/user/form"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"github.com/NyaaPantsu/nyaa/util/modelHelper"
"github.com/NyaaPantsu/nyaa/util/timeHelper"
"github.com/gorilla/context"
@ -62,14 +63,15 @@ func ClearCookie(w http.ResponseWriter) (int, error) {
}
// SetCookieHandler sets the authentication cookie
func SetCookieHandler(w http.ResponseWriter, email string, pass string) (int, error) {
func SetCookieHandler(w http.ResponseWriter, r *http.Request, email string, pass string) (int, error) {
if email == "" || pass == "" {
return http.StatusNotFound, errors.New("No username/password entered")
}
var user model.User
messages := msg.GetMessages(r)
// search by email or username
isValidEmail, _ := formStruct.EmailValidation(email, formStruct.NewErrors())
isValidEmail := formStruct.EmailValidation(email, &messages)
if isValidEmail {
if db.ORM.Where("email = ?", email).First(&user).RecordNotFound() {
return http.StatusNotFound, errors.New("User not found")
@ -104,17 +106,17 @@ func SetCookieHandler(w http.ResponseWriter, email string, pass string) (int, er
}
// RegisterHanderFromForm sets cookie from a RegistrationForm.
func RegisterHanderFromForm(w http.ResponseWriter, registrationForm formStruct.RegistrationForm) (int, error) {
func RegisterHanderFromForm(w http.ResponseWriter, r *http.Request, registrationForm formStruct.RegistrationForm) (int, error) {
username := registrationForm.Username // email isn't set at this point
pass := registrationForm.Password
return SetCookieHandler(w, username, pass)
return SetCookieHandler(w, r, username, pass)
}
// RegisterHandler sets a cookie when user registered.
func RegisterHandler(w http.ResponseWriter, r *http.Request) (int, error) {
var registrationForm formStruct.RegistrationForm
modelHelper.BindValueForm(&registrationForm, r)
return RegisterHanderFromForm(w, registrationForm)
return RegisterHanderFromForm(w, r, registrationForm)
}
// CurrentUser determines the current user from the request or context

Voir le fichier

@ -81,7 +81,8 @@ func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.Use
user.Email = "" // unset email because it will be verified later
user.CreatedAt = time.Now()
// User settings to default
user.ToDefault()
user.Settings.ToDefault()
user.SaveSettings()
// currently unused but needs to be set:
user.ApiToken = ""
user.ApiTokenExpiry = time.Unix(0, 0)
@ -321,7 +322,7 @@ func CreateUserAuthentication(w http.ResponseWriter, r *http.Request) (int, erro
modelHelper.BindValueForm(&form, r)
username := form.Username
pass := form.Password
status, err := SetCookieHandler(w, username, pass)
status, err := SetCookieHandler(w, r, username, pass)
return status, err
}

Voir le fichier

@ -1,7 +1,6 @@
package modelHelper
import (
"fmt"
"github.com/NyaaPantsu/nyaa/util/log"
msg "github.com/NyaaPantsu/nyaa/util/messages"
"net/http"