Commit 82642adbec261e649e3a3512556948f4849fc6d6

Authored by hitier
1 parent 615da07f

Update routes and commands with new crypted methods

Showing 2 changed files with 8 additions and 3 deletions   Show diff stats
app/auth/routes.py
... ... @@ -52,7 +52,7 @@ def login_post():
52 52 user_password = request.form.get('password')
53 53 # user_remember = request.form.get('remember')
54 54 user = User.query.filter_by(login=user_login).one_or_none()
55   - if user and user.password == user_password:
  55 + if user and user.check_password(user_password):
56 56 login_user(user)
57 57 flash("Connection Réussie !", 'success')
58 58 return redirect(url_for('main.index'))
... ...
app/commands/commands.py
... ... @@ -199,7 +199,8 @@ def create_db():
199 199 configure the proper database uri in the db_config.py file.
200 200 """
201 201 db.create_all()
202   - admin = User(email='admin@nowhere.org', name='admin', login='admin', password='admin', role='admin')
  202 + admin = User(email='admin@nowhere.org', name='admin', login='admin', role='admin')
  203 + admin.set_password('admin')
203 204 sqlite_uri = db.engine.url.__str__() if 'sqlite' in db.engine.url.__str__() else None
204 205 try:
205 206 db.session.add(admin)
... ... @@ -221,10 +222,14 @@ def create_db():
221 222 @click.argument('password')
222 223 def user_add(email, name, login, password):
223 224 """ Add a new user in db."""
  225 + user = User.query.filter(User.name==name).one_or_none()
  226 + if( user ):
  227 + current_app.logger.error(f"user already exists {name}")
  228 + return
224 229 user = User(email=email, name=name, login=login, password=password)
225 230 db.session.add(user)
226 231 db.session.commit()
227   - current_app.logger.info("added ", name)
  232 + current_app.logger.info(f"added {name}")
228 233  
229 234  
230 235 @bp.cli.command('user_show_all')
... ...