mirror of
https://github.com/janeczku/calibre-web
synced 2024-10-31 15:20:28 +00:00
Added Password change on cli
This commit is contained in:
parent
4bc3c8d9ac
commit
e09f2c9beb
@ -110,7 +110,10 @@ if ipadress:
|
||||
sys.exit(1)
|
||||
|
||||
# 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
|
||||
filepicker = args.f or None
|
||||
|
18
cps/ub.py
18
cps/ub.py
@ -43,10 +43,11 @@ from sqlalchemy import Column, ForeignKey
|
||||
from sqlalchemy import String, Integer, SmallInteger, Boolean, DateTime, Float, JSON
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
from sqlalchemy.sql.expression import func
|
||||
from sqlalchemy.orm import backref, relationship, sessionmaker, Session, scoped_session
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
from . import constants, logger
|
||||
from . import constants, logger, cli
|
||||
|
||||
log = logger.create()
|
||||
|
||||
@ -680,6 +681,21 @@ def init_db(app_db_path):
|
||||
create_admin_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():
|
||||
global session
|
||||
|
Loading…
Reference in New Issue
Block a user