Skip to content

Commit

Permalink
Merge pull request Hardw01f#45 from Hardw01f/refactor/InstGomod
Browse files Browse the repository at this point in the history
chore: 🤖 introduce go.mod for import local package
  • Loading branch information
Hardw01f authored Jun 8, 2020
2 parents 9a1291f + 4dfe7b2 commit 9072644
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 121 deletions.
27 changes: 27 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module github.com/hardw01f/Vulnerability-goapp

go 1.13

require (
github.com/go-sql-driver/mysql v1.5.0
github.com/hardw01f/vulnerability-goapp v0.0.0-20200608095627-9a1291f40edf // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
)

replace github.com/hardw01f/Vulnerability-goapp/pkg/admin => ./pkg/admin

replace github.com/hardw01f/Vulnerability-goapp/pkg/cookei => ./pkg/cookie

replace github.com/hardw01f/Vulnerability-goapp/pkg/user => ./pkg/user

replace github.com/hardw01f/Vulnerability-goapp/pkg/image => ./pkg/image

replace github.com/hardw01f/Vulnerability-goapp/pkg/login => ./pkg/login

replace github.com/hardw01f/Vulnerability-goapp/pkg/logout => ./pkg/logout

replace github.com/hardw01f/Vulnerability-goapp/pkg/post => ./pkg/post

replace github.com/hardw01f/Vulnerability-goapp/pkg/register => ./pkg/register

replace github.com/hardw01f/Vulnerability-goapp/pkg/search => ./pkg/search
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/hardw01f/vulnerability-goapp v0.0.0-20200608095627-9a1291f40edf h1:4jlqfqANv8ThioC+h0Fxz75tm+zl3Alaav7GQ/Er2eQ=
github.com/hardw01f/vulnerability-goapp v0.0.0-20200608095627-9a1291f40edf/go.mod h1:j334qfhZGFHs1bymGREtSfXoiOXwK/wt9i5PYVbDTTI=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
19 changes: 10 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
_ "github.com/go-sql-driver/mysql"
//login "github.com/Snow-HardWolf/Vulnerability-goapp/pkg/login"

"./pkg/admin"
"./pkg/cookie"
"./pkg/image"
"./pkg/login"
"./pkg/logout"
"./pkg/post"
"./pkg/register"
"./pkg/search"
"./pkg/user"
uploader "github.com/hardw01f/Vulnerability-goapp/pkg/image"

"github.com/hardw01f/Vulnerability-goapp/pkg/admin"
"github.com/hardw01f/Vulnerability-goapp/pkg/cookie"
"github.com/hardw01f/Vulnerability-goapp/pkg/login"
"github.com/hardw01f/Vulnerability-goapp/pkg/logout"
"github.com/hardw01f/Vulnerability-goapp/pkg/post"
"github.com/hardw01f/Vulnerability-goapp/pkg/register"
"github.com/hardw01f/Vulnerability-goapp/pkg/search"
"github.com/hardw01f/Vulnerability-goapp/pkg/user"
)

type Person struct {
Expand Down
5 changes: 3 additions & 2 deletions pkg/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package admin
import (
"database/sql"
"fmt"
"golang.org/x/xerrors"
"html/template"
"log"
"math/rand"
Expand All @@ -12,7 +11,9 @@ import (
"strings"
"time"

"../cookie"
"golang.org/x/xerrors"

"github.com/hardw01f/Vulnerability-goapp/pkg/cookie"
)

type Lists struct {
Expand Down
27 changes: 13 additions & 14 deletions pkg/cookie/cookieManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func CheckSessionID(r *http.Request) bool {
return false
}

if sessionID.Value == "" || userID.Value == "" {
return false
}
if sessionID.Value == "" || userID.Value == "" {
return false
}

uid, err := strconv.Atoi(userID.Value)
if err != nil {
Expand All @@ -84,11 +84,11 @@ func CheckSessionID(r *http.Request) bool {

}

func GetCookieValue(r *http.Request) (SessionID string, UserName string, UserID int, err error){
sessionID, err := r.Cookie("SessionID")
func GetCookieValue(r *http.Request) (SessionID string, UserName string, UserID int, err error) {
sessionID, err := r.Cookie("SessionID")
if err != nil {
fmt.Println(err)
return "","",0,err
return "", "", 0, err
}

userID, err := r.Cookie("UserID")
Expand All @@ -98,19 +98,18 @@ func GetCookieValue(r *http.Request) (SessionID string, UserName string, UserID
uid, err := strconv.Atoi(userID.Value)
if err != nil {
fmt.Println(err)
return "","",0,err
return "", "", 0, err
}

userName, err := r.Cookie("UserName")
if err != nil {
fmt.Println(err)
return "","",0,err
}
userName, err := r.Cookie("UserName")
if err != nil {
fmt.Println(err)
return "", "", 0, err
}

return sessionID.Value, userName.Value, uid, nil
return sessionID.Value, userName.Value, uid, nil
}


func CheckCookieOnlyLogin(r *http.Request) (userNameCookie string, sessionIDCookie string, err error) {
userName, err := r.Cookie("UserName")
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/image/imageUploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"net/http"
"os"

"../cookie"
"../user"
"github.com/hardw01f/Vulnerability-goapp/pkg/cookie"
"github.com/hardw01f/Vulnerability-goapp/pkg/user"
)

type User struct {
Expand Down Expand Up @@ -42,7 +42,7 @@ func ShowImageChangePage(w http.ResponseWriter, r *http.Request) {
}
}

func UpdateDatabase(r *http.Request, imageName string)error{
func UpdateDatabase(r *http.Request, imageName string) error {
_, _, uid, err := cookie.GetCookieValue(r)
if err != nil {
fmt.Printf("%+v\n", err)
Expand All @@ -57,7 +57,7 @@ func UpdateDatabase(r *http.Request, imageName string)error{
defer db.Close()

_, err = db.Exec("update vulnapp.userdetails set userimage = ? where uid = ?", imageName, uid)
if err != nil {
if err != nil {
fmt.Printf("%+v\n", err)
return err
}
Expand Down Expand Up @@ -89,7 +89,7 @@ func UploadImage(w http.ResponseWriter, r *http.Request) {
io.Copy(f, file)
UpdateDatabase(r, handler.Filename)

http.Redirect(w, r, "/profile", 301)
http.Redirect(w, r, "/profile", 301)
}
} else {
http.NotFound(w, nil)
Expand Down
3 changes: 2 additions & 1 deletion pkg/login/login.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package login

import (
"../cookie"
"database/sql"
"encoding/base64"
"fmt"
"log"
"net/http"
"text/template"

"github.com/hardw01f/Vulnerability-goapp/pkg/cookie"
)

type Person struct {
Expand Down
Loading

0 comments on commit 9072644

Please sign in to comment.