Added Password change on cli

This commit is contained in:
Ozzie Isaacs 2021-01-17 09:17:46 +01:00
parent 4bc3c8d9ac
commit e09f2c9beb
2 changed files with 21 additions and 2 deletions

View File

@ -110,7 +110,10 @@ if ipadress:
sys.exit(1) sys.exit(1)
# handle and check user password argument # handle and check user password argument
user_password = args.s or None user_credentials = args.s or None
if user_credentials and ":" not in user_credentials:
print("No valid username:password format")
sys.exit(3)
# Handles enableing of filepicker # Handles enableing of filepicker
filepicker = args.f or None filepicker = args.f or None

View File

@ -43,10 +43,11 @@ from sqlalchemy import Column, ForeignKey
from sqlalchemy import String, Integer, SmallInteger, Boolean, DateTime, Float, JSON from sqlalchemy import String, Integer, SmallInteger, Boolean, DateTime, Float, JSON
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.orm.attributes import flag_modified
from sqlalchemy.sql.expression import func
from sqlalchemy.orm import backref, relationship, sessionmaker, Session, scoped_session from sqlalchemy.orm import backref, relationship, sessionmaker, Session, scoped_session
from werkzeug.security import generate_password_hash from werkzeug.security import generate_password_hash
from . import constants, logger from . import constants, logger, cli
log = logger.create() log = logger.create()
@ -680,6 +681,21 @@ def init_db(app_db_path):
create_admin_user(session) create_admin_user(session)
create_anonymous_user(session) create_anonymous_user(session)
if cli.user_credentials:
username, password = cli.user_credentials.split(':')
user = session.query(User).filter(func.lower(User.nickname) == username.lower()).first()
if user:
user.password = generate_password_hash(password)
if session_commit() == "":
print("Password for user '{}' changed".format(username))
sys.exit(0)
else:
print("Failed changing password")
sys.exit(3)
else:
print("Username '{}' not valid, can't change password".format(username))
sys.exit(3)
def dispose(): def dispose():
global session global session