-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: tags + User auth implementation #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f82e256
1b4eb6c
fada2a4
d9f198e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| RUN go mod download | ||
|
|
||
| EXPOSE 8080 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing line break |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "fmt" | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/jasongauvin/wikiPattern/services" | ||
| "github.com/jasongauvin/wikiPattern/validators" | ||
| "net/http" | ||
| ) | ||
|
|
||
|
|
@@ -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", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
|
@@ -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, | ||
|
|
||
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(®isterForm); 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
| } | ||
| } | ||
| 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing documentation for this exported function |
||
| services.GetProfilePage(c) | ||
| } | ||
There was a problem hiding this comment.
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