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