@@ -8,31 +8,47 @@ class App extends \Config\App
88{
99 /*
1010 |--------------------------------------------------------------------------
11- | UserLib
11+ | User Library settings
1212 |--------------------------------------------------------------------------
1313 |
1414 | UserLib is a CodeIgniter 4 package that provides a way to add simple user management to your application.
1515 |
1616 */
1717
18+
19+ /*
20+ |--------------------------------------------------------------------------
21+ | Enable Routes
22+ |--------------------------------------------------------------------------
23+ * Enable the routes for login, register, logout
24+ */
25+ public bool $ setUserLibRoutes = true ;
26+
1827 /*
28+ *
1929 * Enable Registration
2030 */
2131 public bool $ userCanRegister = true ;
2232
33+ /*
34+ * //! not used
35+ * Enable Login
36+ */
37+ public bool $ userCanLogin = true ;
38+
2339 /*
2440 * Decide if the user can view all pages by default.
2541 * This rule can be overrided by using the method userCanView() or userCanNotView() from the user helper.
2642 * TODO: Implement this
2743 */
2844 public bool $ userCanViewByDefault = false ;
2945
30- /*
31- * Enable Login
32- */
33- public bool $ userLibLogin = true ;
3446
3547 /*
48+ |--------------------------------------------------------------------------
49+ | Captchas
50+ |--------------------------------------------------------------------------
51+ *
3652 * Enable Captcha
3753 */
3854 public bool $ userLibCaptcha = true ;
@@ -60,6 +76,9 @@ class App extends \Config\App
6076 ];
6177
6278 /*
79+ |--------------------------------------------------------------------------
80+ | User attributes
81+ |--------------------------------------------------------------------------
6382 * User extra attributes
6483 * Example: name, phone, address, etc.
6584 * This is just an example of the structure, the content of the array gets emptied from the constructor
@@ -84,19 +103,67 @@ class App extends \Config\App
84103 ];
85104
86105
106+ /*
107+ |--------------------------------------------------------------------------
108+ | Session hijacking
109+ |--------------------------------------------------------------------------
110+ * Match IP
111+ * If true, the session will be destroyed if the client ip and user agent do not match
112+ * //! WARNING: If you enable this the session will be destroyed every time the IP changes, this can happen if the user is using a mobile device (like a phone) and switches networks
113+ */
114+ public bool $ sessionHijackingMatchIP = false ;
115+
116+ /*
117+ * Match User Agent
118+ * If true, the session will be destroyed if the client ip and user agent do not match
119+ */
120+ public bool $ sessionHijackingMatchUserAgent = false ;
121+
122+
123+ /*
124+ |--------------------------------------------------------------------------
125+ | Brute force attacks
126+ |--------------------------------------------------------------------------
127+ * Error logger
128+ * If true, the user will be blocked after exceeding the maximum number of errors
129+ */
130+ public bool $ userPostErrorLogger = true ;
131+
132+ /*
133+ * Maximum number of errors
134+ * The maximum number of errors allowed in a row
135+ */
136+ public int $ maxPostErrors = 10 ;
137+
138+ /*
139+ * Timeout
140+ * The time in seconds before the counter will be resetted and the time the user will be blocked after exceeding the maximum number of errors
141+ */
142+ public int $ userErrorTimeout = 300 ;
143+
144+
145+ /**
146+ * Inside the constructor we check if the user has set the config options in the app config file, if they do we use their values, otherwise we use the default values
147+ */
87148 public function __construct ()
88149 {
89150 $ appConfig = config (AppConfig::class);
90151
91152 $ this ->userLibCaptchaOptions = array ();
92153 $ this ->userExtraAttributes = array ();
154+ $ this ->setUserLibRoutes = property_exists ($ appConfig , "setUserLibRoutes " ) ? $ appConfig ->setUserLibRoutes : $ this ->setUserLibRoutes ;
93155 $ this ->userCanRegister = property_exists ($ appConfig , "userCanRegister " ) ? $ appConfig ->userCanRegister : $ this ->userCanRegister ;
156+ $ this ->userCanLogin = property_exists ($ appConfig , "userCanLogin " ) ? $ appConfig ->userCanLogin : $ this ->userCanLogin ;
94157 $ this ->userCanViewByDefault = property_exists ($ appConfig , "userCanViewByDefault " ) ? $ appConfig ->userCanViewByDefault : $ this ->userCanViewByDefault ;
95- $ this ->userLibLogin = property_exists ($ appConfig , "userLibLogin " ) ? $ appConfig ->userLibLogin : $ this ->userLibLogin ;
96158 $ this ->userLibCaptcha = property_exists ($ appConfig , "userLibCaptcha " ) ? $ appConfig ->userLibCaptcha : $ this ->userLibCaptcha ;
97159 $ this ->userLibCaptchaType = property_exists ($ appConfig , "userLibCaptchaType " ) ? $ appConfig ->userLibCaptchaType : $ this ->userLibCaptchaType ;
98160 $ this ->userLibCaptchaOptions = property_exists ($ appConfig , "userLibCaptchaOptions " ) ? $ appConfig ->userLibCaptchaOptions : $ this ->userLibCaptchaOptions ;
99161 $ this ->userExtraAttributes = property_exists ($ appConfig , "userExtraAttributes " ) ? $ appConfig ->userExtraAttributes : $ this ->userExtraAttributes ;
162+ $ this ->sessionHijackingMatchIP = property_exists ($ appConfig , "sessionHijackingMatchIP " ) ? $ appConfig ->sessionHijackingMatchIP : $ this ->sessionHijackingMatchIP ;
163+ $ this ->sessionHijackingMatchUserAgent = property_exists ($ appConfig , "sessionHijackingMatchUserAgent " ) ? $ appConfig ->sessionHijackingMatchUserAgent : $ this ->sessionHijackingMatchUserAgent ;
164+ $ this ->userPostErrorLogger = property_exists ($ appConfig , "userPostErrorLogger " ) ? $ appConfig ->userPostErrorLogger : $ this ->userPostErrorLogger ;
165+ $ this ->maxPostErrors = property_exists ($ appConfig , "maxPostErrors " ) ? $ appConfig ->maxPostErrors : $ this ->maxPostErrors ;
166+ $ this ->userErrorTimeout = property_exists ($ appConfig , "userErrorTimeout " ) ? $ appConfig ->userErrorTimeout : $ this ->userErrorTimeout ;
100167
101168 $ allowedCaptchas = ["cloudflare " , "recaptcha-v3 " ];
102169 if (
0 commit comments