mirror of
https://github.com/writeas/writefreely
synced 2025-02-09 12:58:37 +01:00
Accept config.Config in datastore.CreateUser()
instead of App Ref T675
This commit is contained in:
parent
569bc792d0
commit
df078c569d
@ -163,7 +163,7 @@ func signupWithRegistration(app *App, signup userRegistration, w http.ResponseWr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create actual user
|
// Create actual user
|
||||||
if err := app.db.CreateUser(app, u, desiredUsername); err != nil {
|
if err := app.db.CreateUser(app.cfg, u, desiredUsername); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
app.go
4
app.go
@ -507,7 +507,7 @@ func DoConfig(app *App, configSections string) {
|
|||||||
|
|
||||||
// Create blog
|
// Create blog
|
||||||
log.Info("Creating user %s...\n", u.Username)
|
log.Info("Creating user %s...\n", u.Username)
|
||||||
err = app.db.CreateUser(app, u, app.cfg.App.SiteName)
|
err = app.db.CreateUser(app.cfg, u, app.cfg.App.SiteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to create user: %s", err)
|
log.Error("Unable to create user: %s", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -702,7 +702,7 @@ func CreateUser(apper Apper, username, password string, isAdmin bool) error {
|
|||||||
userType = "admin"
|
userType = "admin"
|
||||||
}
|
}
|
||||||
log.Info("Creating %s %s...", userType, usernameDesc)
|
log.Info("Creating %s %s...", userType, usernameDesc)
|
||||||
err = apper.App().db.CreateUser(apper.App(), u, desiredUsername)
|
err = apper.App().db.CreateUser(apper.App().Config(), u, desiredUsername)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Unable to create user: %s", err)
|
return fmt.Errorf("Unable to create user: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/writeas/web-core/log"
|
"github.com/writeas/web-core/log"
|
||||||
"github.com/writeas/web-core/query"
|
"github.com/writeas/web-core/query"
|
||||||
"github.com/writeas/writefreely/author"
|
"github.com/writeas/writefreely/author"
|
||||||
|
"github.com/writeas/writefreely/config"
|
||||||
"github.com/writeas/writefreely/key"
|
"github.com/writeas/writefreely/key"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type writestore interface {
|
type writestore interface {
|
||||||
CreateUser(*App, *User, string) error
|
CreateUser(*config.Config, *User, string) error
|
||||||
UpdateUserEmail(keys *key.Keychain, userID int64, email string) error
|
UpdateUserEmail(keys *key.Keychain, userID int64, email string) error
|
||||||
UpdateEncryptedUserEmail(int64, []byte) error
|
UpdateEncryptedUserEmail(int64, []byte) error
|
||||||
GetUserByID(int64) (*User, error)
|
GetUserByID(int64) (*User, error)
|
||||||
@ -162,7 +163,7 @@ func (db *datastore) dateSub(l int, unit string) string {
|
|||||||
return fmt.Sprintf("DATE_SUB(NOW(), INTERVAL %d %s)", l, unit)
|
return fmt.Sprintf("DATE_SUB(NOW(), INTERVAL %d %s)", l, unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *datastore) CreateUser(app *App, u *User, collectionTitle string) error {
|
func (db *datastore) CreateUser(cfg *config.Config, u *User, collectionTitle string) error {
|
||||||
if db.PostIDExists(u.Username) {
|
if db.PostIDExists(u.Username) {
|
||||||
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
|
return impart.HTTPError{http.StatusConflict, "Invalid collection name."}
|
||||||
}
|
}
|
||||||
@ -196,7 +197,7 @@ func (db *datastore) CreateUser(app *App, u *User, collectionTitle string) error
|
|||||||
if collectionTitle == "" {
|
if collectionTitle == "" {
|
||||||
collectionTitle = u.Username
|
collectionTitle = u.Username
|
||||||
}
|
}
|
||||||
res, err = t.Exec("INSERT INTO collections (alias, title, description, privacy, owner_id, view_count) VALUES (?, ?, ?, ?, ?, ?)", u.Username, collectionTitle, "", defaultVisibility(app.cfg), u.ID, 0)
|
res, err = t.Exec("INSERT INTO collections (alias, title, description, privacy, owner_id, view_count) VALUES (?, ?, ?, ?, ?, ?)", u.Username, collectionTitle, "", defaultVisibility(cfg), u.ID, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Rollback()
|
t.Rollback()
|
||||||
if db.isDuplicateKeyErr(err) {
|
if db.isDuplicateKeyErr(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user