1414use Doctrine \DBAL \Connection ;
1515use Doctrine \DBAL \Driver \Result as DriverResult ;
1616use Doctrine \DBAL \Result ;
17+ use Doctrine \DBAL \Schema \Schema ;
1718use Doctrine \DBAL \Types \Types ;
1819use Symfony \Component \Security \Core \Authentication \RememberMe \PersistentToken ;
1920use Symfony \Component \Security \Core \Authentication \RememberMe \PersistentTokenInterface ;
2021use Symfony \Component \Security \Core \Authentication \RememberMe \TokenProviderInterface ;
2122use Symfony \Component \Security \Core \Exception \TokenNotFoundException ;
2223
2324/**
24- * This class provides storage for the tokens that is set in "remember me"
25+ * This class provides storage for the tokens that is set in "remember- me"
2526 * cookies. This way no password secrets will be stored in the cookies on
2627 * the client machine, and thus the security is improved.
2728 *
@@ -53,8 +54,7 @@ public function __construct(Connection $conn)
5354 public function loadTokenBySeries (string $ series )
5455 {
5556 // the alias for lastUsed works around case insensitivity in PostgreSQL
56- $ sql = 'SELECT class, username, value, lastUsed AS last_used '
57- .' FROM rememberme_token WHERE series=:series ' ;
57+ $ sql = 'SELECT class, username, value, lastUsed AS last_used FROM rememberme_token WHERE series=:series ' ;
5858 $ paramValues = ['series ' => $ series ];
5959 $ paramTypes = ['series ' => \PDO ::PARAM_STR ];
6060 $ stmt = $ this ->conn ->executeQuery ($ sql , $ paramValues , $ paramTypes );
@@ -87,8 +87,7 @@ public function deleteTokenBySeries(string $series)
8787 */
8888 public function updateToken (string $ series , string $ tokenValue , \DateTime $ lastUsed )
8989 {
90- $ sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed '
91- .' WHERE series=:series ' ;
90+ $ sql = 'UPDATE rememberme_token SET value=:value, lastUsed=:lastUsed WHERE series=:series ' ;
9291 $ paramValues = [
9392 'value ' => $ tokenValue ,
9493 'lastUsed ' => $ lastUsed ,
@@ -114,9 +113,7 @@ public function updateToken(string $series, string $tokenValue, \DateTime $lastU
114113 */
115114 public function createNewToken (PersistentTokenInterface $ token )
116115 {
117- $ sql = 'INSERT INTO rememberme_token '
118- .' (class, username, series, value, lastUsed) '
119- .' VALUES (:class, :username, :series, :value, :lastUsed) ' ;
116+ $ sql = 'INSERT INTO rememberme_token (class, username, series, value, lastUsed) VALUES (:class, :username, :series, :value, :lastUsed) ' ;
120117 $ paramValues = [
121118 'class ' => $ token ->getClass (),
122119 // @deprecated since 5.3, change to $token->getUserIdentifier() in 6.0
@@ -138,4 +135,32 @@ public function createNewToken(PersistentTokenInterface $token)
138135 $ this ->conn ->executeUpdate ($ sql , $ paramValues , $ paramTypes );
139136 }
140137 }
138+
139+ /**
140+ * Adds the Table to the Schema if "remember me" uses this Connection.
141+ */
142+ public function configureSchema (Schema $ schema , Connection $ forConnection ): void
143+ {
144+ // only update the schema for this connection
145+ if ($ forConnection !== $ this ->conn ) {
146+ return ;
147+ }
148+
149+ if ($ schema ->hasTable ('rememberme_token ' )) {
150+ return ;
151+ }
152+
153+ $ this ->addTableToSchema ($ schema );
154+ }
155+
156+ private function addTableToSchema (Schema $ schema ): void
157+ {
158+ $ table = $ schema ->createTable ('rememberme_token ' );
159+ $ table ->addColumn ('series ' , Types::STRING , ['length ' => 88 ]);
160+ $ table ->addColumn ('value ' , Types::STRING , ['length ' => 88 ]);
161+ $ table ->addColumn ('lastUsed ' , Types::DATETIME_MUTABLE );
162+ $ table ->addColumn ('class ' , Types::STRING , ['length ' => 100 ]);
163+ $ table ->addColumn ('username ' , Types::STRING , ['length ' => 200 ]);
164+ $ table ->setPrimaryKey (['series ' ]);
165+ }
141166}
0 commit comments