Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-06 22:14:02 +02:00
Parent 773ce60848
révision 30a53a79ec
8 fichiers modifiés avec 26 ajouts et 16 suppressions

6
config/user.go Fichier normal
Voir le fichier

@ -0,0 +1,6 @@
package config
// Constants for public models.
const (
UserPublicFields = "id, username, md5, description, created_at, liking_count, liked_count"
)

7
model/language.go Fichier normal
Voir le fichier

@ -0,0 +1,7 @@
package model
// Language is a language model.
type Language struct {
Id uint `json:"id"`
Name string `json:"name"`
}

Voir le fichier

@ -43,6 +43,7 @@ type User struct {
Liked []User `gorm:"foreignkey:follower_id;associationforeignkey:userId;many2many:users_followers;"`
Connections []Connection
Languages []Language `gorm:"many2many:user_languages;"` // Many To Many, user_languages is the join table
Roles []Role `gorm:"many2many:users_roles;"` // Many To Many, users_roles
Torrents []Torrents
}
@ -76,6 +77,7 @@ type PublicUser struct {
CurrentLoginIp omit `json:"currentLoginIp,omitempty",sql:"size:100"`
Connections omit `json:"connections,omitempty"`
Languages omit `json:"languages,omitempty"`
Roles omit `json:"roles,omitempty"`
Torrents omit `json:"articles,omitempty"`
}

Voir le fichier

@ -37,8 +37,7 @@ var cookieHandler = securecookie.New(
func Token(w http.ResponseWriter, r *http.Request) (string, error) {
var token string
request := c.Request
cookie, err := request.Cookie("session")
cookie, err := r.Cookie("session")
if err != nil {
return token, err
}
@ -141,7 +140,7 @@ func CurrentUser(r *http.Request) (model.User, error) {
if len(token) > 0 {
log.Debug("header token exist.")
} else {
token, err = Token(c)
token, err = Token(r)
log.Debug("header token not exist.")
if err != nil {
return user, err

Voir le fichier

@ -106,7 +106,7 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in
var likings []model.User
var likingCount int
db.ORM.Table("users_followers").Where("users_followers.user_id=?", user.Id).Count(&likingCount)
if err = db.ORM.Limit(config.LikingPerPage).Order(config.LikingOrder).Offset(offset).Select(config.UserPublicFields).
if err = db.ORM.Order("created_at desc").Select(config.UserPublicFields).
Joins("JOIN users_followers on users_followers.user_id=?", user.Id).
Where("users.id = users_followers.follower_id").
Group("users.id").Find(&likings).Error; err != nil {
@ -118,7 +118,7 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in
var liked []model.User
var likedCount int
db.ORM.Table("users_followers").Where("users_followers.follower_id=?", user.Id).Count(&likedCount)
if err = db.ORM.Limit(config.LikedPerPage).Order(config.LikedOrder).Offset(offset).Select(config.UserPublicFields).
if err = db.ORM.Order("created_at desc").Select(config.UserPublicFields).
Joins("JOIN users_followers on users_followers.follower_id=?", user.Id).
Where("users.id = users_followers.user_id").
Group("users.id").Find(&liked).Error; err != nil {
@ -316,7 +316,6 @@ func RetrieveUsersForAdmin() []model.User {
// ActivateUser toggle activation of a user.
func ActivateUser(r *http.Request, id string) (model.User, int, error) {
id := c.Params.ByName("id")
var user model.User
var form ActivateForm
modelHelper.BindValueForm(&form, r)

Voir le fichier

@ -1,7 +1,7 @@
package userService
import (
"github.com/ewhalnyaa/db"
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/model"
// "github.com/gin-gonic/gin"
"errors"

Voir le fichier

@ -2,6 +2,7 @@ package crypto
import (
"crypto/md5"
"crypto/rand"
"fmt"
"strings"
)

Voir le fichier

@ -11,11 +11,11 @@ import (
type EmailError error
var (
mailer = InitGomail()
mailer = InitGomail()
)
func InitGomail() *gomail.Mailer {
mailer := gomail.NewDialer(config.EmailHost, config.EmailUsername, config.EmailPassword, config.EmailPort)
func InitGomail() *gomail.Dialer {
mailer := gomail.NewDialer(config.EmailHost, config.EmailPort, config.EmailUsername, config.EmailPassword)
return mailer
}
@ -51,12 +51,8 @@ func SendTestEmail() error {
if err != nil {
panic(err)
}
f, err := gomail.OpenFile(path)
if err != nil {
panic(err)
}
msg.Attach(f)
msg.Attach(path)
// SendEmail(msg)
err := mailer.DialAndSend(msg);
err := mailer.DialAndSend(msg)
return err
}