add rest api for api_bb vue a lot of files

This commit is contained in:
2025-10-09 05:59:40 +05:00
parent 654c682b05
commit 700e404a06
17 changed files with 512 additions and 211 deletions
+32 -15
View File
@@ -1,23 +1,40 @@
// models/user.go
package models
import (
"time"
"gorm.io/gorm"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
"time"
)
type User struct {
gorm.Model
ID uint `gorm:"primaryKey" json:"id"`
Email string `gorm:"uniqueIndex;not null" json:"email"`
Password string `gorm:"not null" json:"-"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Role string `gorm:"default:user" json:"role"` // user, admin
IsActive bool `gorm:"default:true" json:"is_active"`
LastLogin time.Time `json:"last_login"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID uint `json:"id" gorm:"primaryKey"`
Email string `json:"email" gorm:"uniqueIndex;not null"`
Password string `json:"-" gorm:"not null"`
FirstName string `json:"first_name" gorm:"not null"`
LastName string `json:"last_name" gorm:"not null"`
Phone string `json:"phone"`
Experience string `json:"experience"`
Goals string `json:"goals"`
Newsletter bool `json:"newsletter"`
Role string `json:"role" gorm:"default:user"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
}
// Другие модели будут добавлены позже
// type Profile {}, type Event {}, type Review {}, etc.
// HashPassword хеширует пароль перед сохранением
func (u *User) HashPassword() error {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost)
if err != nil {
return err
}
u.Password = string(hashedPassword)
return nil
}
// CheckPassword проверяет пароль
func (u *User) CheckPassword(password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(u.Password), []byte(password))
return err == nil
}