Skip to content

Commit 3f0cf82

Browse files
committed
Minor fixes, removing authentication
1 parent 0cd6b7b commit 3f0cf82

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

server/category.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010

1111
// GetCat - Retrieve a category from the database
1212
func GetCat(collection *mongo.Collection, id int, token string) *Category {
13-
if !validToken(token) {
14-
return nil
15-
}
13+
// if !validToken(token) {
14+
// return nil
15+
// }
1616

1717
var result *Category
1818
filter := bson.D{{"categoryID", id}}
@@ -28,9 +28,9 @@ func GetCat(collection *mongo.Collection, id int, token string) *Category {
2828

2929
// NewCat - Add a new category
3030
func NewCat(collection *mongo.Collection, catID int, index int, name string, token string) {
31-
if !validToken(token) {
32-
return
33-
}
31+
// if !validToken(token) {
32+
// return
33+
// }
3434

3535
category := Category{
3636
categoryID: catID,
@@ -46,9 +46,9 @@ func NewCat(collection *mongo.Collection, catID int, index int, name string, tok
4646

4747
// PatchCat - Update a category with new information
4848
func PatchCat(collection *mongo.Collection, catID int, name string, index int, token string) {
49-
if !validToken(token) {
50-
return
51-
}
49+
// if !validToken(token) {
50+
// return
51+
// }
5252

5353
filter := bson.D{{"categoryID", catID}}
5454
update := bson.D{
@@ -67,9 +67,9 @@ func PatchCat(collection *mongo.Collection, catID int, name string, index int, t
6767

6868
// DeleteCat - Delete a category from the database
6969
func DeleteCat(collection *mongo.Collection, id int, token string) {
70-
if !validToken(token) {
71-
return
72-
}
70+
// if !validToken(token) {
71+
// return
72+
// }
7373

7474
filter := bson.D{{"categoryID", id}}
7575

server/post.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ func GetAllPosts(collection *mongo.Collection, count int, cat string) []*Post {
6464

6565
// NewPost - Add a new post
6666
func NewPost(collection *mongo.Collection, id int, category int, showInMenu bool, title string, subtitle string, postType string, content string, github string, fb string) {
67+
currtime := time.Now()
6768
post := Post{
6869
postID: id,
6970
postTitle: title,
7071
postSubtitle: subtitle,
7172
postType: postType,
7273
postCategory: category,
73-
createdOn: time.Now(),
74-
lastEditedOn: time.Now(),
74+
createdOn: currtime.Unix(),
75+
lastEditedOn: currtime.Unix(),
7576
postContent: content,
7677
postLinkGithub: github,
7778
postLinkFacebook: fb,

server/server.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log"
66
"net/http"
77
"strconv"
8-
"time"
98

109
"github.com/dgrijalva/jwt-go"
1110
"github.com/google/uuid"
@@ -25,8 +24,8 @@ type Post struct {
2524
postSubtitle string
2625
postType string
2726
postCategory int
28-
createdOn time.Time
29-
lastEditedOn time.Time
27+
createdOn int64
28+
lastEditedOn int64
3029
postContent string
3130
postLinkGithub string
3231
postLinkFacebook string
@@ -110,14 +109,14 @@ func serveAPI(e *echo.Echo) {
110109
postsCollection := client.Database("csesoc").Collection("posts")
111110
catCollection := client.Database("csesoc").Collection("categories")
112111
sponsorCollection := client.Database("csesoc").Collection("sponsors")
113-
userCollection := client.Database("csesoc").Collection("users")
112+
// userCollection := client.Database("csesoc").Collection("users")
114113

115114
// Add more API routes here
116115
e.GET("/api/v1/test", func(c echo.Context) error {
117116
return c.String(http.StatusOK, "Hello, World!")
118117
})
119118

120-
e.POST("/login/", login(userCollection))
119+
// e.POST("/login/", login(userCollection))
121120

122121
// Routes for posts
123122
e.GET("/post/:id/", getPost(postsCollection))
@@ -137,17 +136,17 @@ func serveAPI(e *echo.Echo) {
137136
e.DELETE("/sponsor/", deleteSponsor(sponsorCollection))
138137
}
139138

140-
func login(collection *mongo.Collection) echo.HandlerFunc {
141-
return func(c echo.Context) error {
142-
zid := c.FormValue("zid")
143-
password := c.FormValue("password")
144-
permissions := c.FormValue("permissions")
145-
tokenString := Auth(collection, zid, password, permissions)
146-
return c.JSON(http.StatusOK, H{
147-
"token": tokenString,
148-
})
149-
}
150-
}
139+
// func login(collection *mongo.Collection) echo.HandlerFunc {
140+
// return func(c echo.Context) error {
141+
// zid := c.FormValue("zid")
142+
// password := c.FormValue("password")
143+
// permissions := c.FormValue("permissions")
144+
// tokenString := Auth(collection, zid, password, permissions)
145+
// return c.JSON(http.StatusOK, H{
146+
// "token": tokenString,
147+
// })
148+
// }
149+
// }
151150

152151
func getPost(collection *mongo.Collection) echo.HandlerFunc {
153152
return func(c echo.Context) error {

server/sponsor.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
// NewSponsor - Add a new sponsor
1414
func NewSponsor(collection *mongo.Collection, expiryStr string, name string, logo string, tier string, token string) {
15-
if !validToken(token) {
16-
return
17-
}
15+
// if !validToken(token) {
16+
// return
17+
// }
1818

1919
expiryTime, _ := time.Parse(time.RFC3339, expiryStr)
2020
id := uuid.New()
@@ -35,9 +35,9 @@ func NewSponsor(collection *mongo.Collection, expiryStr string, name string, log
3535

3636
// DeleteSponsor - Delete a sponsor from the database
3737
func DeleteSponsor(collection *mongo.Collection, id string, token string) {
38-
if !validToken(token) {
39-
return
40-
}
38+
// if !validToken(token) {
39+
// return
40+
// }
4141

4242
parsedID := uuid.Must(uuid.Parse(id))
4343

@@ -48,3 +48,10 @@ func DeleteSponsor(collection *mongo.Collection, id string, token string) {
4848
log.Fatal(err)
4949
}
5050
}
51+
52+
func GetSponsor(collection *mongo.Collection, id string, token string) {
53+
parsedID := uuid.Must(uuid.Parse(id))
54+
55+
filter := bson.D{{"sponsorID".parsedID}}
56+
_, err := collection.FindOne()
57+
}

0 commit comments

Comments
 (0)