From 85fb2a952bbd879b19c689c8238a70265c3cbacd Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 7 Jun 2021 14:53:22 -0400 Subject: [PATCH] Support setting `description` on user registration --- account.go | 7 ++++--- app.go | 4 ++-- database.go | 6 +++--- users.go | 3 +++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/account.go b/account.go index d1e6a21..65d39c7 100644 --- a/account.go +++ b/account.go @@ -167,7 +167,7 @@ func signupWithRegistration(app *App, signup userRegistration, w http.ResponseWr } // Create actual user - if err := app.db.CreateUser(app.cfg, u, desiredUsername); err != nil { + if err := app.db.CreateUser(app.cfg, u, desiredUsername, signup.Description); err != nil { return nil, err } @@ -193,8 +193,9 @@ func signupWithRegistration(app *App, signup userRegistration, w http.ResponseWr } resUser.Collections = &[]Collection{ { - Alias: signup.Alias, - Title: title, + Alias: signup.Alias, + Title: title, + Description: signup.Description, }, } diff --git a/app.go b/app.go index ed2ba04..40eb858 100644 --- a/app.go +++ b/app.go @@ -621,7 +621,7 @@ func DoConfig(app *App, configSections string) { // Create blog log.Info("Creating user %s...\n", u.Username) - err = app.db.CreateUser(app.cfg, u, app.cfg.App.SiteName) + err = app.db.CreateUser(app.cfg, u, app.cfg.App.SiteName, "") if err != nil { log.Error("Unable to create user: %s", err) os.Exit(1) @@ -866,7 +866,7 @@ func CreateUser(apper Apper, username, password string, isAdmin bool) error { userType = "admin" } log.Info("Creating %s %s...", userType, usernameDesc) - err = apper.App().db.CreateUser(apper.App().Config(), u, desiredUsername) + err = apper.App().db.CreateUser(apper.App().Config(), u, desiredUsername, "") if err != nil { return fmt.Errorf("Unable to create user: %s", err) } diff --git a/database.go b/database.go index df300ce..49a2312 100644 --- a/database.go +++ b/database.go @@ -51,7 +51,7 @@ var ( ) type writestore interface { - CreateUser(*config.Config, *User, string) error + CreateUser(*config.Config, *User, string, string) error UpdateUserEmail(keys *key.Keychain, userID int64, email string) error UpdateEncryptedUserEmail(int64, []byte) error GetUserByID(int64) (*User, error) @@ -179,7 +179,7 @@ func (db *datastore) dateSub(l int, unit string) string { } // CreateUser creates a new user in the database from the given User, UPDATING it in the process with the user's ID. -func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle string) error { +func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle string, collectionDesc string) error { if db.PostIDExists(u.Username) { return impart.HTTPError{http.StatusConflict, "Invalid collection name."} } @@ -213,7 +213,7 @@ func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle str if collectionTitle == "" { collectionTitle = u.Username } - res, err = t.Exec("INSERT INTO collections (alias, title, description, privacy, owner_id, view_count) VALUES (?, ?, ?, ?, ?, ?)", u.Username, collectionTitle, "", defaultVisibility(cfg), u.ID, 0) + res, err = t.Exec("INSERT INTO collections (alias, title, description, privacy, owner_id, view_count) VALUES (?, ?, ?, ?, ?, ?)", u.Username, collectionTitle, collectionDesc, defaultVisibility(cfg), u.ID, 0) if err != nil { t.Rollback() if db.isDuplicateKeyErr(err) { diff --git a/users.go b/users.go index add76cd..fe2f2c8 100644 --- a/users.go +++ b/users.go @@ -43,6 +43,9 @@ type ( Honeypot string `json:"fullname" schema:"fullname"` Normalize bool `json:"normalize" schema:"normalize"` Signup bool `json:"signup" schema:"signup"` + + // Feature fields + Description string `json:"description" schema:"description"` } // AuthUser contains information for a newly authenticated user (either