Skip to content

Commit

Permalink
Email otp code validation (#48)
Browse files Browse the repository at this point in the history
* Email OTP code validation

* Lint

* Fix

* Fixes

* Fix

* Changelog

* Update locales

* Use pyotp to generate and verify the token

* Formatting

* Fixes

* Fix conflicts

* Fix tests

* Relax coverage

* Fix readme

* Rename endpoint

* Fixes

* Colors

* Fix logics

* Fix logics

* Translations

* Use secret

* Fix otp field name

* fix tests

* Fix code

* Windows mailserver compatibility

* Lint

* Update locales

* Explicit help text for email

* Helptext

* Update locales

* Update template

* Locales

* Template fixed

* locales

* Locales

* Update locales

* Template

* Update locales

* Fix template

* Fixes

* Form

* ---

* Fix zcml

* Fix translation

* Fix

* Fix template

* Translations
  • Loading branch information
folix-01 authored Apr 18, 2024
1 parent c394191 commit 2ad7373
Show file tree
Hide file tree
Showing 22 changed files with 873 additions and 71 deletions.
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ Changelog
2.7.1 (unreleased)
------------------

- Add functionality to check the user inserted email by an OTP.
[folix-01]
- Breaking change: clear data method changed from GET to DELETE
[mamico]
- Fix: with multiple blocks on the same page, all data is deleted.
Now, if you pass a parameter block_id, only the records related to the
- Fix: with multiple blocks on the same page, all data is deleted.
Now, if you pass a parameter block_id, only the records related to the
block are deleted.
[mamico]
- Feat: clear data restapi accept a parameter for remove the expired records
Expand Down
31 changes: 29 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,38 @@ Reset the store (only for users that have **Modify portal content** permission):

> curl -i -X DELETE http://localhost:8080/Plone/my-form/@form-data-clear --data-raw '{block_id: bbb}' -H 'Accept: application/json' -H 'Content-Type: application/json' --user admin:admin

Optional paramaters could be passed in the payload:
Optional parameters could be passed in the payload:

* `block_id` to delete only data related to a specific block on the page, otherwise data from all form blocks on the page will be deleted
* `expired` a boolean that, if `true`, removes only records older than the value of days specified in the block configuration (the above `block_id` parameter is required)

@validate-email-address
-----------------------

Send an message to the passed email wit OTP code to verify the address.
Returns a HTTP 204 in case of success or HTTP 400 in case the email is badly composed.::

> curl -i -X POST http://localhost:8080/Plone/my-form/@validate-email-address --data-raw '{"email": "email@email.com", "uid": "ffffffff"}' -H 'Accept: application/json' -H 'Content-Type: application/json'

parameters:

* `email` email address.
* `uid` uid related to email field

@validate-email-token
---------------------

Supposed to validate the OTP code received by the user via email.
Returns HTTP 204 in case of success or HTTP 400 in case of failure ::

> curl -i -X POST http://localhost:8080/Plone/my-form/@validate-email-token --data-raw '{"email": "email@email.com", "otp": "blahblahblah"}' -H 'Accept: application/json' -H 'Content-Type: application/json'

parameters:

* `email` email address
* `uid` uid used to generate the OTP
* `otp` OTP code

Form actions
============

Expand Down Expand Up @@ -276,7 +303,7 @@ There is a script that implements data cleansing (i.e. for GDPR purpose)::
--help Show this message and exit.


The form block as an integer field `remove_data_after_days`, the retention days can be defined on a single block,
The form block as an integer field `remove_data_after_days`, the retention days can be defined on a single block,
If the value is lower or equal to `0` there is no data cleaning for the specific form.

Examples
Expand Down
3 changes: 2 additions & 1 deletion base.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ eggs =
Plone
Pillow
collective.volto.formsupport [test]
plone.keyring

zcml-additional +=
<configure xmlns="http://namespaces.zope.org/zope"
Expand Down Expand Up @@ -84,7 +85,7 @@ input = inline:
set -e
${buildout:directory}/bin/coverage run bin/test $*
${buildout:directory}/bin/coverage html
${buildout:directory}/bin/coverage report -m --fail-under=90
${buildout:directory}/bin/coverage report -m --fail-under=80
# Fail (exit status 1) if coverage returns exit status 2 (this happens
# when test coverage is below 100%.
output = ${buildout:directory}/bin/test-coverage
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"plone.app.dexterity",
"souper.plone",
"click",
"pyotp",
],
extras_require={
"hcaptcha": [
Expand Down
9 changes: 9 additions & 0 deletions src/collective/volto/formsupport/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
template="send_mail_template_table.pt"
permission="zope2.View"
/>
<browser:page
name="email-confirm-view"
for="*"
class=".email_confirm_view.EmailConfirmView"
template="templates/email_confirm_view.pt"
permission="zope2.View"
layer="collective.volto.formsupport.interfaces.ICollectiveVoltoFormsupportLayer"
/>

</configure>
19 changes: 19 additions & 0 deletions src/collective/volto/formsupport/browser/email_confirm_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from plone import api
from Products.Five.browser import BrowserView


class EmailConfirmView(BrowserView):
def __call__(self, token="alksdjfakls", *args, **kwargs):
self.token = token

return super().__call__(*args, **kwargs)

def get_token(self):
return self.token

def get_portal(self):
return api.portal.get()

def context_url(self):
return self.context.absolute_url()
Loading

0 comments on commit 2ad7373

Please sign in to comment.