Skip to content

Commit 6aaf7d6

Browse files
committed
adding admin user
1 parent be6faed commit 6aaf7d6

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Struct/struct.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package structure
22

33
type UserAccount struct {
4-
Id int
5-
Name string //Name of the user
6-
Image string //Path src
7-
Email string
8-
UUID string
9-
Password string
10-
Post []Post
11-
Comment []Comment
12-
Admin bool //true: the user is the Admin
13-
Moderatteur bool
14-
Connected bool
4+
Id int
5+
Name string //Name of the user
6+
Image string //Path src
7+
Email string
8+
UUID string
9+
Password string
10+
Post []Post
11+
Comment []Comment
12+
Admin bool //true: the user is the Admin
13+
Moderateur bool
14+
Connected bool
1515
}
1616

1717
type Comment struct {

data/dataBase.go

+8
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,14 @@ func DataBaseRegister(email string, password string) bool {
226226

227227
}
228228

229+
func AddingAdminUser() {
230+
_, err := Db.Exec("INSERT INTO users (name, image, email, uuid, password, admin) VALUES (?, ?, ?,?,?,?)", "admin", "../assets/images/beehive-37436.svg", "admin", "admin", script.GenerateHash("adminadmin"), true)
231+
if err != nil {
232+
log.Fatal(err)
233+
}
234+
235+
}
236+
229237
func GetAllUsers() []structure.UserAccount {
230238
rows, err := Db.Query("SELECT id,name,image,email,uuid,password,admin FROM users ORDER BY id")
231239
if err != nil {

scripts/cryptage.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package script
22

33
import (
4+
"fmt"
45
"log"
56
"math/rand"
67
"time"
@@ -16,6 +17,7 @@ func GenerateHash(password string) string {
1617
cost := 11
1718
mpCrypt, err := bcrypt.GenerateFromPassword([]byte(password), cost)
1819
if err != nil {
20+
fmt.Println("Error in GenerateHash:")
1921
log.Fatal(err)
2022
}
2123

server.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func erreur(w http.ResponseWriter, r *http.Request) {
5555
func main() {
5656
dataBase.CreateDataBase()
5757
homefeed = data.HomeFeedPost()
58+
data.AddingAdminUser()
5859
uAccount = data.GetAllUsers()
5960
defer data.Db.Close()
6061

0 commit comments

Comments
 (0)