This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chi-like syntactic sugar layer on top of stdlib http.ServeMux. | |
package main | |
import ( | |
"net/http" | |
"slices" | |
) | |
type ( | |
middleware func(http.Handler) http.Handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a robust implementation that is extensible for anything that requires the use of OTP. Want to use OTP to verify | |
a user? Check! Want to use OTP to validate an order? CHeck! Want to use OTP to reset a password? CHEck! Want to use | |
OTP to verify a device? CHECk! Want to use OTP to fight people? CHECK! | |
I used: Django (framework), Django Rest Framework (a plugin for REST API), PostgreSQL (database) | |
and email (for sending the otp). You can substitute any of these for whatever you want, like using Redis instead of Postgres. | |
While this solution is built to be used for Django, I have added comments to explain the process for developers using | |
other frameworks. | |
Legend: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
@pytest.fixture | |
def password(): | |
return 'my-password-is-stronger-than-yours' | |
@pytest.fixture | |
def create_user(db, django_user_model, password): | |
def _user(**kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Gist DarkCode ver 0.2.1 | |
* Update 03/12/2021 www.adiman.web.id | |
*/ | |
.gist{font-size: 18px}.gist-meta, .gist-file, .octotree_toggle, ul.comparison-list > li.title,button.button, a.button, span.button, button.minibutton, a.minibutton,span.minibutton, .clone-url-button > .clone-url-link{background: linear-gradient(#202020, #181818) !important;border-color: #383838 !important;border-radius: 0 0 3px 3px !important;text-shadow: none !important;color: #b5b5b5 !important}.markdown-format pre, .markdown-body pre, .markdown-format .highlight pre,.markdown-body .highlight pre, body.blog pre, #facebox pre, .blob-expanded,.terminal, .copyable-terminal, #notebook .input_area, .blob-code-context,.markdown-format code, body.blog pre > code, .api pre, .api code,.CodeMirror,.highlight{background-color: #1D1F21!important;color: #C5C8C6!important}.gist .blob-code{padding: 1px 10px !important;text-align: left;background: #000;border: 0}::selection{background: #24890d;color: #fff;text-shadow: none}::-moz-selection{background: |