mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-01-18 15:36:27 +00:00
small changes
This commit is contained in:
parent
8ae32f0235
commit
471de27582
@ -29,7 +29,7 @@ func NewAuthPresenter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *authPresenter) ResponseJoin(user *models.User) ([]byte, error) {
|
func (p *authPresenter) ResponseJoin(user *models.User) ([]byte, error) {
|
||||||
tokens, err := p.jwtInteractor.NewToken(user, 24*time.Hour)
|
tokens, err := p.jwtInteractor.NewToken(user, 24*time.Hour, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error create access token. %w", err)
|
return nil, fmt.Errorf("error create access token. %w", err)
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ func (p *authPresenter) ResponseJoin(user *models.User) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *authPresenter) ResponseLogin(user *models.User) ([]byte, error) {
|
func (p *authPresenter) ResponseLogin(user *models.User) ([]byte, error) {
|
||||||
tokens, err := p.jwtInteractor.NewToken(user, 24*time.Hour)
|
tokens, err := p.jwtInteractor.NewToken(user, 24*time.Hour, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error create access token. %w", err)
|
return nil, fmt.Errorf("error create access token. %w", err)
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JWTInteractor interface {
|
type JWTInteractor interface {
|
||||||
NewToken(user models.UserIdentity, duration time.Duration) (AccessToken, error)
|
NewToken(user models.UserIdentity, duration time.Duration, remoteAddr string) (AccessToken, error)
|
||||||
User(token string) (*models.User, error)
|
User(token string) (*models.User, error)
|
||||||
RefreshToken(ctx context.Context, token string, rToken string) (AccessToken, error)
|
RefreshToken(ctx context.Context, token string, rToken string) (AccessToken, error)
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ type AccessToken struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewToken creates new JWT token for given user
|
// NewToken creates new JWT token for given user
|
||||||
func (w *jwtInteractor) NewToken(user models.UserIdentity, duration time.Duration) (AccessToken, error) {
|
func (w *jwtInteractor) NewToken(user models.UserIdentity, duration time.Duration, remoteAddr string) (AccessToken, error) {
|
||||||
tokens, err := w.newTokens(user.Id(), duration)
|
tokens, err := w.newTokens(user.Id(), duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AccessToken{}, fmt.Errorf("error create new tokens. %w", err)
|
return AccessToken{}, fmt.Errorf("error create new tokens. %w", err)
|
||||||
|
@ -22,6 +22,8 @@ type AddTokenParams struct {
|
|||||||
RefreshTokenExpiredAt time.Time
|
RefreshTokenExpiredAt time.Time
|
||||||
|
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
|
|
||||||
|
RemoteAddr string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTokenParams struct {
|
type GetTokenParams struct {
|
||||||
@ -73,6 +75,7 @@ func (r *repositorySQL) AddToken(ctx context.Context, params AddTokenParams) err
|
|||||||
"refresh_token",
|
"refresh_token",
|
||||||
"token_expired_at",
|
"token_expired_at",
|
||||||
"refresh_token_expired_at",
|
"refresh_token_expired_at",
|
||||||
|
"remote_addr",
|
||||||
).
|
).
|
||||||
Values(
|
Values(
|
||||||
params.UserId,
|
params.UserId,
|
||||||
@ -80,6 +83,7 @@ func (r *repositorySQL) AddToken(ctx context.Context, params AddTokenParams) err
|
|||||||
params.RefreshToken,
|
params.RefreshToken,
|
||||||
params.TokenExpiredAt,
|
params.TokenExpiredAt,
|
||||||
params.RefreshTokenExpiredAt,
|
params.RefreshTokenExpiredAt,
|
||||||
|
params.RemoteAddr,
|
||||||
).PlaceholderFormat(sq.Dollar)
|
).PlaceholderFormat(sq.Dollar)
|
||||||
|
|
||||||
if _, err := query.RunWith(r.Conn(ctx)).ExecContext(ctx); err != nil {
|
if _, err := query.RunWith(r.Conn(ctx)).ExecContext(ctx); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user