Added admin IP whitelist feature
Reference post: https://www.howtoforge.com/community/threads/restrict-admin-user-to-white-listed-ip-addresses.80856/
First, I did some refactoring, to make the code a bit more readable, in order to make it obvious where the new feature should be inserted in the code.
The refactoring is done in several smaller steps, so that reviewer(s) can understand the transformations/changes more easily, considering this is the part of the app that is critical to security.
Most of the refactoring is done using immutable transformations, which don't change the logic of the code, but reshape the code layout only. Examples of the transformations used are 'extract method' transformation, as well as 'invert if/else statement' (switches if
/else
bodies) and 'unwrap else' (if the if
body ends with a return
statement, then else
block is redundant / not needed). Also, several times, I had to move the return
statements from the outside of if
/else
blocks into both if
/else
blocks, in order to then simplify each block and continue with immutable transformations. Most of the refactoring has been done with the help of PhpStorm (JetBrains product for PHP - they are well-known for their IDEs which have really powerful refactoring engines for multiple programming languages).
At last, I've added 1 commit with the actual feature itself.
Thank you in advance for reviewing this PR/MR.
Cheers :)