Skip to content

Commit

Permalink
change SecureKey to TransmissionKey
Browse files Browse the repository at this point in the history
  • Loading branch information
yakuter committed Jun 15, 2020
1 parent 84025c5 commit 6bab5f1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions internal/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func Signin(s storage.Store) http.HandlerFunc {
s.Tokens().Delete(int(user.ID))

//create tokens on db
s.Tokens().Save(int(user.ID), token.AtUUID, token.AccessToken, token.AtExpiresTime, token.SecureKey)
s.Tokens().Save(int(user.ID), token.AtUUID, token.AccessToken, token.AtExpiresTime, token.TransmissionKey)
s.Tokens().Save(int(user.ID), token.RtUUID, token.RefreshToken, token.RtExpiresTime, "")

authLoginResponse := model.AuthLoginResponse{
AccessToken: token.AccessToken,
RefreshToken: token.RefreshToken,
SecureKey: token.SecureKey,
UserDTO: model.ToUserDTO(user),
AccessToken: token.AccessToken,
RefreshToken: token.RefreshToken,
TransmissionKey: token.TransmissionKey,
UserDTO: model.ToUserDTO(user),
}

RespondWithJSON(w, 200, authLoginResponse)
Expand Down Expand Up @@ -197,14 +197,14 @@ func RefreshToken(s storage.Store) http.HandlerFunc {
s.Tokens().Delete(int(userid))

//create tokens on db
s.Tokens().Save(int(userid), newtoken.AtUUID, newtoken.AccessToken, newtoken.AtExpiresTime, newtoken.SecureKey)
s.Tokens().Save(int(userid), newtoken.AtUUID, newtoken.AccessToken, newtoken.AtExpiresTime, newtoken.TransmissionKey)
s.Tokens().Save(int(userid), newtoken.RtUUID, newtoken.RefreshToken, newtoken.RtExpiresTime, "")

authLoginResponse := model.AuthLoginResponse{
AccessToken: newtoken.AccessToken,
RefreshToken: newtoken.RefreshToken,
SecureKey: newtoken.SecureKey,
UserDTO: model.ToUserDTO(user),
AccessToken: newtoken.AccessToken,
RefreshToken: newtoken.RefreshToken,
TransmissionKey: newtoken.TransmissionKey,
UserDTO: model.ToUserDTO(user),
}

RespondWithJSON(w, 200, authLoginResponse)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CreateToken(user *model.User) (*model.TokenDetailsDTO, error) {
return nil, err
}

td.SecureKey = GenerateSecureKey(32)
td.TransmissionKey = GenerateSecureKey(32)

return td, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type EmailRepository interface {
// TODO: Add explanation to functions in TokenRepository
type TokenRepository interface {
Any(uuid string) bool
Save(userid int, uuid uuid.UUID, tkn string, expriydate time.Time, secureKey string)
Save(userid int, uuid uuid.UUID, tkn string, expriydate time.Time, transmissionKey string)
Delete(userid int)
DeleteByUUID(uuid string)
Migrate() error
Expand Down
12 changes: 6 additions & 6 deletions internal/storage/token/token_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (p *Repository) Any(uuid string) bool {

}

func (p *Repository) Save(userid int, uid uuid.UUID, tkn string, expriydate time.Time, secureKey string) {
func (p *Repository) Save(userid int, uid uuid.UUID, tkn string, expriydate time.Time, transmissionKey string) {

token := &model.Token{
UserID: userid,
UUID: uid,
Token: tkn,
ExpiryTime: expriydate,
SecureKey: secureKey,
UserID: userid,
UUID: uid,
Token: tkn,
ExpiryTime: expriydate,
TransmissionKey: transmissionKey,
}
p.db.Create(token)

Expand Down
20 changes: 10 additions & 10 deletions model/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type AuthLoginDTO struct {

//AuthLoginResponse ...
type AuthLoginResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
SecureKey string `json:"secure_key"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
TransmissionKey string `json:"transmission_key"`
*UserDTO
}

//TokenDetailsDTO ...
type TokenDetailsDTO struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
AtExpiresTime time.Time
RtExpiresTime time.Time
AtUUID uuid.UUID
RtUUID uuid.UUID
SecureKey string `json:"secure_key"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
AtExpiresTime time.Time
RtExpiresTime time.Time
AtUUID uuid.UUID
RtUUID uuid.UUID
TransmissionKey string `json:"transmission_key"`
}
12 changes: 6 additions & 6 deletions model/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

type Token struct {
ID int `gorm:"primary_key" json:"id"`
UserID int
UUID uuid.UUID `gorm:"type:uuid;type:varchar(100);"`
Token string `gorm:"type:text;"`
SecureKey string `gorm:"type:text;"`
ExpiryTime time.Time
ID int `gorm:"primary_key" json:"id"`
UserID int
UUID uuid.UUID `gorm:"type:uuid;type:varchar(100);"`
Token string `gorm:"type:text;"`
TransmissionKey string `gorm:"type:text;"`
ExpiryTime time.Time
}

0 comments on commit 6bab5f1

Please sign in to comment.