@@ -3,7 +3,6 @@ package models
33import (
44 "time"
55
6- "github.com/shellhub-io/shellhub/pkg/hash"
76 "github.com/shellhub-io/shellhub/pkg/validator"
87)
98
@@ -74,35 +73,21 @@ type User struct {
7473
7574 Status UserStatus `json:"status" bson:"status" bun:"status"`
7675
77- Name string `json:"name" validate:"required,name" bun:"name"`
78- Username string `json:"username" bson:"username" validate:"required,username" bun:"username"`
79- Email string `json:"email" bson:"email" validate:"required,email" bun:"email"`
80- Password string `json:"-" bson:",inline" bun:"password_digest"`
76+ Name string `json:"name" validate:"required,name" bun:"name"`
77+ Username string `json:"username" bson:"username" validate:"required,username" bun:"username"`
78+ Email string `json:"email" bson:"email" validate:"required,email" bun:"email"`
79+ PasswordDigest string `json:"-" bson:",inline" bun:"password_digest"`
8180
8281 Preferences UserPreferences `json:"preferences" bson:"preferences" bun:"embed:"`
83-
84- ///
85- ///
86- ///
87- ///
88- ///
89- ///
90-
91- MFA UserMFA `json:"mfa" bson:"mfa" bun:"-"`
92- RecoveryEmail string `json:"recovery_email" bson:"recovery_email" validate:"omitempty,email" bun:"-"`
93- MaxNamespaces int `json:"max_namespaces" bson:"max_namespaces" bun:"-"`
94- EmailMarketing bool `json:"email_marketing" bson:"email_marketing" bun:"-"`
82+ MFA UserMFA `json:"mfa" bson:"mfa" bun:"-"`
9583}
9684
97- type UserData struct {
98- Name string `json:"name" validate:"required,name"`
99- Username string `json:"username" bson:"username" validate:"required,username"`
100- Email string `json:"email" bson:"email" validate:"required,email"`
101- // RecoveryEmail is a custom, non-unique email address that a user can use to recover their account
102- // when they lose access to all other methods. It must never be equal to [UserData.Email].
103- //
104- // NOTE: Recovery email is available as a cloud-only feature and must be ignored in community.
105- RecoveryEmail string `json:"recovery_email" bson:"recovery_email" validate:"omitempty,email"`
85+ type UserPreferences struct {
86+ PreferredNamespace string `json:"-" bson:"preferred_namespace" bun:"preferred_namespace_id,nullzero"`
87+ AuthMethods []UserAuthMethod `json:"auth_methods" bson:"auth_methods" bun:"auth_methods,array"`
88+ SecurityEmail string `json:"recovery_email" bson:"recovery_email" validate:"omitempty,email" bun:"security_email,nullzero"`
89+ MaxNamespaces int `json:"max_namespaces" bson:"max_namespaces" bun:"namespace_ownership_limit"`
90+ EmailMarketing bool `json:"email_marketing" bson:"email_marketing" bun:"email_marketing"`
10691}
10792
10893// UserMFA represents the attributes related to MFA for a user.
@@ -115,43 +100,6 @@ type UserMFA struct {
115100 RecoveryCodes []string `json:"-" bson:"recovery_codes"`
116101}
117102
118- type UserPreferences struct {
119- PreferredNamespace string `json:"-" bson:"preferred_namespace" bun:"preferred_namespace_id,nullzero"`
120- AuthMethods []UserAuthMethod `json:"auth_methods" bson:"auth_methods" bun:"auth_methods,array"`
121- RecoveryEmail string `json:"recovery_email" bson:"recovery_email" validate:"omitempty,email" bun:"security_email,nullzero"`
122- MaxNamespaces int `json:"max_namespaces" bson:"max_namespaces" bun:"namespace_ownership_limit"`
123- EmailMarketing bool `json:"email_marketing" bson:"email_marketing" bun:"email_marketing"`
124- }
125-
126- type UserPassword struct {
127- // Plain contains the plain text password.
128- Plain string `json:"password" bson:"-" validate:"required,password"`
129- // Hash contains the hashed pasword from plain text.
130- Hash string `json:"-" bson:"password"`
131- }
132-
133- // HashUserPassword receives a plain password and hash it, returning
134- // a [UserPassword].
135- func HashUserPassword (plain string ) (UserPassword , error ) {
136- p := UserPassword {
137- Plain : plain ,
138- }
139-
140- var err error
141- p .Hash , err = hash .Do (p .Plain )
142-
143- return p , err
144- }
145-
146- // Compare reports whether a plain password matches with hash.
147- //
148- // For compatibility purposes, it can compare using both SHA256 and bcrypt algorithms.
149- // Hashes starting with "$" are assumed to be a bcrypt hash; otherwise, they are treated as
150- // SHA256 hashes.
151- func (p * UserPassword ) Compare (plain string ) bool {
152- return hash .CompareWith (plain , p .Hash )
153- }
154-
155103// UserAuthIdentifier is an username or email used to authenticate.
156104type UserAuthIdentifier string
157105
0 commit comments