CuriousLearner / django-phone-verify

A Django app to support phone number verification using security code / One-Time-Password (OTP) sent via SMS.
https://www.sanyamkhurana.com/django-phone-verify/
GNU General Public License v3.0
258 stars 61 forks source link

Add ability to customize message format in the #97

Open vaughnkoch opened 5 months ago

vaughnkoch commented 5 months ago

Hi, currently you can customize DPV by extending BaseBackend. Would it be possible to allow PhoneVerificationService to check whether the backend wants to supply the message directly, instead of having it only pull from settings.PHONE_VERIFICATION['MESSAGE']?

Specifically, allow the backend to replace this logic:

def _generate_message(self, security_code):
    return self.verification_message.format(
        app=settings.PHONE_VERIFICATION.get("APP_NAME", DEFAULT_APP_NAME),
        security_code=security_code,
    )
CuriousLearner commented 1 week ago

Hi @vaughnkoch

Can you please let me know about your exact use-case here? 🤔 I'm trying to understand what you are trying to accomplish.

vaughnkoch commented 1 week ago

Hi, to be honest I don't recall the exact use case since this was 6 months ago. But in general, it would be useful to be able to customize the message since currently the only variables allowed are app and security_code, and the rest of the message has to be determined at import time, not runtime. So you can't say for example 'Hello, {user_name}, your code is {security_code}`.

This should be straightforward enough if the BaseBackend can call an optionally-defined function, or allow the message generation function to be overridden by a subclass.