Commit 7b60bcd17d1385209bb30b19c0ac6d67a4c37452
1 parent
c05eeb69
Exists in
master
and in
4 other branches
Added docs for password validators
Showing
2 changed files
with
38 additions
and
0 deletions
Show diff stats
docs/source/plugindev.rst
| @@ -189,3 +189,32 @@ Example Usage: | @@ -189,3 +189,32 @@ Example Usage: | ||
| 189 | 189 | ||
| 190 | def get_last_updated_timestamp(self): | 190 | def get_last_updated_timestamp(self): |
| 191 | return TimeStampPlugin.get_last_updated_timestamp('TestPlugin') | 191 | return TimeStampPlugin.get_last_updated_timestamp('TestPlugin') |
| 192 | + | ||
| 193 | + | ||
| 194 | +Password Validation | ||
| 195 | +------------------- | ||
| 196 | + | ||
| 197 | +Allows the plugin to define rules to set the password. The validators | ||
| 198 | +are functions which receive the password as only argument and if it | ||
| 199 | +doesn't match the desired rules raises a `ValidationError`. The message | ||
| 200 | +sent in the validation error will be displayed to user in the HTML form. | ||
| 201 | + | ||
| 202 | +Example: | ||
| 203 | + | ||
| 204 | +.. code-block:: python | ||
| 205 | + | ||
| 206 | + ## myplugin/password_validators.py | ||
| 207 | + | ||
| 208 | + def has_uppercase_char(password): | ||
| 209 | + for char in password: | ||
| 210 | + if char.isupper(): | ||
| 211 | + return | ||
| 212 | + | ||
| 213 | + raise ValidationError('Password must have at least one upper case char') | ||
| 214 | + | ||
| 215 | + ## /etc/colab/plugins.d/myplugin.py | ||
| 216 | + | ||
| 217 | + password_validators = ( | ||
| 218 | + 'myplugin.password_validators.has_uppercase_char', | ||
| 219 | + ) | ||
| 220 | + |
docs/source/user.rst
| @@ -165,6 +165,15 @@ Declares the additional installed apps that this plugin depends on. | @@ -165,6 +165,15 @@ Declares the additional installed apps that this plugin depends on. | ||
| 165 | This doesn't automatically install the python dependecies, only add to django | 165 | This doesn't automatically install the python dependecies, only add to django |
| 166 | apps. | 166 | apps. |
| 167 | 167 | ||
| 168 | +.. attribute:: password_validators | ||
| 169 | + | ||
| 170 | +A lista of functions to validade password in the moment it's set. | ||
| 171 | +This allows plugins to define their own password validators. For | ||
| 172 | +example if the proxied app requires the password to have at least | ||
| 173 | +one upper case character it should provide a password validator | ||
| 174 | +for that. | ||
| 175 | + | ||
| 176 | + | ||
| 168 | urls | 177 | urls |
| 169 | ++++ | 178 | ++++ |
| 170 | 179 |