How I implemented login and registration forms using Django

Main
Goals
Solution
Result

This is why you should read a documentation

I was needed authentication system on my website. Do not ask me why, I just need it. I knew basic principals of session-based authentication system and user authorizations. And I decided, to myself that it will be easy to make that system on my website.

Honestly speaking, I did it.

But the thing is that Django already has everything I need for solving my problems. I just needed to know about this features. But I did not. At the end I did invent a wheel again, but it is squared one.

Goals

Considering the fact that, only small part would to sign up, I would to make as simple as possible authentication system. This is why it does not have neither captcha nor email validation.

Also I did not know, the possible way to recieve an image from user and apply it on server side of the website. Back then, all I send and recieve was either strings or numbers. Long story short, I would love to figure it out.

Solution

My authentication system build upon a usual Django models. I named that model User (So obvious) and added some fields to that model, there are:

  • user name
  • email
  • password
  • avatar
  • about user

Because of my decision to make model for authentication system by myself, I had to write down all checks and validation code by hand. And I've spend hours to thinking about all the possible ways to break my validation.

After I solved the problems with validating user registration and authorization, It's time to apply everything I did and show to user that he is registered and/or authorized.

To do this, I added a user icon at the top right (if he has added icon, of course). I also added a profile page where the user could view and get acquainted with his profile.

Result

My first goal was to make simple authorization system. Done

The second goal was to figure out how to send images to server via forms, using AJAX requests. Done

I'm very sorry for a reason that I didn't know about build-in feature for user registration and managing. At least I didn't know that this feature is working without Django admin panel.

But, I'm confident about my decision to rewrite my User Django app in a way that this will be integrated into Django's default Users model.

Additional materials


heart 0
3 connected dots 0