Overriding a Statamic method #10698
Replies: 2 comments 2 replies
-
Oh dear, how embarrassing, I forgot to add the original file's namespace declaration at the top of my overriding controller! For similar queries in the future, I got it working with creating an overrides directory in the root application folder, created a PasswordController.php file in there and pasted the original file contents of vendor/statamic/Http/Controllers/CP/Users/PasswordController.php and added a couple of lines of code to create an entry in the password_histories table. Then, in composer.json, adjust your "autoload" array key to something similar:
|
Beta Was this translation helpful? Give feedback.
-
Usually, trying to override methods provided by a package (like Statamic) is considered bad practice. What are you trying to add/remove/change about Statamic's |
Beta Was this translation helpful? Give feedback.
-
Hello, I have been asked by management to add password history functionality for up to 5 password hashes to our Statamic (4.460) CMS and it seems I must override the way Statamic saves a user's password to include storing a hash of it in my password_histories table.
I already created a custom validation rule for checking on this table, and a PasswordHistory model, table and all of the bells and whistles it needs to function.
I tried overriding the PasswordController using two methods: one is via binding in the AppServiceProvider.php file and another by adding an "exclude-from-classmap" array with the class to exclude, and include my override file.
I tried both of these methods and none seem to register my overrides. I'm not even sure if this is the correct way of doing it. I've been reading up on overriding vendor classes for two days and trying everything suggested, but none of the methods load my custom PasswordController file. (I don't really want to be overriding Statamic's files, to be honest, but management has requested this for cybersecurity insurance).
What am I doing wrong, and if there's a better way, how should I achieve storing a hash of a user's last 5 passwords in a database table?
Beta Was this translation helpful? Give feedback.
All reactions