So the first piece of code is the backend end point and second is the front end. It does not send the token to an email address on the server or using Postman raw data. But it does send a token using form-data. Any ideas I'm new to this. thanks
class RegisterView(View):
def post(self, request, *args, **kwargs):
data = request.POST.get('email')
check_if_email_exists = []
for email in Registration.objects.all().values_list('email', flat=True):
check_if_email_exists.append(email)
if data in check_if_email_exists:
return JsonResponse('Email already provided', safe=False, status=200)
else:
new_user = Registration.objects.create(email=data)
new_user.save()
content = {'code': new_user.code}
send_mail(
"Thanks for Registering",
f'Here is your signup Token:{content}',
'djangod192@gmail.com',
[data],
fail_silently=False,
)
return JsonResponse(content, status=201)
const SignUpStep1 = () => {
const navigate = useNavigate();
const [email,setEmail] = useState("");
const dispatch = useDispatch();
const url = "https://motion.propulsion-learn.ch/app/api/auth/registration/";
const updateEmail = (event) => {
setEmail(event.target.value);
}
const sendVerificationCode = (event) => {
event.preventDefault();
if (email.length > 0) {
const data = {
email: email
};
const fetchConfig = {
method: 'POST',
headers: new Headers({
"Content-Type": "application/json",
}),
body: JSON.stringify(data),
};
fetch(url,fetchConfig)
.then((response) => {
return response.json();
})
const action = {
type:"setEmail",
payload:email
};
dispatch(action)
navigate("/SignUpStep2")
}else{
alert("please enter email address");
}
}