How to register a user and post the user data to the remote database in the server?

Hi all,

I’m new to Django, now I have built up my backend, and I can fetch my data via my database API token. Now I want to build a register and login function. Here is my idea, I get the request.POST data from my register form, then I POST the data to my backend to create a new user, if this process is not successful on my backend, I will tell the user on frontend.

But the problem is I only know I can use login() function built in django.contrib.auth package to login a user, but the data would be my local database.

Is there any built-in function for me to login a user by checking through my remote database? Or is there normal way to fulfil this function?

Thank you so much!

Kind regards,
Xi

No there isn’t.

Effectively, that’s what packages like django-allauth and django-cas-ng do - they authenticate to external sources. You might want to look at those packages to see how they work.

You could also develop your own “provider” for django-allauth and so take advantage of the project itself with your own adapter for your remote data.

Hi Ken,

Thank you so much for your reply! I will have a look at django-allauth and django-cas-ng for sure.

I’m also new to backend. Normally, what would developers do to fulfill a registration and login function with a remote backend?

My backend django project is connecting to my database now, should I just post the username and password from the frontend, and save it to the database from the backend. Or I’m supposed to connect my database from frontend as well so that I can post the username and password to my database directly. Could you please explain more? Am I doing it correctly?

Thank you!
Xi

In general, there are two separate and independent processes involved here.

Regardless of the source that you are going to use for authentication, you will want to create users in your local Django database. I know that django-cas-ng has facilities for creating the User objects for you, I’d assume that django-allauth can do the same.

However, I would question your assumptions here. Why do you think there is any benefit or advantage to storing these credentials externally to your system?

By credentials, do you mean my SSH key to my server or the username and password?

Sorry, to be honest, I don’t know… At first, I thought this might be save, because I feel the database is important, it’s better to “hide” it.

So, do you mean I should connect to my database as well from my frontend using my ssh key? Then there is no need to use API with token, is that right?

Sorry and thank you Ken, I feel there is still a lot for me to learn.

No, the point is that the browser never makes a direct connection to the database. Everything goes through the code running on the server.

thank you so much Ken, let me think…