Added request verification and url encoding
This commit is contained in:
parent
a35e34b5f0
commit
8b744b2d03
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import urllib
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
@ -11,6 +12,8 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.desk.form.assign_to import add as add_assignemnt
|
from frappe.desk.form.assign_to import add as add_assignemnt
|
||||||
|
from frappe.utils import get_url
|
||||||
|
from frappe.utils.verified_command import verify_request,get_signed_params
|
||||||
|
|
||||||
|
|
||||||
class Appointment(Document):
|
class Appointment(Document):
|
||||||
@ -40,13 +43,23 @@ class Appointment(Document):
|
|||||||
# Set status to unverified
|
# Set status to unverified
|
||||||
self.status = 'Unverified'
|
self.status = 'Unverified'
|
||||||
# Send email to confirm
|
# Send email to confirm
|
||||||
verify_url = ''.join([frappe.utils.get_url(),'/book-appointment/verify?email=',self.customer_email,'&appointment=',self.name])
|
verify_url = self.get_verify_url()
|
||||||
message = ''.join(['Please click the following link to confirm your appointment:',verify_url])
|
message = ''.join(['Please click the following link to confirm your appointment:',verify_url])
|
||||||
frappe.sendmail(recipients=[self.customer_email],
|
frappe.sendmail(recipients=[self.customer_email],
|
||||||
message=message,
|
message=message,
|
||||||
subject=_('Appointment Confirmation'))
|
subject=_('Appointment Confirmation'))
|
||||||
frappe.msgprint('Please check your email to confirm the appointment')
|
frappe.msgprint('Please check your email to confirm the appointment')
|
||||||
|
|
||||||
|
def get_verify_url(self):
|
||||||
|
verify_route = '/book-appointment/verify'
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'email':self.customer_email,
|
||||||
|
'appointment':self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
return get_url(verify_route + '?' + get_signed_params(params))
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
# Sync Calednar
|
# Sync Calednar
|
||||||
if not self.calendar_event:
|
if not self.calendar_event:
|
||||||
@ -60,8 +73,9 @@ class Appointment(Document):
|
|||||||
frappe.throw('Email verification failed.')
|
frappe.throw('Email verification failed.')
|
||||||
# Create new lead
|
# Create new lead
|
||||||
self.create_lead()
|
self.create_lead()
|
||||||
# Create calender event
|
# Remove unverified status
|
||||||
self.status = 'Open'
|
self.status = 'Open'
|
||||||
|
# Create calender event
|
||||||
self.create_calendar_event()
|
self.create_calendar_event()
|
||||||
self.save(ignore_permissions=True)
|
self.save(ignore_permissions=True)
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import frappe
|
import frappe
|
||||||
|
from frappe.utils.verified_command import verify_request
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
|
if not verify_request():
|
||||||
|
context.success = False
|
||||||
|
return context
|
||||||
|
|
||||||
email = frappe.form_dict['email']
|
email = frappe.form_dict['email']
|
||||||
appointment_name = frappe.form_dict['appointment']
|
appointment_name = frappe.form_dict['appointment']
|
||||||
|
|
||||||
if email and appointment_name:
|
if email and appointment_name:
|
||||||
appointment = frappe.get_doc('Appointment',appointment_name)
|
appointment = frappe.get_doc('Appointment',appointment_name)
|
||||||
appointment.set_verified(email)
|
appointment.set_verified(email)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user