mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-10-23 04:55:22 +00:00
50188352a5
feat: store user roles in user roles table, drops the roles table on users table. feat: standardize column names in schema, renames disabled bool to enables. - vue router fixes to allow components / pages to rerender after creating an object in db. - minor fixes and refactors.
28 lines
828 B
Go
28 lines
828 B
Go
package user
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/abhinavxd/libredesk/internal/user/models"
|
|
"github.com/volatiletech/null/v9"
|
|
)
|
|
|
|
// CreateContact creates a new contact user.
|
|
func (u *Manager) CreateContact(user *models.User) error {
|
|
password, err := u.generatePassword()
|
|
if err != nil {
|
|
u.lo.Error("generating password", "error", err)
|
|
return fmt.Errorf("generating password: %w", err)
|
|
}
|
|
|
|
// Normalize email address.
|
|
user.Email = null.NewString(strings.ToLower(user.Email.String), user.Email.Valid)
|
|
|
|
if err := u.q.InsertContact.QueryRow(user.Email, user.FirstName, user.LastName, password, user.AvatarURL, user.InboxID, user.SourceChannelID).Scan(&user.ID, &user.ContactChannelID); err != nil {
|
|
u.lo.Error("error inserting contact", "error", err)
|
|
return fmt.Errorf("insert contact: %w", err)
|
|
}
|
|
return nil
|
|
}
|