Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ WORKDIR /go/src
# Copy the full project to currennt directory
COPY . .
# Run command to nstall the dependencies
RUN go install

CMD go run main.go

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove your go run, you then need to compile and start the binary or nothing will happen

RUN go mod download

EXPOSE 8080

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing line break

19 changes: 19 additions & 0 deletions controllers/ArticleController.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/jasongauvin/wikiPattern/services"
"github.com/jasongauvin/wikiPattern/validators"
"net/http"
)

Expand Down Expand Up @@ -58,6 +59,15 @@ func CreateArticle(c *gin.Context) {
})
case "POST":
var form services.ArticleForm
err := validators.ValidateArticle(&form)
if err != nil {
fmt.Println("error:", err)
c.HTML(
http.StatusBadRequest,
"errors/error.html",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a constant since you'll use this error file pretty often

gin.H{"error": err.Error()})
return
}
if err := c.ShouldBind(&form); err != nil {
fmt.Println("error:", err)
c.HTML(
Expand Down Expand Up @@ -100,6 +110,15 @@ func EditArticleById(c *gin.Context) {
})
case "POST":
var form services.ArticleForm
err := validators.ValidateArticle(&form)
if err != nil {
fmt.Println("error:", err)
c.HTML(
http.StatusBadRequest,
"errors/error.html",
gin.H{"error": err.Error()})
return
}
if err := c.ShouldBind(&form); err != nil {
c.HTML(
http.StatusBadRequest,
Expand Down
83 changes: 83 additions & 0 deletions controllers/SecurityController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package controllers

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/jasongauvin/wikiPattern/models"
"github.com/jasongauvin/wikiPattern/services"
uuid "github.com/satori/go.uuid"
"net/http"
)

func GetRegistrationForm(c *gin.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this exported function

c.HTML(
http.StatusOK,
"security/registration.html",
gin.H{
"title": "Registration",
})
}

func Registration(c *gin.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this exported function

var registerForm services.RegisterForm
if err := c.ShouldBind(&registerForm); err != nil {
fmt.Println("error:", err)
c.HTML(
http.StatusBadRequest,
"errors/error.html",
gin.H{"error": err.Error()})
return
}
userCreated, err := services.SaveUser(registerForm.Email, registerForm.Password)
if err != nil {
c.HTML(
http.StatusUnprocessableEntity,
"errors/error.html",
gin.H{"error": err.Error()})
return
}
sessionKey := uuid.NewV4().String()
session, err := models.CreateUserSession(userCreated, sessionKey)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Souldn't be a model (see comment on the model file)

if err != nil {
c.HTML(
http.StatusUnprocessableEntity,
"errors/error.html",
gin.H{"error": err.Error()})
return
}
c.SetCookie("session_token", session.SessionKey, 3600, "/", "localhost", false, true)
c.Redirect(http.StatusMovedPermanently, "/auth/profile")
c.Abort()
}

func GetLoginForm(c *gin.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this exported function

c.HTML(
http.StatusOK,
"security/login.html",
gin.H{
"title": "Registration",
})
}

func Login(c *gin.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this exported function

var err error
var loginForm services.LoginForm
if err = c.ShouldBind(&loginForm); err != nil {
fmt.Println("error:", err)
c.HTML(
http.StatusBadRequest,
"errors/error.html",
gin.H{"error": err.Error()})
return
}
var userSession *models.UserSession
userSession, err = services.AuthenticateUser(loginForm.Email, loginForm.Password)
if err != nil {
c.AbortWithStatus(http.StatusUnauthorized)
}
if userSession != nil {
c.SetCookie("session_token", userSession.SessionKey, 3600, "/", "localhost", false, true)
c.Redirect(http.StatusMovedPermanently, "/auth/profile")
c.Abort()
}
}
10 changes: 10 additions & 0 deletions controllers/UserController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package controllers

import (
"github.com/gin-gonic/gin"
"github.com/jasongauvin/wikiPattern/services"
)

func GetUserProfile(c *gin.Context) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation for this exported function

services.GetProfilePage(c)
}
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ module github.com/jasongauvin/wikiPattern
go 1.14

require (
github.com/badoux/checkmail v0.0.0-20200623144435-f9f80cb795fa
github.com/caarlos0/env/v6 v6.3.0
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73 // indirect
github.com/foolin/goview v0.3.0
github.com/gin-contrib/sessions v0.0.3 // indirect
github.com/gin-gonic/contrib v0.0.0-20191209060500-d6e26eeaa607 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/go-testfixtures/testfixtures v2.5.1+incompatible // indirect
github.com/go-testfixtures/testfixtures/v3 v3.3.0
github.com/gobuffalo/packr/v2 v2.8.0
github.com/golang/protobuf v1.4.2 // indirect
github.com/gorilla/sessions v1.2.0 // indirect
github.com/jinzhu/gorm v1.9.15
github.com/json-iterator/go v1.1.10 // indirect
github.com/karrick/godirwalk v1.15.6 // indirect
github.com/lib/pq v1.3.0
github.com/rogpeppe/go-internal v1.6.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/spf13/cobra v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/satori/go.uuid v1.2.0
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666 // indirect
golang.org/x/tools v0.0.0-20200721223218-6123e77877b2 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading