Initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type RegisterForm struct {
|
||||
gorm.Model
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
Name string `json:"name" gorm:"name"`
|
||||
Email string `json:"email" gorm:"email"`
|
||||
Password string `json:"password,omitempty" gorm:"password"`
|
||||
EmailVerified bool `json:"email_verified" gorm:"email_verified"`
|
||||
IsAdmin bool `json:"is_admin" gorm:"is_admin"`
|
||||
RoleID uint `json:"role_id" gorm:"role_id"`
|
||||
Role Roles `gorm:"foreignKey:RoleID"` // Establecer relación con Roles
|
||||
|
||||
NombreUsuario string `json:"nombre_usuario" gorm:"nombre_usuario"`
|
||||
Documento string `json:"documento" gorm:"documento"`
|
||||
Estado *bool `json:"estado" gorm:"estado"`
|
||||
TipoUsuario string `json:"tipo" gorm:"tipo_usuario"`
|
||||
CogidoUsuarioGas string `json:"cogido_usuario_gas" gorm:"cogido_usuario_gas"`
|
||||
NumeroMedidor string `json:"numero_medidor" gorm:"numero_medidor"`
|
||||
TelefonoFijo string `json:"telefono_fijo" gorm:"telefono_fijo"`
|
||||
Celular string `json:"celular" gorm:"celular"`
|
||||
AceptoInfo bool `json:"acepto_info" gorm:"acepto_info"`
|
||||
}
|
||||
|
||||
func (RegisterForm) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
|
||||
func (l *RegisterForm) Signup() (*RegisterForm, error) {
|
||||
|
||||
user, _ := GetUserByUsuario(l.NombreUsuario)
|
||||
if user != nil {
|
||||
return nil, errors.New("User Already Exists")
|
||||
}
|
||||
l.Password, _ = app.Http.Hash.Create(l.Password)
|
||||
app.Http.Database.DB.Create(l)
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (l *RegisterForm) ResetPassword() (*RegisterForm, error) {
|
||||
l.Password, _ = app.Http.Hash.Create(l.Password)
|
||||
app.Http.Database.DB.Updates(&l)
|
||||
return l, nil
|
||||
}
|
||||
Reference in New Issue
Block a user