Пример #1
0
func Register(w http.ResponseWriter, r *http.Request) {

	user := models.User{}

	if r.FormValue("displayName") != "" {
		user.DisplayName = r.FormValue("displayName")
	} else {
		user.DisplayName = "NULL"
	}

	_email := r.FormValue("email")
	if _email != "" {
		user.Email.Scan(_email)
	}

	if r.FormValue("password") != "" {
		user.Password = r.FormValue("password")
	} else {
		user.Password = "******"
	}

	createUserToken(&user)

	if err := repository.CreateUser(&user).Error; err != nil {
		w.WriteHeader(http.StatusForbidden)
		json.NewEncoder(w).Encode(err)
		return
	}

	log.Println(user)

	json.NewEncoder(w).Encode(user)
}
Пример #2
0
func createUserToken(u *models.User) {
	u.Token = strconv.Itoa(int(time.Now().Unix()))
	u.ExpiredTime = time.Now()
}
Пример #3
0
package api_srv_test

import (
	// "fmt"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/triitvn/instagram-go/api/db"
	"github.com/triitvn/instagram-go/api/models"
	"net/url"
	"strconv"
)

var _ = Describe("Photo", func() {
	var (
		u       models.User
		photoId string
	)

	u = models.User{}
	db.Conn.Where(&models.User{}, 1).First(&u)
	u.Token = "123456"
	db.Conn.Save(&u)

	Describe("Get User Photo", func() {
		Context("Success", func() {
			It("User Id must exist", func() {
				response := Request("GET", "/user/1/photos", "")

				Expect(response.Body).Should(ContainSubstring(`https://farm1.staticflickr.com/499/19728341563_3a9d97e5e1_b.jpg`))
			})
		})