Files
upstream-ory-kratos/selfservice/strategy/code/code_registration.go
upstream-mirror c60cc7ca75
Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
snapshot of https://github.com/ory/kratos.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 21:19:12 +05:00

103 lines
2.6 KiB
Go

// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package code
import (
"context"
"database/sql"
"time"
"github.com/pkg/errors"
"github.com/gofrs/uuid"
"github.com/ory/kratos/identity"
"github.com/ory/x/clock"
)
// swagger:ignore
type RegistrationCode struct {
// ID represents the tokens's unique ID.
//
// required: true
// type: string
// format: uuid
ID uuid.UUID `json:"id" db:"id" faker:"-"`
// Address represents the address that the code was sent to.
// this can be an email address or a phone number.
Address string `json:"-" db:"address"`
// AddressType represents the type of the address
// this can be an email address or a phone number.
AddressType identity.CodeChannel `json:"-" db:"address_type"`
// CodeHMAC represents the HMACed value of the verification code
CodeHMAC string `json:"-" db:"code"`
// UsedAt is the timestamp of when the code was used or null if it wasn't yet
UsedAt sql.NullTime `json:"-" db:"used_at"`
// ExpiresAt is the time (UTC) when the token expires.
// required: true
ExpiresAt time.Time `json:"expires_at" faker:"time_type" db:"expires_at"`
// IssuedAt is the time (UTC) when the token was issued.
// required: true
IssuedAt time.Time `json:"issued_at" faker:"time_type" db:"issued_at"`
// CreatedAt is a helper struct field for gobuffalo.pop.
CreatedAt time.Time `json:"-" faker:"-" db:"created_at"`
// UpdatedAt is a helper struct field for gobuffalo.pop.
UpdatedAt time.Time `json:"-" faker:"-" db:"updated_at"`
// FlowID is a helper struct field for gobuffalo.pop.
FlowID uuid.UUID `json:"-" faker:"-" db:"selfservice_registration_flow_id"`
NID uuid.UUID `json:"-" faker:"-" db:"nid"`
}
func (RegistrationCode) TableName(context.Context) string {
return "identity_registration_codes"
}
func (c *RegistrationCode) Validate(clk clock.Clock) error {
if c == nil {
return errors.WithStack(ErrCodeNotFound())
}
return validateOneTimeCode(c.ExpiresAt, c.UsedAt, clk)
}
func (c *RegistrationCode) GetHMACCode() string {
return c.CodeHMAC
}
func (c *RegistrationCode) GetID() uuid.UUID {
return c.ID
}
// swagger:ignore
type CreateRegistrationCodeParams struct {
// Address is the email address or phone number the code should be sent to.
// required: true
Address string
// AddressType is the type of the address (email or phone number).
// required: true
AddressType identity.CodeChannel
// Code represents the recovery code
// required: true
RawCode string
// ExpiresAt is the time (UTC) when the code expires.
// required: true
ExpiresIn time.Duration
// FlowID is a helper struct field for gobuffalo.pop.
// required: true
FlowID uuid.UUID
}