refactor: improve user feedback messages in portal account creation and OTP validation
This commit is contained in:
parent
a856b8df56
commit
b9a916cd0a
|
|
@ -23,9 +23,10 @@ class CreatePortalAccount(http.Controller):
|
|||
|
||||
# Validate required fields
|
||||
if not login:
|
||||
msg = _("Login is required.")
|
||||
data = {
|
||||
'status': False,
|
||||
'message': 'login is required.'
|
||||
'message': msg
|
||||
}
|
||||
return json.dumps(data)
|
||||
|
||||
|
|
@ -130,11 +131,11 @@ class CreatePortalAccount(http.Controller):
|
|||
'is_donor': True,
|
||||
'is_sponsor_portal': True,
|
||||
})
|
||||
|
||||
msg = _("Portal account created successfully. An OTP has been sent to your mobile phone.")
|
||||
# Return success response
|
||||
data = {
|
||||
'status': True,
|
||||
'message': 'User and benefit record created successfully.',
|
||||
'message': msg,
|
||||
'user_id': user.id,
|
||||
'grant_benefit_id': grant_benefit.id if grant_benefit else False,
|
||||
}
|
||||
|
|
@ -171,9 +172,10 @@ class CreatePortalAccount(http.Controller):
|
|||
}
|
||||
# Replace with your desired link
|
||||
else:
|
||||
message = _("Invalid OTP. Please try again.")
|
||||
# If OTP validation fails, return an error
|
||||
data = {
|
||||
'status': False,
|
||||
'message': 'OTP not valid',
|
||||
'message': message,
|
||||
}
|
||||
return request.make_response(json.dumps(data), headers={'Content-Type': 'application/json'})
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from odoo import http
|
||||
from odoo import http, _
|
||||
from odoo.http import request
|
||||
from odoo.addons.web.controllers.main import Home
|
||||
import random
|
||||
|
|
@ -7,12 +7,14 @@ import json
|
|||
class AuthSignInHome(Home):
|
||||
@http.route('/generate_otp', type='http', auth="public", website=True)
|
||||
def generate_otp(self, **kw):
|
||||
msg = _("No user found with the provided mobile phone number.")
|
||||
data = {
|
||||
'status': False,
|
||||
'msg': 'No user linked to this phone number!'
|
||||
'msg': msg
|
||||
}
|
||||
if not kw.get('otp_mobile_phone'):
|
||||
data['msg'] = 'No mobile phone number provided for OTP!'
|
||||
msg = _("Please provide a mobile phone number.")
|
||||
data['msg'] = msg
|
||||
else:
|
||||
# Get the target boolean field name for the account_type
|
||||
target_field = request.env['res.partner'].sudo().get_partner_target_account_type(kw.get('account_type'))
|
||||
|
|
@ -23,8 +25,9 @@ class AuthSignInHome(Home):
|
|||
('partner_id.%s' % target_field, '=', True)
|
||||
], limit=1)
|
||||
if user:
|
||||
msg = _("OTP has been sent to your mobile phone number.")
|
||||
data['status'] = True
|
||||
data['msg'] = 'OTP is generated and sent successfully!'
|
||||
data['msg'] = msg
|
||||
user.generate_otp()
|
||||
|
||||
return json.dumps(data)
|
||||
|
|
@ -52,9 +55,10 @@ class AuthSignInHome(Home):
|
|||
}
|
||||
else:
|
||||
# OTP validation failed
|
||||
msg = _("Invalid OTP. Please try again.")
|
||||
data = {
|
||||
'status': False,
|
||||
'msg': 'OTP not valid',
|
||||
'msg': msg,
|
||||
}
|
||||
|
||||
return request.make_response(json.dumps(data), headers={'Content-Type': 'application/json'})
|
||||
Loading…
Reference in New Issue