Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a user 'programmatically' with Flask-user extension?

I have this extension used in my project: https://pythonhosted.org/Flask-User/index.html

I also have a REST API and a register() function there which accepts JSON-object and should be able to create a new user.

How can I achieve this with Flask-user API?

UPDATE: I have a fully created User model. Basically I need some kind of User() constructor provided from Flask-user where I can pass the input from JSON-object.

Why do I need it: Flask-user extension has its own way of working. For example, it sends e-mails to confirm an account, hashes password in its own way.

like image 340
Igor Avatar asked Mar 05 '15 15:03

Igor


1 Answers

The short answer is no, there is no built-in way to perform the registration the same way that Flask-User's register view does. You'll have to do everything that view does when handling a POST request. The basics are:

  • Create and populate the models with the data you have.
  • Use user_manager.hash_password(secret) to create a hashed password, and set this on the user.
  • Call _send_registered_email(user, email, True) to send the confirmation email.
like image 91
davidism Avatar answered Oct 15 '22 14:10

davidism