Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
akuma06 2017-05-06 22:27:21 +02:00
Parent 45eb38ee87
révision 4182e22262
4 fichiers modifiés avec 9 ajouts et 27 suppressions

Voir le fichier

@ -6,4 +6,5 @@ const (
Environment = "DEVELOPMENT"
// Environment = "PRODUCTION"
WebAddress = "nyaa.pantsu.cat"
AuthTokenExpirationDay = 1000
)

Voir le fichier

@ -35,7 +35,7 @@ var cookieHandler = securecookie.New(
// return userName, nil
// }
func Token(w http.ResponseWriter, r *http.Request) (string, error) {
func Token(r *http.Request) (string, error) {
var token string
cookie, err := r.Cookie("session")
if err != nil {

Voir le fichier

@ -80,7 +80,7 @@ func CreateUser(w http.ResponseWriter, r *http.Request) (int, error) {
return http.StatusInternalServerError, err
}
SendVerificationToUser(user)
status, err = RegisterHandler(w)
status, err = RegisterHandler(w, r)
return status, err
}
@ -113,7 +113,6 @@ func RetrieveUser(r *http.Request, id string) (*model.PublicUser, bool, uint, in
log.Fatal(err.Error())
}
user.Likings = likings
var likingList model.LikingList
var liked []model.User
var likedCount int
@ -183,7 +182,7 @@ func UpdateUser(w http.ResponseWriter, r *http.Request, id string) (*model.User,
}
default:
var form UserForm
modelHelper.BindValueForm(&form, binding.Form)
modelHelper.BindValueForm(&form, r)
log.Debugf("form %+v\n", form)
modelHelper.AssignValue(&user, &form)
}

Voir le fichier

@ -3,47 +3,29 @@ package userService
import (
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/model"
// "github.com/gin-gonic/gin"
"errors"
"net/http"
"github.com/ewhal/nyaa/util/log"
// "github.com/dorajistyle/goyangi/util/crypto"
)
// FindUserByUserName creates a user.
func FindUserByUserName(appID int64, userName string) (model.User, int, error) {
func FindUserByUserName(userName string) (model.User, int, error) {
var user model.User
var err error
// token := c.Request.Header.Get("X-Auth-Token")
if db.ORM.Where("app_id=? and name=?", appID, userName).First(&user).RecordNotFound() {
if db.ORM.Where("name=?", appID, userName).First(&user).RecordNotFound() {
return user, http.StatusUnauthorized, err
}
return user, http.StatusOK, nil
}
// FindOrCreateUser creates a user.
func FindOrCreateUser(appID int64, userName string) (model.User, int, error) {
func FindOrCreateUser(username string) (model.User, int, error) {
var user model.User
var err error
// if len(token) > 0 {
// log.Debug("header token exist.")
// } else {
// token, err = Token(c)
// log.Debug("header token not exist.")
// if err != nil {
// return user, http.StatusUnauthorized, err
// }
// }
log.Debugf("userName : %s\n", userName)
// log.Debugf("Error : %s\n", err.Error())
if db.ORM.Where("app_id=? and name=?", appID, userName).First(&user).RecordNotFound() {
if db.ORM.Where("username=?", username).First(&user).RecordNotFound() {
var user model.User
// return user, http.StatusBadRequest, err
user.Name = userName
// user.Token = token
user.AppID = appID
user.Username = username
log.Debugf("user %+v\n", user)
if db.ORM.Create(&user).Error != nil {
return user, http.StatusBadRequest, errors.New("User is not created.")