Add user accounts cli
Add forgot password link at login Update AUTHORS.md
This commit is contained in:
1 parent
ee93e25ffd
commit
ea1bcf8e5d
5 files changed
+86
-4
No files matched your search
@@ -106,6 +106,7 @@ date of first contribution):
|
||||
* [Janne Mäntyharju](https://github.com/JanneMantyharju)
|
||||
* [Steven Spungin](https://github.com/flamenco)
|
||||
* [Piotr Usewicz](https://github.com/pusewicz)
|
||||
* [Aliaksei Pilko](https://github.com/aliaksei135)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -137,9 +137,10 @@ from .dev import dev_commands
|
||||
from .client import client_commands
|
||||
from .config import config_commands
|
||||
from .analysis import analysis_commands
|
||||
from .user import user_commands
|
||||
|
||||
@click.group(name="octoprint", invoke_without_command=True, cls=click.CommandCollection,
|
||||
sources=[server_commands, plugin_commands, dev_commands, client_commands, config_commands, analysis_commands])
|
||||
sources=[server_commands, plugin_commands, dev_commands, client_commands, config_commands, analysis_commands, user_commands])
|
||||
@standard_options()
|
||||
@legacy_options
|
||||
@click.version_option(version=octoprint.__version__, allow_from_autoenv=False)
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
|
||||
import click
|
||||
import logging
|
||||
|
||||
from octoprint import init_settings
|
||||
from octoprint.cli import get_ctx_obj_option
|
||||
from octoprint.users import FilebasedUserManager, UnknownUser
|
||||
|
||||
#~~ "octoprint user" commands
|
||||
|
||||
|
||||
@click.group()
|
||||
def user_commands():
|
||||
pass
|
||||
|
||||
|
||||
@user_commands.group(name="user")
|
||||
@click.pass_context
|
||||
def user(ctx):
|
||||
"""User account management"""
|
||||
try:
|
||||
logging.basicConfig(level=logging.DEBUG if get_ctx_obj_option(ctx, "verbosity", 0) > 0 else logging.WARN)
|
||||
settingz = init_settings(get_ctx_obj_option(ctx, "basedir", None), get_ctx_obj_option(ctx, "configfile", None))
|
||||
ctx.obj.users = FilebasedUserManager(settingz=settingz)
|
||||
except Exception:
|
||||
click.echo("Could not instantiate user manager")
|
||||
return
|
||||
|
||||
|
||||
@user.command(name="add_user")
|
||||
@click.argument("username", type=click.STRING, required=True)
|
||||
@click.password_option("--password", "password", help="Password for user")
|
||||
@click.option("--is-admin", "is_admin", type=click.BOOL, default=False,
|
||||
help="Sets user role as admin")
|
||||
@click.pass_context
|
||||
def add_user_command(ctx, username, password, is_admin):
|
||||
"""Adds new user account"""
|
||||
ctx.obj.users.addUser(
|
||||
username,
|
||||
password,
|
||||
roles=("admin" if is_admin else "user"),
|
||||
active=True
|
||||
)
|
||||
|
||||
|
||||
@user.command(name="remove_user")
|
||||
@click.argument("username", type=click.STRING)
|
||||
@click.pass_context
|
||||
def remove_user_command(ctx, username):
|
||||
"""Removes user account"""
|
||||
confirm = click.prompt(
|
||||
"This is will irreversibly destroy the user account! Enter 'yes' to confirm",
|
||||
type=click.STRING)
|
||||
|
||||
if confirm == 'yes':
|
||||
ctx.obj.users.removeUser(username)
|
||||
else:
|
||||
click.echo("User NOT removed")
|
||||
|
||||
|
||||
@user.command(name="change_password")
|
||||
@click.argument("username", type=click.STRING)
|
||||
@click.password_option("--password", "password", help="New password for user")
|
||||
@click.pass_context
|
||||
def change_password_command(ctx, username, password):
|
||||
"""Changes an existing user password"""
|
||||
try:
|
||||
ctx.obj.users.changeUserPassword(username, password)
|
||||
except UnknownUser:
|
||||
click.echo("User does not exist!")
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
<input type="text" id="login-user" class="input-block-level" placeholder="{{ _('Username') }}" autofocus>
|
||||
<input type="password" id="login-password" class="input-block-level" placeholder="{{ _('Password') }}">
|
||||
<span class="pull-right"><small><a href="https://faq.octoprint.org/forgotten-password" id="login-forgotpassword" target="_blank" tabindex="-1">{{ _('Forgot password?') }}</a></small></span>
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" id="login-remember"> {{ _('Remember me') }}
|
||||
</label>
|
||||
|
||||
@@ -216,10 +216,12 @@ class UserManager(object):
|
||||
##~~ FilebasedUserManager, takes available users from users.yaml file
|
||||
|
||||
class FilebasedUserManager(UserManager):
|
||||
def __init__(self):
|
||||
def __init__(self, settingz=None):
|
||||
UserManager.__init__(self)
|
||||
|
||||
userfile = settings().get(["accessControl", "userfile"])
|
||||
if settingz is None:
|
||||
userfile = settings().get(["accessControl", "userfile"])
|
||||
else:
|
||||
userfile = settingz.get(["accessControl", "userfile"])
|
||||
if userfile is None:
|
||||
userfile = os.path.join(settings().getBaseFolder("base"), "users.yaml")
|
||||
self._userfile = userfile
|
||||
|
||||
Reference in new issue
Block a user