Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
User Registration | Authentication with JWT
Professional Web API with Flask
course content

Зміст курсу

Professional Web API with Flask

Professional Web API with Flask

1. Introduction to the Course
2. Database and Models
3. Flask-Smorest and Schemas
4. Endpoints with Blueprints and MethodView
5. Authentication with JWT
6. Deployment

bookUser Registration

We have already defined a model and schema for the User. Additionally, we have several endpoints for reading user information.

Adding a User Registration Endpoint

In the resources/user.py file, we will add a new class UserRegister with a post method to allow users to register on our site. We specify the endpoint URL using the blueprint route decorator. For the post method, we use the blueprint arguments decorator that links the method to the UserSchema.

Username Existence Check

We write a condition to check for the existence of the same username in the database. If such a username already exists, we return an error. If the check passes and the username is unique, we create a new user with the data received in the user data dictionary.

Using Passlib for Password Hashing

We use the additional library passlib.hash from which we import pbkdf2_sha256 to ensure that plain passwords are not stored in the database. This way, even if our database is compromised, the attackers cannot easily read the passwords because they are encrypted when written to the database and cannot be decrypted back into a readable password.

We add the new user to the database and save the changes.

We also need to add a password field to our schemas, which will be mandatory and only for loading, not available for reading.

In the next chapters, we will write our next endpoints for login and logout.

1. What does the blueprint route decorator `@blp.route` specify in Flask?
2. What happens if a user tries to register with a username that already exists in the database?
3. If a registration attempt is made with a duplicate username, what HTTP status code should the error response ideally have?
What does the blueprint route decorator `@blp.route` specify in Flask?

What does the blueprint route decorator @blp.route specify in Flask?

Виберіть правильну відповідь

What happens if a user tries to register with a username that already exists in the database?

What happens if a user tries to register with a username that already exists in the database?

Виберіть правильну відповідь

If a registration attempt is made with a duplicate username, what HTTP status code should the error response ideally have?

If a registration attempt is made with a duplicate username, what HTTP status code should the error response ideally have?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 5. Розділ 3
We're sorry to hear that something went wrong. What happened?
some-alt