move reCaptcha keys into settings

This commit is contained in:
2022-06-09 16:35:37 +02:00
parent 0203ac065a
commit bf936c90d8
4 changed files with 12 additions and 7 deletions

View File

@@ -159,7 +159,7 @@
</div> </div>
<textarea class="form-control" id="comments" name="comments" placeholder="Message - Tin nhắn" required rows="5"></textarea> <textarea class="form-control" id="comments" name="comments" placeholder="Message - Tin nhắn" required rows="5"></textarea>
<br> <br>
<div class="g-recaptcha" data-sitekey="6LeDvVUgAAAAAOqD_-h93kd5aW8CmpeVvKYu-m0p" data-callback='recaptchaCallback'></div> <div class="g-recaptcha" data-sitekey="{{ site_key }}" data-callback='recaptchaCallback'></div>
<input type="hidden" id="response" name="response" value="" /> <input type="hidden" id="response" name="response" value="" />
<br> <br>
<button class="btn btn-primary hidden" id="btnSubmit" type="submit" name="form.submitted">Envoyer</button> <button class="btn btn-primary hidden" id="btnSubmit" type="submit" name="form.submitted">Envoyer</button>

View File

@@ -53,7 +53,7 @@ def home(request):
response = request.params['response'] response = request.params['response']
# verification reCaptcha ? # verification reCaptcha ?
ok, erreur = captcha_verify(response, request.remote_addr) ok, erreur = captcha_validate(response, request.remote_addr, request.registry.settings['secret_key'])
if ok and comments != '': if ok and comments != '':
# no, message is not spam, send it # no, message is not spam, send it
body = """ body = """
@@ -72,7 +72,7 @@ webmaster@meditation-sunyata.paris
""".format(name, email, comments) """.format(name, email, comments)
message = Message(subject="[MSParis] Message de contact", message = Message(subject="[MSParis] Message de contact",
sender=request.registry.settings['cao_blogr.admin_email'], sender=request.registry.settings['admin_email'],
body=body) body=body)
message.add_recipient('phuoc@caotek.fr') message.add_recipient('phuoc@caotek.fr')
mailer = request.registry['mailer'] mailer = request.registry['mailer']
@@ -87,12 +87,13 @@ webmaster@meditation-sunyata.paris
'name': name, 'name': name,
'email': email, 'email': email,
'comments': comments, 'comments': comments,
'site_key' : request.registry.settings['site_key'],
} }
def captcha_verify(response, remote_addr): def captcha_validate(response, remote_addr, secret):
VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify' VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify'
data = { data = {
'secret': '6LeDvVUgAAAAAGASZXCmcmhh-KtBWTZjXpLpKdNt', 'secret': secret,
'response': response, 'response': response,
'remoteip': remote_addr, 'remoteip': remote_addr,
} }

View File

@@ -18,11 +18,15 @@ sqlalchemy.url = sqlite:///%(here)s/cao_blogr.sqlite
# images location # images location
images_dir = /pyramid10/cao_sunyata/cao_blogr/static/img/ images_dir = /pyramid10/cao_sunyata/cao_blogr/static/img/
# reCaptcha keys
site_key = 6LeDvVUgAAAAAOqD_-h93kd5aW8CmpeVvKYu-m0p
secret_key = 6LeDvVUgAAAAAGASZXCmcmhh-KtBWTZjXpLpKdNt
# Mailer configuration # Mailer configuration
# cao_blogr.admin_email = cao.thien-phuoc@orange.fr # cao_blogr.admin_email = cao.thien-phuoc@orange.fr
# mail.host = smtp.orange.fr # mail.host = smtp.orange.fr
# mail.port = 25 # mail.port = 25
cao_blogr.admin_email = phuoc@caotek.fr admin_email = phuoc@caotek.fr
mail.host = smtp.gmail.com mail.host = smtp.gmail.com
mail.port = 465 mail.port = 465
mail.ssl = True mail.ssl = True

View File

@@ -19,7 +19,7 @@ images_dir = /pyramid10/cao_sunyata/cao_blogr/static/img/
# Mailer configuration # Mailer configuration
# mail.host = localhost # mail.host = localhost
# mail.port = 25 # mail.port = 25
cao_blogr.admin_email = phuoc@caotek.fr admin_email = phuoc@caotek.fr
mail.host = smtp.gmail.com mail.host = smtp.gmail.com
mail.port = 465 mail.port = 465
mail.ssl = True mail.ssl = True