frontend: disabled button while processing password reset
This commit is contained in:
15
go-backend/internal/models/bank_account.go
Normal file
15
go-backend/internal/models/bank_account.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type BankAccount struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
MandateDateSigned time.Time `gorm:"not null" json:"mandate_date_signed"`
|
||||
Bank string `json:"bank_name" binding:"safe_content"`
|
||||
AccountHolderName string `json:"account_holder_name" binding:"safe_content"`
|
||||
IBAN string `json:"iban"`
|
||||
BIC string `json:"bic"`
|
||||
MandateReference string `gorm:"not null" json:"mandate_reference"`
|
||||
ID uint `gorm:"primaryKey"`
|
||||
}
|
||||
17
go-backend/internal/models/consents.go
Normal file
17
go-backend/internal/models/consents.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Consent struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
FirstName string `gorm:"not null" json:"first_name" binding:"safe_content"`
|
||||
LastName string `gorm:"not null" json:"last_name" binding:"safe_content"`
|
||||
Email string `json:"email" binding:"email,safe_content"`
|
||||
ConsentType string `gorm:"not null" json:"consent_type" binding:"safe_content"`
|
||||
ID uint `gorm:"primaryKey"`
|
||||
User User
|
||||
UserID uint
|
||||
}
|
||||
22
go-backend/internal/models/drivers_licence.go
Normal file
22
go-backend/internal/models/drivers_licence.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Licence struct {
|
||||
ID uint `json:"id"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Status int8 `json:"status" binding:"omitempty,number"`
|
||||
Number string `json:"number" binding:"omitempty,safe_content"`
|
||||
IssuedDate time.Time `json:"issued_date" binding:"omitempty"`
|
||||
ExpirationDate time.Time `json:"expiration_date" binding:"omitempty"`
|
||||
IssuingCountry string `json:"country" binding:"safe_content"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:licence_2_categories"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
Name string `json:"category" binding:"safe_content"`
|
||||
}
|
||||
15
go-backend/internal/models/membership.go
Normal file
15
go-backend/internal/models/membership.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Membership struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
StartDate time.Time `json:"start_date"`
|
||||
EndDate time.Time `json:"end_date"`
|
||||
Status int8 `json:"status" binding:"number,safe_content"`
|
||||
SubscriptionModel SubscriptionModel `gorm:"foreignKey:SubscriptionModelID" json:"subscription_model"`
|
||||
SubscriptionModelID uint `json:"subsription_model_id"`
|
||||
ParentMembershipID uint `json:"parent_member_id" binding:"omitempty,omitnil,number"`
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
19
go-backend/internal/models/subscription_model.go
Normal file
19
go-backend/internal/models/subscription_model.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type SubscriptionModel struct {
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string `gorm:"unique" json:"name" binding:"required"`
|
||||
Details string `json:"details"`
|
||||
Conditions string `json:"conditions"`
|
||||
RequiredMembershipField string `json:"required_membership_field"`
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
MonthlyFee float32 `json:"monthly_fee"`
|
||||
HourlyRate float32 `json:"hourly_rate"`
|
||||
IncludedPerYear int16 `json:"included_hours_per_year"`
|
||||
IncludedPerMonth int16 `json:"included_hours_per_month"`
|
||||
}
|
||||
132
go-backend/internal/models/user.go
Normal file
132
go-backend/internal/models/user.go
Normal file
@@ -0,0 +1,132 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"GoMembership/pkg/logger"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/alexedwards/argon2id"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
DateOfBirth time.Time `gorm:"not null" json:"dateofbirth" binding:"required,safe_content"`
|
||||
Company string `json:"company" binding:"omitempty,omitnil,safe_content"`
|
||||
Phone string `json:"phone" binding:"omitempty,omitnil,safe_content"`
|
||||
Notes string `json:"notes" binding:"safe_content"`
|
||||
FirstName string `gorm:"not null" json:"first_name" binding:"required,safe_content"`
|
||||
Password string `json:"password" binding:"safe_content"`
|
||||
Email string `gorm:"unique;not null" json:"email" binding:"required,email,safe_content"`
|
||||
LastName string `gorm:"not null" json:"last_name" binding:"required,safe_content"`
|
||||
ProfilePicture string `json:"profile_picture" binding:"omitempty,omitnil,image,safe_content"`
|
||||
Address string `gorm:"not null" json:"address" binding:"required,safe_content"`
|
||||
ZipCode string `gorm:"not null" json:"zip_code" binding:"required,alphanum,safe_content"`
|
||||
City string `form:"not null" json:"city" binding:"required,alphaunicode,safe_content"`
|
||||
Consents []Consent `gorm:"constraint:OnUpdate:CASCADE"`
|
||||
BankAccount BankAccount `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"bank_account"`
|
||||
BankAccountID uint
|
||||
Verification Verification `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
VerificationID uint
|
||||
Membership Membership `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"membership"`
|
||||
MembershipID uint
|
||||
Licence *Licence `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"licence"`
|
||||
LicenceID uint
|
||||
PaymentStatus int8 `json:"payment_status"`
|
||||
Status int8 `json:"status"`
|
||||
RoleID int8 `json:"role_id"`
|
||||
}
|
||||
|
||||
func (u *User) AfterCreate(tx *gorm.DB) (err error) {
|
||||
if u.BankAccount.ID != 0 && u.BankAccount.MandateReference == "" {
|
||||
mandateReference := u.GenerateMandateReference()
|
||||
|
||||
return tx.Model(&u.BankAccount).Update("MandateReference", mandateReference).Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) GenerateMandateReference() string {
|
||||
return fmt.Sprintf("%s%d%s", time.Now().Format("20060102"), u.ID, u.BankAccount.IBAN)
|
||||
}
|
||||
|
||||
func (u *User) SetPassword(plaintextPassword string) error {
|
||||
if plaintextPassword == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
hash, err := argon2id.CreateHash(plaintextPassword, argon2id.DefaultParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.Password = hash
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *User) PasswordMatches(plaintextPassword string) (bool, error) {
|
||||
logger.Error.Printf("plaintext: %v user password: %v", plaintextPassword, u.Password)
|
||||
return argon2id.ComparePasswordAndHash(plaintextPassword, u.Password)
|
||||
}
|
||||
|
||||
func (u *User) Safe() map[string]interface{} {
|
||||
result := map[string]interface{}{
|
||||
"email": u.Email,
|
||||
"first_name": u.FirstName,
|
||||
"last_name": u.LastName,
|
||||
"phone": u.Phone,
|
||||
"notes": u.Notes,
|
||||
"address": u.Address,
|
||||
"zip_code": u.ZipCode,
|
||||
"city": u.City,
|
||||
"status": u.Status,
|
||||
"id": u.ID,
|
||||
"role_id": u.RoleID,
|
||||
"company": u.Company,
|
||||
"dateofbirth": u.DateOfBirth,
|
||||
"membership": map[string]interface{}{
|
||||
"id": u.Membership.ID,
|
||||
"start_date": u.Membership.StartDate,
|
||||
"end_date": u.Membership.EndDate,
|
||||
"status": u.Membership.Status,
|
||||
"subscription_model": map[string]interface{}{
|
||||
"id": u.Membership.SubscriptionModel.ID,
|
||||
"name": u.Membership.SubscriptionModel.Name,
|
||||
"details": u.Membership.SubscriptionModel.Details,
|
||||
"conditions": u.Membership.SubscriptionModel.Conditions,
|
||||
"monthly_fee": u.Membership.SubscriptionModel.MonthlyFee,
|
||||
"hourly_rate": u.Membership.SubscriptionModel.HourlyRate,
|
||||
"included_per_year": u.Membership.SubscriptionModel.IncludedPerYear,
|
||||
"included_per_month": u.Membership.SubscriptionModel.IncludedPerMonth,
|
||||
},
|
||||
},
|
||||
"licence": map[string]interface{}{
|
||||
"id": 0,
|
||||
},
|
||||
"bank_account": map[string]interface{}{
|
||||
"id": u.BankAccount.ID,
|
||||
"mandate_date_signed": u.BankAccount.MandateDateSigned,
|
||||
"bank": u.BankAccount.Bank,
|
||||
"account_holder_name": u.BankAccount.AccountHolderName,
|
||||
"iban": u.BankAccount.IBAN,
|
||||
"bic": u.BankAccount.BIC,
|
||||
"mandate_reference": u.BankAccount.MandateReference,
|
||||
},
|
||||
}
|
||||
|
||||
if u.Licence != nil {
|
||||
result["licence"] = map[string]interface{}{
|
||||
"id": u.Licence.ID,
|
||||
"number": u.Licence.Number,
|
||||
"status": u.Licence.Status,
|
||||
"issued_date": u.Licence.IssuedDate,
|
||||
"expiration_date": u.Licence.ExpirationDate,
|
||||
"country": u.Licence.IssuingCountry,
|
||||
"categories": u.Licence.Categories,
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
13
go-backend/internal/models/verification.go
Normal file
13
go-backend/internal/models/verification.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Verification struct {
|
||||
UpdatedAt time.Time
|
||||
CreatedAt time.Time
|
||||
VerifiedAt *time.Time `gorm:"Default:NULL" json:"verified_at"`
|
||||
VerificationToken string `json:"token"`
|
||||
ID uint `gorm:"primaryKey"`
|
||||
UserID uint `gorm:"unique;" json:"user_id"`
|
||||
Type string
|
||||
}
|
||||
Reference in New Issue
Block a user