mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 11:46:22 -07:00
Implement Staff sql funcs
This commit is contained in:
parent
704d9055b0
commit
2bf2d4aa35
5 changed files with 25 additions and 20 deletions
|
@ -110,7 +110,7 @@ CREATE TABLE DBPREFIXstaff(
|
||||||
password_checksum VARCHAR(120) NOT NULL,
|
password_checksum VARCHAR(120) NOT NULL,
|
||||||
global_rank INT,
|
global_rank INT,
|
||||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_login TIMESTAMP NOT NULL,
|
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||||
UNIQUE(username)
|
UNIQUE(username)
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,7 +110,7 @@ CREATE TABLE DBPREFIXstaff(
|
||||||
password_checksum VARCHAR(120) NOT NULL,
|
password_checksum VARCHAR(120) NOT NULL,
|
||||||
global_rank INT,
|
global_rank INT,
|
||||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_login TIMESTAMP NOT NULL,
|
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||||
UNIQUE(username)
|
UNIQUE(username)
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,7 +110,7 @@ CREATE TABLE DBPREFIXstaff(
|
||||||
password_checksum VARCHAR(120) NOT NULL,
|
password_checksum VARCHAR(120) NOT NULL,
|
||||||
global_rank INT,
|
global_rank INT,
|
||||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_login TIMESTAMP NOT NULL,
|
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||||
UNIQUE(username)
|
UNIQUE(username)
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,7 +110,7 @@ CREATE TABLE DBPREFIXstaff(
|
||||||
password_checksum VARCHAR(120) NOT NULL,
|
password_checksum VARCHAR(120) NOT NULL,
|
||||||
global_rank INT,
|
global_rank INT,
|
||||||
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
added_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_login TIMESTAMP NOT NULL,
|
last_login TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
is_active BOOL NOT NULL DEFAULT TRUE,
|
is_active BOOL NOT NULL DEFAULT TRUE,
|
||||||
UNIQUE(username)
|
UNIQUE(username)
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gochan-org/gochan/pkg/gcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAllNondeletedMessageRaw gets all the raw message texts from the database, saved per id
|
// GetAllNondeletedMessageRaw gets all the raw message texts from the database, saved per id
|
||||||
|
@ -130,28 +132,31 @@ func GetStaffByName(name string) (*Staff, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStaff creates a new staff account from a given username, password and rank
|
// NewStaff creates a new staff account from a given username, password and rank
|
||||||
func NewStaff(username string, password string, rank int) error { //TODO not up to date with old db yet
|
func NewStaff(username string, password string, rank int) error {
|
||||||
// _, err := execSQL("INSERT INTO DBPREFIXstaff (username, password_checksum, rank) VALUES(?,?,?)",
|
const sql = `INSERT INTO DBPREFIXstaff (username, password_checksum, global_rank)
|
||||||
// &username, bcryptSum(password), &rank)
|
VALUES (?, ?, ?);`
|
||||||
// return err
|
_, err := ExecSQL(sql, username, gcutil.BcryptSum(password), rank)
|
||||||
return errors.New("Not implemented")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteStaff deletes the staff with a given name.
|
// DeleteStaff deletes the staff with a given name.
|
||||||
func DeleteStaff(username string) error { //TODO not up to date with old db yet
|
// Implemented to change the account name to a random string and set it to inactive
|
||||||
// _, err := execSQL("DELETE FROM DBPREFIXstaff WHERE username = ?", username)
|
func DeleteStaff(username string) error {
|
||||||
// return err
|
const sql = `UPDATE DBPREFIXstaff SET username = ?, is_active = FALSE WHERE username = ?`
|
||||||
return errors.New("Not implemented")
|
_, err := ExecSQL(sql, gcutil.RandomString(45), username)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateSession inserts a session for a given key and username into the database
|
// CreateSession inserts a session for a given key and username into the database
|
||||||
func CreateSession(key string, username string) error { //TODO not up to date with old db yet
|
func CreateSession(key string, username string) error {
|
||||||
//TODO move amount of time to config file
|
const sql = `INSERT INTO DBPREFIXsessions (staff_id,data,expires) VALUES(?,?,?);
|
||||||
//TODO also set last login
|
UPDATE DBPREFIXstaff SET last_login = CURRENT_TIMESTAMP WHERE id = ?;`
|
||||||
// return execSQL("INSERT INTO DBPREFIXsessions (name,sessiondata,expires) VALUES(?,?,?)",
|
staff, err := GetStaffByName(username)
|
||||||
// key, username, getSpecificSQLDateTime(time.Now().Add(time.Duration(time.Hour*730))),
|
if err != nil {
|
||||||
// )
|
return err
|
||||||
return errors.New("Not implemented")
|
}
|
||||||
|
_, err = ExecSQL(sql, staff.ID, key, time.Now().Add(time.Duration(time.Hour*730)), staff.ID) //TODO move amount of time to config file
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PermanentlyRemoveDeletedPosts removes all posts and files marked as deleted from the database
|
// PermanentlyRemoveDeletedPosts removes all posts and files marked as deleted from the database
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue