Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
feat: return a json without sensitive information
Browse files Browse the repository at this point in the history
  • Loading branch information
youngtrashbag committed Jul 8, 2020
1 parent 2fcf63c commit c164e97
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/mysql/create-user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ GRANT insert ON toolset.* TO 'toolset_insert'@'localhost';

-- only delete
CREATE USER 'toolset_delete'@'localhost' IDENTIFIED BY 'password';
GRANT permission ON toolset.* TO 'toolset_delete'@'localhost';
GRANT delete ON toolset.* TO 'toolset_delete'@'localhost';

-- only update
CREATE USER 'toolset_update'@'localhost' IDENTIFIED BY 'password';
GRANT permission ON toolset.* TO 'toolset_update'@'localhost';
GRANT update ON toolset.* TO 'toolset_update'@'localhost';
1 change: 1 addition & 0 deletions src/user/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func GetByID(id int64) User {
log.Panicln(userRows.Err())
}

log.Printf("id: %s usrname: %s\n",string(u.ID), u.Username)
if u.ID == 0 && u.Email == "" && u.Username == "" {
// when there is no entry found, return id = -1
u.ID = -1
Expand Down
21 changes: 14 additions & 7 deletions src/user/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ package user
import (
"bytes"
"encoding/json"
"github.com/gorilla/mux"
"github.com/youngtrashbag/toolset/src/database"
"io/ioutil"
"log"
"net/http"
"strconv"
"time"

"github.com/gorilla/mux"
"github.com/youngtrashbag/toolset/src/database"
)

type jUser struct {
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
password string
CreationDate time.Time `json:"creation_date"`
CreationDate string `json:"creation_date"`
}

// APIHandleCreate : handles the creation a user
Expand Down Expand Up @@ -82,7 +79,17 @@ func APIHandleByID(res http.ResponseWriter, req *http.Request) {
u := GetByID(int64(id))

if u.ID != -1 {
json.NewEncoder(res).Encode(u)

var t string
database.ConvertTime(&u.CreationDate, &t)
j := jUser{
ID: u.ID,
Username: u.Username,
Email: u.Email,
CreationDate: t,
}

json.NewEncoder(res).Encode(j)
res.WriteHeader(http.StatusOK)
} else {
//user not in database
Expand Down

0 comments on commit c164e97

Please sign in to comment.