<commit_before>//go:generate gourd gen store -type=User -coll=user $GOFILE
//go:generate gourd gen endpoints -type=User -store=UserStore -storekey=KeyUser user_store.go
//go:generate gourd gen rest -type=User -store=UserStore -storekey=KeyUser user_store.go
package oauth2

import (
	"crypto/md5"
	"encoding/json"
	"fmt"
	"io"
	"time"
)

// OAuth2User is the generic user interface
// for OAuth2 login check
type OAuth2User interface {
	// PasswordIs matches a string with the stored password.
	// If the stored password is hash, this function will apply to the
	// input before matching.
	PasswordIs(pass string) bool
}

// User of the API server
type User struct {
	ID       string    `db:"id,omitempty" json:"id"`
	Username string    `db:"username" json:"username"`
	Email    string    `db:"email" json:"email"`
	Password string    `db:"password" json:"-"`
	Name     string    `db:"name" json:"name"`
	MetaJSON string    `db:"meta_json" json:"-"`
	Token    string    `db:"token" json:"-"` // token for lost password request
	Created  time.Time `db:"created" json:"created"`
	Updated  time.Time `db:"updated" json:"updated"`
}

// userJSON is the struct for marshaling and unmarshaling
type userJSON struct {
	ID       string              `json:"id"`
	Username string              `json:"username"`
	Password string              `json:"password"`
	Email    string              `json:"email"`
	Name     string              `json:"name"`
	Meta     map[string][]string `json:"meta"`
	Created  time.Time           `json:"created"`
	Updated  time.Time           `json:"updated"`
}

// Meta read MetaJSON as map[string][]string
func (u User) Meta() (m map[string][]string) {
	m = make(map[string][]string)
	json.Unmarshal([]byte(u.MetaJSON), &m)
	return
}

// AddMeta adds Meta value
func (u *User) AddMeta(key, value string) {
	m := u.Meta()<commit_msg>oauth2: User should omit empty password<commit_after>//go:generate gourd gen store -type=User -coll=user $GOFILE
//go:generate gourd gen endpoints -type=User -store=UserStore -storekey=KeyUser user_store.go
//go:generate gourd gen rest -type=User -store=UserStore -storekey=KeyUser user_store.go
package oauth2

import (
	"crypto/md5"
	"encoding/json"
	"fmt"
	"io"
	"time"
)

// OAuth2User is the generic user interface
// for OAuth2 login check
type OAuth2User interface {
	// PasswordIs matches a string with the stored password.
	// If the stored password is hash, this function will apply to the
	// input before matching.
	PasswordIs(pass string) bool
}

// User of the API server
type User struct {
	ID       string    `db:"id,omitempty" json:"id"`
	Username string    `db:"username" json:"username"`
	Email    string    `db:"email" json:"email"`
	Password string    `db:"password,omitempty" json:"-"`
	Name     string    `db:"name" json:"name"`
	MetaJSON string    `db:"meta_json" json:"-"`
	Token    string    `db:"token" json:"-"` // token for lost password request
	Created  time.Time `db:"created" json:"created"`
	Updated  time.Time `db:"updated" json:"updated"`
}

// userJSON is the struct for marshaling and unmarshaling
type userJSON struct {
	ID       string              `json:"id"`
	Username string              `json:"username"`
	Password string              `json:"password"`
	Email    string              `json:"email"`
	Name     string              `json:"name"`
	Meta     map[string][]string `json:"meta"`
	Created  time.Time           `json:"created"`
	Updated  time.Time           `json:"updated"`
}

// Meta read MetaJSON as map[string][]string
func (u User) Meta() (m map[string][]string) {
	m = make(map[string][]string)
	json.Unmarshal([]byte(u.MetaJSON), &m)
	return
}

// AddMeta adds Meta value
func (u *User) AddMeta(key, value string) {
	m := u.Meta()
{'fraction_non_alphanumeric': 0.1316916488222698, 'fraction_numerical': 0.0029443254817987153, 'mean_word_length': 3.2855504587155964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1946626', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1162, 'n_words': 368}