README.md in token_authenticate_me-0.8.0 vs README.md in token_authenticate_me-0.9.0

- old
+ new

@@ -56,16 +56,68 @@ ## Authentication Model The model has 4 concerns: * [Authenticatable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/authenticatable.rb) * [Invitable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/invitable.rb) * [Sessionable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/sessionable.rb) -* -[Passwordable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/passwordable.rb) +* [Passwordable](https://github.com/wildland/token_authenticate_me/blob/master/lib/token_authenticate_me/concerns/models/passwordable.rb) -*tl;dr*: +## Usage +```rb +class MyUser + include TokenAuthenticateMe::Concerns::Models::Authenticatable +end +``` +### Default rules and behavior. * `email` is required, can't be blank, is unique (case insensitive), and must look like an email address. * `password` is required, can not be blank, it must be confirmed (`password_confirmation`), and must be between 8 and 72 characters long. If the model has been persisted `password` can be blank or `nil` which indicates that it should not be changed and will be ignored. * `username` is required, can't be blank, is unique (case insensitive), and only allows alphanumeric values. * To change the `password` or `email` after the model has been persisted, you will need to provide the current password as `current_password`. +* To change the `email` after the model has been persisted, you will need to be confirmed (`email_confirmation`) to change. + +### Custom Validation Rules +If you don't like the validation rules you can customize some of them by using the following override methods and/or writing your own rules. Note that they are additive with the existing rules. + +```ruby +class MyUser + def ignore_password_length_validations? + true # defaults to false + end + + def ignore_username_format_validation? + true # defaults to false + end + + def ignore_email_format_validation? + true # defaults to false + end + + def ignore_email_confirmation_on_change? + false # defaults to true + end +end +``` + +Custom Validation Rules Example +```Ruby +class MyUser + ### Other Code + validates( + :password, + format: { + with: /\A[a-zA-Z0-9]+\Z/, + message: 'only letters and numbers are allowed.' + } # We wanted to have alphanumeric passwords. + if: :password_required? # This triggers the requirements when token_authenticate_me requires them + ) + ### More Code + def ignore_password_length_validations? # We didn't want a password length constraints, but wanted only alphanumeric characters. + true + end + + def ignore_email_confirmation_on_change? # We want users to have to confirm emails to reduce mistakes. + false + end +end +``` ## Code Of Conduct Wildland Open Source [Code Of Conduct](https://github.com/wildland/code-of-conduct)