R sir ne condition lagayi hai ::
yahan tak ki condition lagayi ::
...................................................................................................................................
otp.save
if params[:data][:type] == "login_with_otp"
if otp.class.name == "AccountBlock::SmsOtp"
account = AccountBlock::Account.find_by(full_phone_number: otp.full_phone_number)
else
account = AccountBlock::Account.find_by(email: otp.email)
end
token = BuilderJsonWebToken.encode(account.id)
# Delete OTP object as it's not needed anymore
otp.destroy
return render json: {meta: {account: account, token: token, profile_id: account&.profile&.id}}
...................................................................................................................................
iske bad code aise hua hai ::
# Check OTP code
if otp.pin == create_params[:otp_code].to_i
otp.activated = true
otp.save
if params[:data][:type] == "login_with_otp"
if otp.class.name == "AccountBlock::SmsOtp"
account = AccountBlock::Account.find_by(full_phone_number: otp.full_phone_number)
else
account = AccountBlock::Account.find_by(email: otp.email)
end
token = BuilderJsonWebToken.encode(account.id)
# Delete OTP object as it's not needed anymore
otp.destroy
return render json: {meta: {account: account, token: token, profile_id: account&.profile&.id}}
else
render json: {
messages: [{
otp: 'OTP validation success',
}],
}, status: :created
end
else
return render json: {
errors: [{
otp: 'Invalid OTP provided',
}],
}, status: :unprocessable_entity
end
else
return render json: {
errors: [{
otp: 'Token and OTP code are required',
}],
}, status: :unprocessable_entity
end
end
Comments
Post a Comment