# -*- coding: utf-8 -*-
#
# ITerativ GmbH
# http://www.iterativ.ch/
#
# Copyright (c) 2019 ITerativ GmbH. All rights reserved.
#
# Created on 2019-04-08
# @author: chrigu <christian.cueni@iterativ.ch>
from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.management import BaseCommand

from books.models import Module


class Command(BaseCommand):

    def add_arguments(self, parser):
        # Positional arguments
        parser.add_argument('username', nargs='+', type=str)

    def handle(self, *args, **options):
        self.stdout.write("Reset Testuser Password")

        email = "{}@skillbox.example".format(options['username'][0])

        try:
            user = get_user_model().objects.get(email=email)
            user.set_password('test')
            user.save()
            self.stdout.write("Password reset successful")
        except get_user_model().DoesNotExist:
            self.stdout.write("No user found!")
