Skip to content

Commit

Permalink
Merge pull request #155 from google/110-reset-passwd-if-user-exists
Browse files Browse the repository at this point in the history
Update password if user exists
  • Loading branch information
berggren committed Dec 5, 2015
2 parents 9fa8dbf + 049fd53 commit 2c09766
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions tsctl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2c09766

Please sign in to comment.