github.com/greenpau/go-authcrunch@v1.1.4/pkg/identity/registration.go (about)

     1  // Copyright 2022 Paul Greenberg greenpau@outlook.com
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package identity
    16  
    17  import (
    18  	"time"
    19  )
    20  
    21  // Registration is an instance of user registration.
    22  // Typically used in scenarios where user wants to
    23  // register for a service. The user provides identity information
    24  // and waits for an approval.
    25  type Registration struct {
    26  	ID         string    `json:"id,omitempty" xml:"id,omitempty" yaml:"id,omitempty"`
    27  	CreatedAt  time.Time `json:"created_at,omitempty" xml:"created_at,omitempty" yaml:"created_at,omitempty"`
    28  	ApprovedAt time.Time `json:"approved_at,omitempty" xml:"approved_at,omitempty" yaml:"approved_at,omitempty"`
    29  	Approved   bool      `json:"approved,omitempty" xml:"approved,omitempty" yaml:"approved,omitempty"`
    30  	DeclinedAt time.Time `json:"declined_at,omitempty" xml:"declined_at,omitempty" yaml:"declined_at,omitempty"`
    31  	Declined   bool      `json:"declined,omitempty" xml:"declined,omitempty" yaml:"declined,omitempty"`
    32  }
    33  
    34  // NewRegistration returns an instance of Registration.
    35  func NewRegistration(s string) *Registration {
    36  	r := &Registration{
    37  		ID:        s,
    38  		CreatedAt: time.Now().UTC(),
    39  	}
    40  	return r
    41  }
    42  
    43  // Approve approves the Registration.
    44  func (r *Registration) Approve() {
    45  	r.Approved = true
    46  	r.ApprovedAt = time.Now().UTC()
    47  }
    48  
    49  // Decline declines the Registration.
    50  func (r *Registration) Decline() {
    51  	r.Declined = true
    52  	r.DeclinedAt = time.Now().UTC()
    53  }