temp_user.go 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
package models

import (
	"errors"
	"time"
)

// Typed errors
var (
	ErrTempUserNotFound = errors.New("User not found")
)

13 14 15
type TempUserStatus string

const (
16
	TmpUserSignUpStarted TempUserStatus = "SignUpStarted"
17 18 19 20 21
	TmpUserInvitePending TempUserStatus = "InvitePending"
	TmpUserCompleted     TempUserStatus = "Completed"
	TmpUserRevoked       TempUserStatus = "Revoked"
)

22
// TempUser holds data for org invites and unconfirmed sign ups
23
type TempUser struct {
24 25 26 27 28
	Id              int64
	OrgId           int64
	Version         int
	Email           string
	Name            string
29
	Role            RoleType
30
	InvitedByUserId int64
31
	Status          TempUserStatus
32 33 34 35

	EmailSent   bool
	EmailSentOn time.Time
	Code        string
36
	RemoteAddr  string
37 38 39 40 41 42 43 44 45

	Created time.Time
	Updated time.Time
}

// ---------------------
// COMMANDS

type CreateTempUserCommand struct {
46 47 48 49
	Email           string
	Name            string
	OrgId           int64
	InvitedByUserId int64
50
	Status          TempUserStatus
51
	Code            string
52
	Role            RoleType
53
	RemoteAddr      string
54 55 56 57

	Result *TempUser
}

58
type UpdateTempUserStatusCommand struct {
59
	Code   string
60 61 62
	Status TempUserStatus
}

63 64 65 66
type UpdateTempUserWithEmailSentCommand struct {
	Code string
}

67
type GetTempUsersQuery struct {
68
	OrgId  int64
69
	Email  string
70
	Status TempUserStatus
71 72 73 74

	Result []*TempUserDTO
}

75
type GetTempUserByCodeQuery struct {
76 77
	Code string

78
	Result *TempUserDTO
79 80
}

81
type TempUserDTO struct {
82
	Id             int64          `json:"id"`
83
	OrgId          int64          `json:"orgId"`
84 85
	Name           string         `json:"name"`
	Email          string         `json:"email"`
86
	Role           RoleType       `json:"role"`
87 88 89 90 91 92 93 94 95
	InvitedByLogin string         `json:"invitedByLogin"`
	InvitedByEmail string         `json:"invitedByEmail"`
	InvitedByName  string         `json:"invitedByName"`
	Code           string         `json:"code"`
	Status         TempUserStatus `json:"status"`
	Url            string         `json:"url"`
	EmailSent      bool           `json:"emailSent"`
	EmailSentOn    time.Time      `json:"emailSentOn"`
	Created        time.Time      `json:"createdOn"`
96
}