Merge branch 'master' of github.com:ewhal/nyaa
Cette révision appartient à :
révision
c0e2eaa56a
12 fichiers modifiés avec 65 ajouts et 46 suppressions
|
@ -138,7 +138,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
UploaderName: util.SafeText(uploader),
|
||||
OldUploader: util.SafeText(t.OldUploader),
|
||||
WebsiteLink: util.Safe(t.WebsiteLink),
|
||||
Magnet: util.Safe(magnet),
|
||||
Magnet: template.URL(magnet),
|
||||
TorrentLink: util.Safe(torrentlink)}
|
||||
|
||||
return res
|
||||
|
|
|
@ -28,6 +28,7 @@ type UploadForm struct {
|
|||
Name string
|
||||
Magnet string
|
||||
Category string
|
||||
Remake bool
|
||||
Description string
|
||||
captcha.Captcha
|
||||
|
||||
|
@ -40,19 +41,12 @@ type UploadForm struct {
|
|||
|
||||
// TODO: these should be in another package (?)
|
||||
|
||||
// form value for torrent name
|
||||
// form names
|
||||
const UploadFormName = "name"
|
||||
|
||||
// form value for torrent file
|
||||
const UploadFormTorrent = "torrent"
|
||||
|
||||
// form value for magnet uri (?)
|
||||
const UploadFormMagnet = "magnet"
|
||||
|
||||
// form value for category
|
||||
const UploadFormCategory = "c"
|
||||
|
||||
// form value for description
|
||||
const UploadFormRemake = "remake"
|
||||
const UploadFormDescription = "desc"
|
||||
|
||||
// error indicating that you can't send both a magnet link and torrent
|
||||
|
@ -84,6 +78,7 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
f.Category = r.FormValue(UploadFormCategory)
|
||||
f.Description = r.FormValue(UploadFormDescription)
|
||||
f.Magnet = r.FormValue(UploadFormMagnet)
|
||||
f.Remake = r.FormValue(UploadFormRemake) == "on"
|
||||
f.Captcha = captcha.Extract(r)
|
||||
|
||||
if !captcha.Authenticate(f.Captcha) {
|
||||
|
|
|
@ -33,12 +33,18 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
fmt.Printf("error %+v\n", err)
|
||||
}
|
||||
status := 1 // normal
|
||||
if uploadForm.Remake { // overrides trusted
|
||||
status = 2
|
||||
} else if user.Status == 1 {
|
||||
status = 3 // mark as trusted if user is trusted
|
||||
}
|
||||
//add to db and redirect depending on result
|
||||
torrent := model.Torrent{
|
||||
Name: uploadForm.Name,
|
||||
Category: uploadForm.CategoryID,
|
||||
SubCategory: uploadForm.SubCategoryID,
|
||||
Status: 1,
|
||||
Status: status,
|
||||
Hash: uploadForm.Infohash,
|
||||
Date: time.Now(),
|
||||
Filesize: uploadForm.Filesize,
|
||||
|
|
|
@ -3,6 +3,7 @@ package router
|
|||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ewhal/nyaa/db"
|
||||
|
@ -40,6 +41,10 @@ func PostCommentHandler(w http.ResponseWriter, r *http.Request) {
|
|||
vars := mux.Vars(r)
|
||||
id := vars["id"]
|
||||
|
||||
if strings.TrimSpace(r.FormValue("comment")) == "" {
|
||||
http.Error(w, "comment empty", 406)
|
||||
}
|
||||
|
||||
userCaptcha := captcha.Extract(r)
|
||||
if !captcha.Authenticate(userCaptcha) {
|
||||
http.Error(w, "bad captcha", 403)
|
||||
|
|
|
@ -85,7 +85,6 @@ func ClearCookie(w http.ResponseWriter) (int, error) {
|
|||
// SetCookieHandler sets a cookie with email and password.
|
||||
func SetCookieHandler(w http.ResponseWriter, email string, pass string) (int, error) {
|
||||
if email != "" && pass != "" {
|
||||
log.Debugf("User email : %s , password : %s", email, pass)
|
||||
var user model.User
|
||||
isValidEmail, _ := formStruct.EmailValidation(email, formStruct.NewErrors())
|
||||
if isValidEmail {
|
||||
|
@ -115,14 +114,9 @@ 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) {
|
||||
email := registrationForm.Email
|
||||
if email == "" {
|
||||
email = registrationForm.Username
|
||||
}
|
||||
username := registrationForm.Username // email isn't set at this point
|
||||
pass := registrationForm.Password
|
||||
log.Debugf("RegisterHandler UserEmail : %s", email)
|
||||
log.Debugf("RegisterHandler UserPassword : %s", pass)
|
||||
return SetCookieHandler(w, email, pass)
|
||||
return SetCookieHandler(w, username, pass)
|
||||
}
|
||||
|
||||
// RegisterHandler sets a cookie when user registered.
|
||||
|
|
|
@ -62,6 +62,7 @@ func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.Use
|
|||
if user.Email == "" {
|
||||
user.MD5 = ""
|
||||
} else {
|
||||
// Despite the email not being verified yet we calculate this for convenience reasons
|
||||
var err error
|
||||
user.MD5, err = crypto.GenerateMD5Hash(user.Email)
|
||||
if err != nil {
|
||||
|
@ -72,6 +73,7 @@ func CreateUserFromForm(registrationForm formStruct.RegistrationForm) (model.Use
|
|||
if err != nil {
|
||||
return user, errors.New("token not generated")
|
||||
}
|
||||
user.Email = "" // unset email because it will be verified later
|
||||
|
||||
user.Token = token
|
||||
user.TokenExpiration = timeHelper.FewDaysLater(config.AuthTokenExpirationDay)
|
||||
|
@ -108,7 +110,7 @@ func CreateUser(w http.ResponseWriter, r *http.Request) (int, error) {
|
|||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
SendVerificationToUser(user)
|
||||
SendVerificationToUser(user, registrationForm.Email)
|
||||
status, err = RegisterHandler(w, r)
|
||||
return status, err
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ import (
|
|||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
// "github.com/ewhal/nyaa/util/crypto"
|
||||
"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"
|
||||
|
@ -27,43 +26,30 @@ 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)
|
||||
//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
|
||||
}
|
||||
|
||||
// SendVerificationToUser sends an email verification token to user.
|
||||
func SendVerificationToUser(user model.User) (int, error) {
|
||||
func SendVerificationToUser(user model.User, newEmail string) (int, error) {
|
||||
validUntil := timeHelper.TwentyFourHoursLater() // TODO: longer duration?
|
||||
value := map[string]string{
|
||||
"t": strconv.FormatInt(validUntil.Unix(), 10),
|
||||
"u": strconv.FormatUint(uint64(user.ID), 10),
|
||||
"e": user.Email,
|
||||
"e": newEmail,
|
||||
}
|
||||
encoded, err := verificationHandler.Encode("", value)
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
err = SendEmailVerification(user.Email, encoded, "en-us")
|
||||
err = SendEmailVerification(newEmail, encoded, "en-us")
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
// SendVerification sends an email verification token.
|
||||
func SendVerification(r *http.Request) (int, error) {
|
||||
var user model.User
|
||||
currentUser, err := CurrentUser(r)
|
||||
if err != nil {
|
||||
return http.StatusUnauthorized, errors.New("unauthorized")
|
||||
}
|
||||
if db.ORM.First(&user, currentUser.ID).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("user not found")
|
||||
}
|
||||
status, err := SendVerificationToUser(user)
|
||||
return status, err
|
||||
}
|
||||
|
||||
// EmailVerification verifies the token used for email verification
|
||||
func EmailVerification(token string, w http.ResponseWriter) (int, error) {
|
||||
value := make(map[string]string)
|
||||
|
|
|
@ -58,6 +58,9 @@ http://tracker.baka-sub.cf/announce</pre>
|
|||
<h2>{{T "why_written_in_go"}}</h2>
|
||||
<p>{{T "authors_favorite_language"}}</p>
|
||||
|
||||
<h2>{{T "who_is_renchon"}}</h2>
|
||||
<p>{{T "renchon_anon_explanation" }}</p>
|
||||
|
||||
<br />
|
||||
|
||||
<img style="max-width: 100%" src="https://my.mixtape.moe/omrskw.png" alt="funny meme">
|
||||
|
|
|
@ -40,7 +40,10 @@
|
|||
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>{{T "software_applications"}}</option>
|
||||
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>{{T "software_games"}}</option>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="checkbox" name="remake">
|
||||
<label for="remake">{{T "mark_as_remake"}}</label>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
<a style="margin: 5px;" aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-lg btn-success download-btn">
|
||||
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
|
||||
</a>
|
||||
<a style="margin: 5px;" aria-label="Report button" href="{{.TorrentLink}}" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger btn-lg download-btn">
|
||||
{{end}}
|
||||
<a style="margin: 5px;" aria-label="Report button" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger btn-lg">
|
||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Report!
|
||||
</a> {{end}}
|
||||
</a>
|
||||
|
||||
{{ if HasAdmin $.User}}
|
||||
<a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a>
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
},
|
||||
{
|
||||
"id":"confirm_password",
|
||||
"translation": "Bestätige dein Passwort"
|
||||
"translation": "Passwort-Bestätigung"
|
||||
},
|
||||
{
|
||||
"id":"i_agree",
|
||||
|
@ -317,7 +317,7 @@
|
|||
},
|
||||
{
|
||||
"id": "answer_how_can_i_help",
|
||||
"translation": "Wenn du Erfahrungen mit Webseitenprogrammierung hast, kannst du dem IRC-Kanal #nyaapantsu auf irc.rizon.net(Englisch) beitreten. Wenn du irgendwelche Datenbanken hast, insbesondere für Sukebei, <b>LAD SIE HOCH</b>."
|
||||
"translation": "Wenn du Erfahrungen mit Webseitenprogrammierung hast, kannst du dem IRC-Kanal #nyaapantsu auf irc.rizon.net (Englisch) beitreten. Wenn du irgendwelche Datenbanken hast, insbesondere für Sukebei, <b>LAD SIE HOCH</b>."
|
||||
},
|
||||
{
|
||||
"id": "your_design_sucks_found_a_bug",
|
||||
|
@ -325,7 +325,7 @@
|
|||
},
|
||||
{
|
||||
"id": "why_written_in_go",
|
||||
"translation": "Warum in Gottesnamen ist eurer Code in Go geschrieben?"
|
||||
"translation": "Warum in Gottes Namen ist eurer Code in Go geschrieben?"
|
||||
},
|
||||
{
|
||||
"id": "authors_favorite_language",
|
||||
|
@ -562,5 +562,13 @@
|
|||
{
|
||||
"id": "delete_success",
|
||||
"translation": "Dein Profil wurde erfolgreich gelöscht!"
|
||||
},
|
||||
{
|
||||
"id": "moderation",
|
||||
"translation": "Moderation"
|
||||
},
|
||||
{
|
||||
"id": "mark_as_remake",
|
||||
"translation": "Als Remake markieren"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -562,5 +562,21 @@
|
|||
{
|
||||
"id": "delete_success",
|
||||
"translation": "The account has been successfully deleted!"
|
||||
},
|
||||
{
|
||||
"id": "moderation",
|
||||
"translation": "Moderation"
|
||||
},
|
||||
{
|
||||
"id": "who_is_renchon",
|
||||
"translation": "Who the fuck is れんちょん?"
|
||||
},
|
||||
{
|
||||
"id": "renchon_anon_explanation",
|
||||
"translation": "れんちょん is the username assigned to uploads and comments made anonymously. It is also used for torrent imported from the original nyaa, though the original uploader may be displayed alongside."
|
||||
},
|
||||
{
|
||||
"id": "mark_as_remake",
|
||||
"translation": "Mark as remake"
|
||||
}
|
||||
]
|
||||
|
|
Référencer dans un nouveau ticket