示例#1
0
func SetupDB() *sql.DB {
	dbConfig, err := utility.LoadPage("article/dbconfig")
	utility.ShitAppend(err)
	DB, err := sql.Open("postgres", string(dbConfig.Body))
	utility.ShitAppend(err)
	return DB
}
示例#2
0
func FindFish(name string) []Fish {
	var count int
	err := db.QueryRow("SELECT COUNT(*) FROM fish WHERE type = $1", name).Scan(&count)
	utility.ShitAppend(err)

	fishes := make([]Fish, count)

	for loop := 0; loop <= count-1; loop++ {
		//fishes := append(fishes, Fish{})
		err := db.QueryRow("SELECT * FROM fish WHERE type = $1", name).Scan(
			&fishes[loop].Id,
			&fishes[loop].Type,
			&fishes[loop].Username,
			&fishes[loop].Weight,
			&fishes[loop].Length,
			&fishes[loop].Location,
			&fishes[loop].Date,
			&fishes[loop].Lure,
			&fishes[loop].Info,
			&fishes[loop].Picture)

		if fishes[loop].Picture == "" {
			fishes[loop].Picture = "img/fish/" + fishes[loop].Type + ".jpg"
		}
		utility.ShitAppend(err)
	}

	return fishes
}
示例#3
0
func HomeHandler(rw http.ResponseWriter, req *http.Request) {
	fishes := make([]Fish, 20)

	var cookie, er = req.Cookie("fishme")
	if er != nil {
		http.Redirect(rw, req, "/", http.StatusFound)
	} else {
		cookieVal := cookie.Value
		var count int
		err := db.QueryRow("SELECT COUNT(*) FROM fish WHERE username = $1", cookieVal).Scan(&count)
		utility.ShitAppend(err)
		for loop := 0; loop <= count-1; loop++ {
			//fishes := append(fishes, make(Fish{}))
			err := db.QueryRow("SELECT * FROM fish WHERE username = $1 LIMIT 1 OFFSET $2", cookieVal, loop).Scan(
				&fishes[loop].Id,
				&fishes[loop].Type,
				&fishes[loop].Username,
				&fishes[loop].Weight,
				&fishes[loop].Length,
				&fishes[loop].Location,
				&fishes[loop].Date,
				&fishes[loop].Lure,
				&fishes[loop].Info,
				&fishes[loop].Picture)

			if fishes[loop].Picture == "" {
				fishes[loop].Picture = "img/fish/" + fishes[loop].Type + ".jpg"
			}

			utility.ShitAppend(err)
		}

		fishes = fishes[0:count]
		sort.Sort(ById(fishes))

		temp, err := template.ParseFiles("template/home.html") // Parse the home.html file
		utility.ShitAppend(err)

		userId := "{{define \"userId\"}}" + cookie.Value + "{{end}}" // Create a template on the fly to get the username with the cookie value

		temp = template.Must(temp.Parse(ParseNavbarFile("template/navbar"))) // Add The content of the navbar.tmpl to the current template
		temp = template.Must(temp.Parse(userId))                             // Same as above but for userId
		temp = template.Must(temp.ParseFiles("template/add_fish.tmpl"))      // Add Fish modal
		temp = template.Must(temp.ParseFiles("template/map.tmpl"))           // Map template

		temp.Execute(rw, ParseFishFile(fishes)) // Execute the template and push it to the ResponseWrite

	}

}
示例#4
0
func FindHandler(rw http.ResponseWriter, req *http.Request) {
	var _, er = req.Cookie("fishme")

	if er != nil {
		http.Redirect(rw, req, "/", http.StatusFound)
	} else {
		term := req.FormValue("find")
		if term != "" {
			term = strings.ToLower(term)
			term = strings.Replace(term, term[:1], strings.ToUpper(term[:1]), 1)
			log.Println(term)

			temp, err := template.ParseFiles("template/find.html")
			utility.ShitAppend(err)

			temp = template.Must(temp.Parse(ParseNavbarFile("template/navbar"))) // Add The content of the navbar.tmpl to the current template
			temp = template.Must(temp.ParseFiles("template/add_fish.tmpl"))
			temp = template.Must(temp.ParseFiles("template/map.tmpl")) // Map template

			fishFind := FindFish(term)

			temp.Execute(rw, ParseSecureFishFile(fishFind))
		} else {
			http.Redirect(rw, req, "/home", http.StatusFound)
		}

	}
}
示例#5
0
文件: resize.go 项目: squiidz/fishMe
func ResizeGif(pic string) {
	// open the Picture
	file, err := os.Open(pic)
	utility.ShitAppend(err)

	img, err := gif.Decode(file)
	utility.ShitAppend(err)
	file.Close()

	// Resize the Picture Data
	m := resize.Resize(565, 363, img, resize.Lanczos3)

	out, err := os.Create(pic)
	utility.ShitAppend(err)
	defer out.Close()

	// OverWrite the None Resizing Picture
	gif.Encode(out, m, nil)
}
示例#6
0
func AddUser(rw http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {

		user := User{
			Username: strings.ToLower(req.FormValue("username")),
			Email:    req.FormValue("email"),
			Password: req.FormValue("password"),
			Date:     time.Now()}

		var userCheck, mailCheck string

		err := db.QueryRow("SELECT username, email FROM users WHERE username = $1 AND email= $2", user.Username, user.Email).Scan(&userCheck, &mailCheck)
		utility.ShitAppend(err)
		if userCheck != "" || mailCheck != "" {
			http.Redirect(rw, req, "/", http.StatusFound)

		} else {
			rows, erro := db.Query("INSERT INTO users(username, email, password, date) VALUES($1, $2, $3, $4)",
				user.Username,
				user.Email,
				user.Password,
				user.Date)

			utility.ShitAppend(erro)
			defer rows.Close()
			utility.Mkdir("img/users/" + user.Username)
			timeNow := time.Now().Format(time.RFC822)
			_, er := db.Query("INSERT INTO fish(type, username, weight, length, location, date, lure, info, picture) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
				"Goldfish",
				user.Username,
				0.2,
				1.2,
				"Toilette",
				timeNow,
				"Net",
				"Just the Beginning !",
				"")
			utility.ShitAppend(er)

			http.Redirect(rw, req, "/", http.StatusFound)
		}
	}
}
示例#7
0
func DeleteFish(rw http.ResponseWriter, req *http.Request) {

	picture := req.FormValue("picture")
	species := req.FormValue("type")
	id, err := strconv.Atoi(req.FormValue("id"))
	utility.ShitAppend(err)

	fish := Fish{Id: id, Picture: picture}

	if species != "Goldfish" {
		_, err = db.Query("DELETE FROM fish WHERE id = $1", fish.Id)
		utility.ShitAppend(err)
		/*
			err = os.Remove("/img/users/" + fish.Picture)
			utility.ShitAppend(err)
		*/
	}
	http.Redirect(rw, req, "/home", http.StatusFound)
}
示例#8
0
文件: resize.go 项目: squiidz/fishMe
func ResizeJpeg(pic string) {
	log.Println("RESIZING !! JPEG")
	// open the Picture
	file, err := os.Open(pic)
	utility.ShitAppend(err)

	img, err := jpeg.Decode(file)
	utility.ShitAppend(err)
	file.Close()

	// Resize the Picture Data
	m := resize.Resize(565, 363, img, resize.Lanczos3)

	out, err := os.Create(pic)
	utility.ShitAppend(err)
	defer out.Close()

	// OverWrite the None Resizing Picture
	jpeg.Encode(out, m, nil)
}
示例#9
0
func AddFish(rw http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		var cookie, er = req.Cookie("fishme")
		utility.ShitAppend(er)
		species := req.FormValue("type")
		var path string
		// Picture Upload
		file, handler, err := req.FormFile("picture")
		utility.ShitAppend(err)

		if err != nil {
			path = "img/fish/" + species + ".jpg"
		} else {
			data, err := ioutil.ReadAll(file)
			utility.ShitAppend(err)
			path = "img/users/" + cookie.Value + "/" + handler.Filename
			err = ioutil.WriteFile(path, data, 0777)
			utility.ShitAppend(err)
			resize.ResizeMe(path)
		}
		// End

		poid, err := strconv.ParseFloat(req.FormValue("weigth"), 32)
		utility.ShitAppend(err)

		long, err := strconv.ParseFloat(req.FormValue("length"), 32)
		utility.ShitAppend(err)

		timeNow := time.Now().Format(time.RFC822)

		fish := Fish{
			Type:     species,
			Username: cookie.Value,
			Weight:   poid,
			Length:   long,
			Location: req.FormValue("location"),
			Date:     timeNow,
			Lure:     req.FormValue("lure"),
			Info:     req.FormValue("info"),
			Picture:  path}

		rows, err := db.Query("INSERT INTO fish(type, username, weight, length, location, date, lure, info, picture) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
			fish.Type,
			fish.Username,
			fish.Weight,
			fish.Length,
			fish.Location,
			fish.Date,
			fish.Lure,
			fish.Info,
			fish.Picture)
		utility.ShitAppend(err)
		defer rows.Close()
		http.Redirect(rw, req, "/home", http.StatusFound)
	}
}
示例#10
0
// Search in DB
func FindUser(name string) *User {
	result := User{}
	err := db.QueryRow("SELECT * FROM users WHERE username = $1", name).Scan(
		&result.Id,
		&result.Username,
		&result.Email,
		&result.Password,
		&result.Date,
	)
	utility.ShitAppend(err)

	return &result
}
示例#11
0
func ProfilHandler(rw http.ResponseWriter, req *http.Request) {
	var _, er = req.Cookie("fishme")
	if er != nil {
		http.Redirect(rw, req, "/", http.StatusFound)
	} else {
		temp, err := template.ParseFiles("template/profil.html")
		utility.ShitAppend(err)

		temp = template.Must(temp.Parse(ParseNavbarFile("template/navbar"))) // Add The content of the navbar.tmpl to the current template
		temp = template.Must(temp.ParseFiles("template/add_fish.tmpl"))

		temp.Execute(rw, nil)
	}
}
示例#12
0
func Handler(rw http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" { // Check if the request is for the root
		http.NotFound(rw, req)
		return
	}
	var _, er = req.Cookie("fishme")

	if er != nil {
		temp, err := template.ParseFiles("template/index.html")
		signin, err := utility.LoadPage("article/signin")
		utility.ShitAppend(err)
		SignButton := template.HTML(string(signin.Body))
		temp.Execute(rw, SignButton)
	} else {
		http.Redirect(rw, req, "/home", http.StatusFound)
	}
}
示例#13
0
// End of the ParseFishFile Function !
func ParseNavbarFile(file string) string {
	home, err := utility.LoadTemplate(file) // Load the content of the home.pk file (Navbar)
	utility.ShitAppend(err)
	return string(home.Body)
}