Adding upstream version 0.28.1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
88f1d47ab6
commit
e28c88ef14
933 changed files with 194711 additions and 0 deletions
85
core/record_model_auth.go
Normal file
85
core/record_model_auth.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package core
|
||||
|
||||
import "github.com/pocketbase/pocketbase/tools/security"
|
||||
|
||||
// Email returns the "email" record field value (usually available with Auth collections).
|
||||
func (m *Record) Email() string {
|
||||
return m.GetString(FieldNameEmail)
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" record field value (usually available with Auth collections).
|
||||
func (m *Record) SetEmail(email string) {
|
||||
m.Set(FieldNameEmail, email)
|
||||
}
|
||||
|
||||
// Verified returns the "emailVisibility" record field value (usually available with Auth collections).
|
||||
func (m *Record) EmailVisibility() bool {
|
||||
return m.GetBool(FieldNameEmailVisibility)
|
||||
}
|
||||
|
||||
// SetEmailVisibility sets the "emailVisibility" record field value (usually available with Auth collections).
|
||||
func (m *Record) SetEmailVisibility(visible bool) {
|
||||
m.Set(FieldNameEmailVisibility, visible)
|
||||
}
|
||||
|
||||
// Verified returns the "verified" record field value (usually available with Auth collections).
|
||||
func (m *Record) Verified() bool {
|
||||
return m.GetBool(FieldNameVerified)
|
||||
}
|
||||
|
||||
// SetVerified sets the "verified" record field value (usually available with Auth collections).
|
||||
func (m *Record) SetVerified(verified bool) {
|
||||
m.Set(FieldNameVerified, verified)
|
||||
}
|
||||
|
||||
// TokenKey returns the "tokenKey" record field value (usually available with Auth collections).
|
||||
func (m *Record) TokenKey() string {
|
||||
return m.GetString(FieldNameTokenKey)
|
||||
}
|
||||
|
||||
// SetTokenKey sets the "tokenKey" record field value (usually available with Auth collections).
|
||||
func (m *Record) SetTokenKey(key string) {
|
||||
m.Set(FieldNameTokenKey, key)
|
||||
}
|
||||
|
||||
// RefreshTokenKey generates and sets a new random auth record "tokenKey".
|
||||
func (m *Record) RefreshTokenKey() {
|
||||
m.Set(FieldNameTokenKey+autogenerateModifier, "")
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" record field value (usually available with Auth collections).
|
||||
func (m *Record) SetPassword(password string) {
|
||||
// note: the tokenKey will be auto changed if necessary before db write
|
||||
m.Set(FieldNamePassword, password)
|
||||
}
|
||||
|
||||
// SetRandomPassword sets the "password" auth record field to a random autogenerated value.
|
||||
//
|
||||
// The autogenerated password is ~30 characters and it is set directly as hash,
|
||||
// aka. the field plain password value validators (length, pattern, etc.) are ignored
|
||||
// (this is usually used as part of the auto created OTP or OAuth2 user flows).
|
||||
func (m *Record) SetRandomPassword() string {
|
||||
pass := security.RandomString(30)
|
||||
|
||||
m.Set(FieldNamePassword, pass)
|
||||
m.RefreshTokenKey() // manually refresh the token key because the plain password is resetted
|
||||
|
||||
// unset the plain value to skip the field validators
|
||||
if raw, ok := m.GetRaw(FieldNamePassword).(*PasswordFieldValue); ok {
|
||||
raw.Plain = ""
|
||||
}
|
||||
|
||||
return pass
|
||||
}
|
||||
|
||||
// ValidatePassword validates a plain password against the "password" record field.
|
||||
//
|
||||
// Returns false if the password is incorrect.
|
||||
func (m *Record) ValidatePassword(password string) bool {
|
||||
pv, ok := m.GetRaw(FieldNamePassword).(*PasswordFieldValue)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
return pv.Validate(password)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue