[MM-33395] Invalidate email tokens (#17069)
* [MM-33395] Invalidate existing verify email tokens when creating a new one * Update store layers * Addressing review comments * Fix linter Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b5266c37dc
Коммит
5b99df7bcd
@@ -7,6 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
@@ -74,6 +75,19 @@ func (s SqlTokenStore) Cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlTokenStore) GetAllTokensByType(tokenType string) ([]*model.Token, error) {
|
||||
tokens := []*model.Token{}
|
||||
query, args, err := s.getQueryBuilder().Select("*").From("Tokens").Where(sq.Eq{"Type": tokenType}).ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not build sql query to get all tokens by type")
|
||||
}
|
||||
|
||||
if _, err := s.GetReplica().Select(&tokens, query, args...); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get all tokens of Type=%s", tokenType)
|
||||
}
|
||||
return tokens, nil
|
||||
}
|
||||
|
||||
func (s SqlTokenStore) RemoveAllTokensByType(tokenType string) error {
|
||||
if _, err := s.GetMaster().Exec("DELETE FROM Tokens WHERE Type = :TokenType", map[string]interface{}{"TokenType": tokenType}); err != nil {
|
||||
return errors.Wrapf(err, "failed to remove all Tokens with Type=%s", tokenType)
|
||||
|
||||
Ссылка в новой задаче
Block a user