Merge branch 'main' of ssh://git.tjoyspotifylastfm.tech:10022/MERDE.COM/eternos
This commit is contained in:
75
not_sorted/register.go
Normal file
75
not_sorted/register.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
db "market/database"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// Data структура для входящих данных
|
||||
type Data struct {
|
||||
ID int `json:"ID"`
|
||||
Count int `json:"Count"`
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
Login string `json:"Login"`
|
||||
Password string `json:"Password"`
|
||||
}
|
||||
|
||||
func HashPassword(password string) (string) {
|
||||
// Генерация хэша с заданным уровнем сложности (по умолчанию 10)
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(hash)
|
||||
}
|
||||
|
||||
// CheckPassword сравнивает хэшированный пароль с обычным
|
||||
func CheckPassword(hashedPassword, plainPassword string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Инициализация Fiber
|
||||
app := fiber.New()
|
||||
|
||||
// Маршрут для обработки POST-запроса
|
||||
app.Post("/register", func(c *fiber.Ctx) error {
|
||||
// var input []Data
|
||||
var input Account
|
||||
// Парсинг входящих данных
|
||||
if err := c.BodyParser(&input); err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"message": "err",
|
||||
})
|
||||
}
|
||||
|
||||
check_auth := fmt.Sprintf("SELECT ID, login WHERE login=%s", input.Login)
|
||||
is_exist := db.Insert_Data(check_auth)
|
||||
if is_exist{
|
||||
pswd := HashPassword(input.Password)
|
||||
formatted := fmt.Sprintf("INSERT INTO users (login, hash_password) VALUES (%s, %s)", input.Login, pswd)
|
||||
err := db.Insert_Data(formatted)
|
||||
if err == false {
|
||||
log.Printf("Ошибка при вставке данных")
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||||
"message": "err",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"message": "OK",
|
||||
})
|
||||
})
|
||||
|
||||
// Запуск сервера
|
||||
log.Fatal(app.Listen(":3000"))
|
||||
}
|
||||
18
|
||||
BIN
not_sorted/url_for_pay_example
Executable file
BIN
not_sorted/url_for_pay_example
Executable file
Binary file not shown.
55
not_sorted/url_for_pay_example.go
Normal file
55
not_sorted/url_for_pay_example.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func Pay(sum float64) string{
|
||||
// Базовый URL
|
||||
baseURL := "https://yoomoney.ru/quickpay/confirm.xml"
|
||||
baseSum := fmt.Sprintf("%f", sum)
|
||||
|
||||
// Параметры запроса
|
||||
params := url.Values{}
|
||||
params.Add("receiver", "410012845407838")
|
||||
params.Add("quickpay-form", "shop")
|
||||
params.Add("targets", "Тестовая покупка")
|
||||
params.Add("paymentType", "SB")
|
||||
params.Add("sum", baseSum)
|
||||
params.Add("label", "cheche")
|
||||
|
||||
// Формируем полный URL с параметрами
|
||||
fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())
|
||||
// fmt.Println("Request URL:", fullURL)
|
||||
|
||||
// Создаем кастомный HTTP-клиент с отключенными редиректами
|
||||
client := &http.Client{
|
||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||
// Останавливаемся после первого редиректа
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
|
||||
// Отправляем POST-запрос с пустым телом
|
||||
resp, err := client.Post(fullURL, "application/x-www-form-urlencoded", nil)
|
||||
if err != nil {
|
||||
// fmt.Println("Error sending request:", err)
|
||||
return "WHOOPS"
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
location, err := resp.Location()
|
||||
if err != nil {
|
||||
// fmt.Println("Error getting location:", err)
|
||||
return "WHOOPS"
|
||||
}
|
||||
// fmt.Println("Redirect URL:", location.String())
|
||||
return location.String()
|
||||
}
|
||||
|
||||
func main() {
|
||||
pay := Pay(6.0)
|
||||
fmt.Println(pay)
|
||||
}
|
||||
Reference in New Issue
Block a user