Add: support insert active user
This commit is contained in:
@@ -23,7 +23,22 @@ func (database *Database) LoginAsAnonymous() (*User, error) {
|
||||
}
|
||||
|
||||
func (database *Database) Register(username string, password string, usertype int64) (*User, error) {
|
||||
_, err := database.stmt.insertUser.Exec(username, password, usertype, 0)
|
||||
countAdmin, err := database.CountAdmin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
active := false
|
||||
if countAdmin == 0 {
|
||||
active = true
|
||||
}
|
||||
|
||||
// active normal user by default
|
||||
if usertype == 2 {
|
||||
active = true
|
||||
}
|
||||
|
||||
_, err = database.stmt.insertUser.Exec(username, password, usertype, active, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -40,3 +55,12 @@ func (database *Database) GetUserById(id int64) (*User, error) {
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (database *Database) CountAdmin() (int64, error) {
|
||||
var count int64
|
||||
err := database.stmt.countAdmin.QueryRow().Scan(&count)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user