-
Notifications
You must be signed in to change notification settings - Fork 0
/
AuthEventsBase.go
256 lines (196 loc) · 6.73 KB
/
AuthEventsBase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package auth
import (
"encoding/json"
"fmt"
"github.com/go-ee/utils/enum"
"github.com/google/uuid"
"github.com/looplab/eventhorizon"
"gopkg.in/mgo.v2/bson"
)
const (
AccountCreatedEvent eventhorizon.EventType = "AccountCreated"
AccountUpdatedEvent eventhorizon.EventType = "AccountUpdated"
AccountDeletedEvent eventhorizon.EventType = "AccountDeleted"
AccountEnabledEvent eventhorizon.EventType = "AccountEnabled"
AccountDisabledEvent eventhorizon.EventType = "AccountDisabled"
SendEnabledAccountConfirmationedEvent eventhorizon.EventType = "SendEnabledAccountConfirmationed"
SendDisabledAccountConfirmationedEvent eventhorizon.EventType = "SendDisabledAccountConfirmationed"
AccountLoggedEvent eventhorizon.EventType = "AccountLogged"
SendCreatedAccountConfirmationedEvent eventhorizon.EventType = "SendCreatedAccountConfirmationed"
)
type AccountCreated struct {
Name *PersonName `json:"name" eh:"optional"`
Username string `json:"username" eh:"optional"`
Password string `json:"password" eh:"optional"`
Email string `json:"email" eh:"optional"`
Roles []string `json:"roles" eh:"optional"`
Id uuid.UUID `json:"id" eh:"optional"`
}
func (o *AccountCreated) AddToRoles(item string) string {
o.Roles = append(o.Roles, item)
return item
}
type AccountUpdated struct {
Name *PersonName `json:"name" eh:"optional"`
Username string `json:"username" eh:"optional"`
Password string `json:"password" eh:"optional"`
Email string `json:"email" eh:"optional"`
Roles []string `json:"roles" eh:"optional"`
Id uuid.UUID `json:"id" eh:"optional"`
}
func (o *AccountUpdated) AddToRoles(item string) string {
o.Roles = append(o.Roles, item)
return item
}
type AccountDeleted struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type AccountEnabled struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type AccountDisabled struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type SendEnabledAccountConfirmationed struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type SendDisabledAccountConfirmationed struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type AccountLogged struct {
Username string `json:"username" eh:"optional"`
Email string `json:"email" eh:"optional"`
Password string `json:"password" eh:"optional"`
Id uuid.UUID `json:"id" eh:"optional"`
}
type SendCreatedAccountConfirmationed struct {
Id uuid.UUID `json:"id" eh:"optional"`
}
type AccountEventType struct {
name string
ordinal int
}
func (o *AccountEventType) Name() string {
return o.name
}
func (o *AccountEventType) Ordinal() int {
return o.ordinal
}
func (o AccountEventType) MarshalJSON() (ret []byte, err error) {
return json.Marshal(&enum.EnumBaseJson{Name: o.name})
}
func (o *AccountEventType) UnmarshalJSON(data []byte) (err error) {
lit := enum.EnumBaseJson{}
if err = json.Unmarshal(data, &lit); err == nil {
if v, ok := AccountEventTypes().ParseAccountEventType(lit.Name); ok {
*o = *v
} else {
err = fmt.Errorf("invalid AccountEventType %q", lit.Name)
}
}
return
}
func (o AccountEventType) GetBSON() (ret interface{}, err error) {
return o.name, nil
}
func (o *AccountEventType) SetBSON(raw bson.Raw) (err error) {
var lit string
if err = raw.Unmarshal(&lit); err == nil {
if v, ok := AccountEventTypes().ParseAccountEventType(lit); ok {
*o = *v
} else {
err = fmt.Errorf("invalid AccountEventType %q", lit)
}
}
return
}
func (o *AccountEventType) IsAccountCreated() bool {
return o == _accountEventTypes.AccountCreated()
}
func (o *AccountEventType) IsAccountDeleted() bool {
return o == _accountEventTypes.AccountDeleted()
}
func (o *AccountEventType) IsAccountDisabled() bool {
return o == _accountEventTypes.AccountDisabled()
}
func (o *AccountEventType) IsAccountEnabled() bool {
return o == _accountEventTypes.AccountEnabled()
}
func (o *AccountEventType) IsAccountLogged() bool {
return o == _accountEventTypes.AccountLogged()
}
func (o *AccountEventType) IsSendCreatedAccountConfirmationed() bool {
return o == _accountEventTypes.SendCreatedAccountConfirmationed()
}
func (o *AccountEventType) IsSendDisabledAccountConfirmationed() bool {
return o == _accountEventTypes.SendDisabledAccountConfirmationed()
}
func (o *AccountEventType) IsSendEnabledAccountConfirmationed() bool {
return o == _accountEventTypes.SendEnabledAccountConfirmationed()
}
func (o *AccountEventType) IsAccountUpdated() bool {
return o == _accountEventTypes.AccountUpdated()
}
type accountEventTypes struct {
values []*AccountEventType
literals []enum.Literal
}
var _accountEventTypes = &accountEventTypes{values: []*AccountEventType{
{name: "AccountCreated", ordinal: 0},
{name: "AccountDeleted", ordinal: 1},
{name: "AccountDisabled", ordinal: 2},
{name: "AccountEnabled", ordinal: 3},
{name: "AccountLogged", ordinal: 4},
{name: "SendCreatedAccountConfirmationed", ordinal: 5},
{name: "SendDisabledAccountConfirmationed", ordinal: 6},
{name: "SendEnabledAccountConfirmationed", ordinal: 7},
{name: "AccountUpdated", ordinal: 8}},
}
func AccountEventTypes() *accountEventTypes {
return _accountEventTypes
}
func (o *accountEventTypes) Values() []*AccountEventType {
return o.values
}
func (o *accountEventTypes) Literals() []enum.Literal {
if o.literals == nil {
o.literals = make([]enum.Literal, len(o.values))
for i, item := range o.values {
o.literals[i] = item
}
}
return o.literals
}
func (o *accountEventTypes) AccountCreated() *AccountEventType {
return _accountEventTypes.values[0]
}
func (o *accountEventTypes) AccountDeleted() *AccountEventType {
return _accountEventTypes.values[1]
}
func (o *accountEventTypes) AccountDisabled() *AccountEventType {
return _accountEventTypes.values[2]
}
func (o *accountEventTypes) AccountEnabled() *AccountEventType {
return _accountEventTypes.values[3]
}
func (o *accountEventTypes) AccountLogged() *AccountEventType {
return _accountEventTypes.values[4]
}
func (o *accountEventTypes) SendCreatedAccountConfirmationed() *AccountEventType {
return _accountEventTypes.values[5]
}
func (o *accountEventTypes) SendDisabledAccountConfirmationed() *AccountEventType {
return _accountEventTypes.values[6]
}
func (o *accountEventTypes) SendEnabledAccountConfirmationed() *AccountEventType {
return _accountEventTypes.values[7]
}
func (o *accountEventTypes) AccountUpdated() *AccountEventType {
return _accountEventTypes.values[8]
}
func (o *accountEventTypes) ParseAccountEventType(name string) (ret *AccountEventType, ok bool) {
if item, ok := enum.Parse(name, o.Literals()); ok {
return item.(*AccountEventType), ok
}
return
}