<commit_before>package view

import "github.com/pufferpanel/pufferpanel/models"

type UserViewModel struct {
	Username string `json:"username"`
	Email    string `json:"email"`
}

func FromModel(model *models.User) *UserViewModel {
	return &UserViewModel{
		Username: model.Username,
		Email:    model.Email,
	}
}

func (model *UserViewModel) CopyToModel(newModel *models.User) {
	if model.Username != "" {
		newModel.Username = model.Username
	}

	if model.Email != "" {
		newModel.Email = model.Email
	}<commit_msg>Add ability to set password via view model<commit_after>package view

import "github.com/pufferpanel/pufferpanel/models"

type UserViewModel struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	//ONLY SHOW WHEN COPYING
	Password string `json:"password,omitempty"`
}

func FromUser(model *models.User) *UserViewModel {
	return &UserViewModel{
		Username: model.Username,
		Email:    model.Email,
	}
}

func (model *UserViewModel) CopyToModel(newModel *models.User) {
	if model.Username != "" {
		newModel.Username = model.Username
	}

	if model.Email != "" {
		newModel.Email = model.Email
	}

	if model.Password != "" {
		newModel.SetPassword(model.Password)
	}
{'fraction_non_alphanumeric': 0.12406328059950042, 'fraction_numerical': 0.0, 'mean_word_length': 4.513761467889908, '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': '5481462', 'n_tokens_mistral': 405, 'n_tokens_neox': 382, 'n_words': 89}