From 8ab0282db92103c8eab8b6df8a493c34833d3c8f Mon Sep 17 00:00:00 2001 From: Johan Berggren Date: Thu, 3 Dec 2015 16:10:05 +0100 Subject: [PATCH] Update password if user exists --- tsctl | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tsctl b/tsctl index 26d2a6e9cf..a797380b90 100644 --- a/tsctl +++ b/tsctl @@ -78,16 +78,11 @@ class AddUser(Command): password = self.get_password_from_prompt() password = unicode(password.decode(encoding=u'utf-8')) username = unicode(username.decode(encoding=u'utf-8')) - user = User(username=username, name=username) + user = User.get_or_create(username=username) user.set_password(plaintext=password) - try: - db_session.add(user) - db_session.commit() - sys.stdout.write(u'User {0:s} created\n'.format(username)) - except IntegrityError: - sys.stderr.write( - u'The username ({0:s}) is already taken, ' - u'try another one.\n'.format(username)) + db_session.add(user) + db_session.commit() + sys.stdout.write(u'User {0:s} created/updated\n'.format(username)) class AddSearchIndex(Command):