Beispiel #1
0
class UserAdminChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    # password = ReadOnlyPasswordHashField()

    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_(
            "Raw passwords are not stored, so there is no way to see this "
            "user's password, but you can change the password using "
            "<a href=\"../password/\">this form</a>."),
    )

    class Meta:
        model = User
        fields = ('full_name', 'email', 'password', 'is_active', 'admin')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #2
0
class UserChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField(
        help_text='This field contains hashed and salted value')

    #change_password = forms.CharField(label='Set new password:'******'Leave empty if no change is needed',
    #                                  widget=forms.PasswordInput)

    class Meta:
        model = User
        fields = ('username', 'email', 'password', 'is_active', 'source',
                  'first_name', 'last_name', 'full_name', 'is_staff',
                  'is_superuser', 'groups', 'user_permissions', 'date_joined',
                  'last_login')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        print(self.initial["password"])
        return self.initial["password"]

    def save(self, commit=True):
        user = super(UserChangeForm, self).save(commit=False)

        # if len(self.cleaned_data["change_password"]):
        #    user.set_password(self.cleaned_data["change_password"])

        if commit:
            user.save()

        return user
Beispiel #3
0
class KitChangeForm(forms.ModelForm):
    """
    A form for updating kits. Includes all the fields on
    the kit, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_(
            "Raw passwords are not stored, so there is no way to see this "
            "user's password, but you can change the password using "
            "<a href=\"../password/\">this form</a>."
        ),
    )

    class Meta:
        model = models.Kit
        fields = ('username', 'password', 'type', 'name', 'description', 'latitude', 'longitude')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #4
0
class UserChangeForm(forms.ModelForm):
    '''A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    '''
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = SchuleUser
        fields = ('username', 'password', 'email', 'first_name', 'last_name',
                  'userType', 'addressLine1', 'addressLine2', 'state',
                  'country', 'postalCode', 'countryCode', 'phone', 'birthDate')

    username = forms.RegexField(
        label=_("Username"),
        max_length=30,
        regex=r"^[\w.@+-]+$",
        help_text=_("Required. 30 characters or fewer. Letters, digits and "
                    "@/./+/-/_ only."),
        error_messages={
            'invalid':
            _("This value may contain only letters, numbers and "
              "@/./+/-/_ characters.")
        })

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #5
0
class UserAdminChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
	the user, but replaces the password field with admin's
	password hash display field.
	"""
    password = ReadOnlyPasswordHashField()
    email = forms.EmailField(label='إسم المستخدم', required=True)
    name = forms.CharField(label='الإسم ', required=True)
    lastname = forms.CharField(label='اللقب', required=True)

    email.widget.attrs.update({
        'class': 'form-control text-right',
        'autofocus': True,
        '': 'E-mail'
    })
    name.widget.attrs.update({
        'class': 'form-control text-right',
        'autofocus': True,
        '': 'Prénom'
    })
    lastname.widget.attrs.update({
        'class': 'form-control text-right',
        'autofocus': True,
        '': 'Nom'
    })

    class Meta:
        model = User
        fields = ('email', 'password', 'is_active', 'is_admin', 'name',
                  'lastname')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #6
0
class UserChangeForm(forms.ModelForm):
    """
    A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField(
        label=_("Password"), widget=BetterReadOnlyPasswordHashWidget)

    class Meta:
        model = User
        exclude = ()

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #7
0
class UserChangeForm(forms.ModelForm):
    '''
    Handle data received from form to edit user data
    '''
    password = ReadOnlyPasswordHashField(
        label='Password',
        help_text=("Raw passwords are not stored, so there is no way to see "
                   "this user's password, but you can change the password "
                   "using <a href=\"../password/\">this form</a>."))

    class Meta:
        '''
        Meta data for the class
        '''
        model = User
        fields = ('username', 'email', 'is_admin', 'avatar')

    def clean_password(self):
        '''
        Regardless of what the user provides, return the initial value.
        This is done here, rather than on the field, because the
        field does not have access to the initial value
        '''
        return self.initial["password"]
Beispiel #8
0
class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField(label=("Password"),
                                         help_text=("Raw passwords are not stored, so there is no way to see "
                                                    "this user's password, but you can change the password "
                                                    "using <a href=\"../password/\">this form</a>."))

    class Meta:
        model = User
        fields = ('username', 'password')

    def clean(self):
        if not (self.cleaned_data.get('is_teacher') ^ self.cleaned_data.get('is_student')):
            raise forms.ValidationError('Exactly one of is_teacher and is_student should be True.')

        return super(UserChangeForm, self).clean()

    def clean_password(self):
        return self.initial["password"]

    def save(self, commit=True, request=None):
        user = super(UserChangeForm, self).save(commit=False)
        if commit:
            user.save()
        return user
Beispiel #9
0
class UserChangeForm(forms.ModelForm):
    """
    A form for updating users, including all fields on the user,
    but replaces the password field with admin's password hash display
    field.
    """
    email = forms.EmailField(
        label='Email',
        help_text="Required.  Standard format email address.",
    )

    password = ReadOnlyPasswordHashField(
        label="Password",
        help_text="Raw passwords are not stored, so there is no way to see "
        "this user's password, but you can change the password "
        "using <a href=\"password/\">this form</a>.")

    class Meta:
        model = EmailUser
        fields = ('email', 'password', 'first_name', 'last_name', 'is_active',
                  'is_staff', 'is_superuser', 'groups', 'user_permissions',
                  'last_login', 'date_joined')

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        """
        Regardless of what the user provides, return the initial value.
        This is done here, rather than on the field, because the
        field does not have access to the inital value.
        """
        return self.initial["password"]
Beispiel #10
0
class UserChangeForm(forms.ModelForm): # pragma: no cover
    email = forms.EmailField(label=_("Email"), max_length=500)
    name = forms.CharField(label=_("Name"), max_length=500)
    password = ReadOnlyPasswordHashField(label=_("Password"),
        help_text=_("Raw passwords are not stored, so there is no way to see "
                    "this user's password, but you can change the password "
                    "using <a href=\"password/\">this form</a>."))

    class Meta:
        model = User
        fields = ('email', 'name', 'is_staff', 'is_active', 'is_superuser', 'date_joined',)


    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
class CustomUserChangeForm(UserChangeForm):



    password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
    password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)

    class Meta(UserChangeForm):
        model = CustomUser
        fields = '__all__'
    
    password = ReadOnlyPasswordHashField()



    class Meta:
        model = CustomUser
        fields = ('__all__')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #12
0
class UserChangeForm(forms.ModelForm):
    username = forms.RegexField(
        label=_("Username"), max_length=30, regex=r'^[\w]+$',
        help_text=_("Required. 30 characters or fewer. Letters and digits."),
        error_messages={
            'invalid': _("This value may contain only letters and numbers.")})
    # TODO: remove this hardcoded URL from here
    password = ReadOnlyPasswordHashField(label=_("Password"),
                                         help_text=_("Raw passwords are not"
                                                     " stored, so there is no"
                                                     " way to see "
                                                     "this user's password, "
                                                     "but you can change the "
                                                     "password "
                                                     "using <a "
                                                     "href=\"password/\">this"
                                                     " form</a>."))

    class Meta:
        model = User
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

        # Set email as required field
        self.fields['email'].required = True

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
class UserChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = ('email', 'password', 'is_active', 'is_admin')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]

    def clean_password2(self):
        # Check that the two password entries match
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match")
        return password2
Beispiel #14
0
class CustomUserChangeForm(UserChangeForm):
    password = ReadOnlyPasswordHashField(label="", help_text="")

    #     help_text="Raw passwords are not stored, so there is no way to see "
    #               "this user's password, but you can change the password "
    #               "using <a href=\"password/\">this form</a>.")

    class Meta:
        model = CustomUser
        fields = ['email', 'bio', 'location', 'birth_date']
        # fields = ['username','first_name', 'last_name', 'date_joined','email', 'bio', 'location','birth_date']
        # fields = '__all__'
        widgets = {
            'birth_date':
            forms.DateInput(format=('%m/%d/%Y'),
                            attrs={
                                'class': 'form-item',
                                'placeholder': 'Select a date',
                                'type': 'date'
                            }),
            'bio':
            forms.Textarea(
                attrs={
                    'size': 10,
                    'id': 'form-bio',
                    'class': "form-item",
                    'placeholder': 'Enter a brief description',
                }),
            'password':
            forms.HiddenInput(),
            # 'groups': forms.HiddenInput(),
            # 'is_superuser': forms.HiddenInput(),
            # 'user_permissions': forms.HiddenInput(),
            # 'is_active': forms.HiddenInput(),
            # 'is_staff': forms.HiddenInput(),
        }
Beispiel #15
0
class UpdateForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = MyUser
        fields = ('email', 'password', 'first_name', 'last_name')

    def clean_password(self):
        return self.initial["password"]

    def clean_email(self):
        email = self.cleaned_data.get("email")
        #Check is email has changed
        if email == self.initial["email"]:
            return email
        #Check if email exists before
        try:
            exists = MyUser.objects.get(email=email)
            raise forms.ValidationError("This email has already been taken")
        except MyUser.DoesNotExist:
            return email
        except:
            raise forms.ValidationError(
                "There was an error, please contact us later")

    def clean_first_name(self):
        first_name = self.cleaned_data.get("first_name")
        #Check is email has changed
        if first_name is None or first_name == "" or first_name == '':
            email = self.cleaned_data.get("email")
            return email[:email.find("@")]
        return first_name
Beispiel #16
0
class UserChangeForm(UserValidationMixin, forms.ModelForm):
    model = get_user_model()

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        if not self.user.is_superuser:
            self.fields[
                'working_groups'].queryset = WorkingGroup.objects.filter(
                    id__in=[wg.id for wg in self.user.working_groups.all()])
            self.fields['registry'].queryset = Registry.objects.filter(
                code__in=[reg.code for reg in self.user.registry.all()])

    from django.contrib.auth.forms import UserChangeForm as OldUserChangeForm
    password = ReadOnlyPasswordHashField(
        help_text=(OldUserChangeForm.base_fields['password'].help_text))

    preferred_language = ChoiceField(choices=get_supported_languages())

    class Meta:
        fields = "__all__"
        model = get_user_model()

    def clean_password(self):
        return self.initial["password"]
Beispiel #17
0
class UserChangeForm(forms.ModelForm):
    """
    A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = (
            'email',
            'name',
            'phone',
            'password',
        )

    def clean_password(self):
        """
        Regardless of what the user provides, return the initial value.
        This is done here, rather than on the field, because the
        field does not have access to the initial value
        """
        return self.initial["password"]
Beispiel #18
0
class CustomUserChangeForm(forms.ModelForm):
    username = forms.RegexField(
        label=_("Username"),
        max_length=30,
        regex=r"^[\w.@+-]+$",
        help_text=_("Required. 30 characters or fewer. Letters, digits and "
                    "@/./+/-/_ only."),
        error_messages={
            'invalid':
            _("This value may contain only letters, numbers and "
              "@/./+/-/_ characters.")
        })
    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_("Raw passwords are not stored, so there is no way to see "
                    "this user's password, but you can change the password "
                    "using <a href=\"password/\">this form</a>."))

    class Meta:
        # Point to our CustomUser here instead of default `User`

        model = CustomUser
        fields = ('full_name', 'short_name', 'email', 'sex', 'phone_number',
                  'user_type', 'address', 'username', 'password')

    def __init__(self, *args, **kwargs):
        # Make sure we pass back in our CustomUserChangeForm and not the
        # default `UserChangeForm`
        super(CustomUserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):

        return self.initial["password"]
Beispiel #19
0
class CustomUserChangeForm(forms.ModelForm):
    username = forms.RegexField(
        label=_("Username"),
        max_length=30,
        regex=r"^[a-zA-Z0-9_.@+-]+$",
        help_text=_("Required. 30 characters or fewer. Letters, digits and "
                    "@/./+/-/_ only."),
        error_messages={
            'invalid':
            _("This value may contain only letters, numbers and "
              "@/./+/-/_ characters.")
        })
    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_("Raw passwords are not stored, so there is no way to see "
                    "this user's password, but you can change the password "
                    "using <a href=\"password/\">this form</a>."))

    class Meta:
        # Point to our CustomUser here instead of default `User`
        model = CustomUser
        exclude = ()

    def __init__(self, *args, **kwargs):
        # Make sure we pass back in our CustomUserChangeForm and not the
        # default `UserChangeForm`
        super().__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #20
0
class EmailUserChangeForm(forms.ModelForm):
    email = forms.EmailField(label=_("Email"))

    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_("Raw passwords are not stored, so there is no way to see "
                    "this user's password, but you can change the password "
                    "using <a href=\"password/\">this form</a>."))

    class Meta:
        model = EmailUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(EmailUserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #21
0
class UserChangeForm(forms.ModelForm):
    """
    A form for updating users. Includes all the fields on the user, but replaces
    the password field with admin's password hash display field.
    """
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = MyUser
        fields = (
            'first_name',
            'last_name',
            'email',
            'date_of_birth',
            'password',
            'is_active',
            'is_admin',
        )

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the field
        # does not have access to the initial value.
        return self.initial['password']
Beispiel #22
0
class UserChangeForm(forms.ModelForm):
    """
    A form for changing a user
    """
    password = ReadOnlyPasswordHashField()
    timezone = forms.ChoiceField(label='Time Zone',
                                 choices=[(t, t)
                                          for t in pytz.common_timezones])

    class Meta:
        model = UserProfile
        fields = [
            'email',
            'known_as',
            'timezone',
        ]

    def clean_password(self):
        self.initial['password']

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        for field_name, field in self.fields.items():
            field.widget.attrs['class'] = 'form-control'
class EmailUserChangeForm(forms.ModelForm):

    """ A form for updating users.

    Includes all the fields on the user, but replaces the password field
    with admin's password hash display field.

    """

    password = ReadOnlyPasswordHashField(label=_("Password"), help_text=_(
        "Raw passwords are not stored, so there is no way to see "
        "this user's password, but you can change the password "
        "using <a href=\"password/\">this form</a>."))

    class Meta:
        model = get_user_model()
        exclude = ()

    def __init__(self, *args, **kwargs):
        """ Init the form."""
        super(EmailUserChangeForm, self).__init__(*args, **kwargs)
        f = self.fields.get('user_permissions', None)
        if f is not None:
            f.queryset = f.queryset.select_related('content_type')

    def clean_password(self):
        """ Clean password.

        Regardless of what the user provides, return the initial value.
        This is done here, rather than on the field, because the
        field does not have access to the initial value.

        :return str password:

        """
        return self.initial["password"]
Beispiel #24
0
class UserChangeForm(forms.ModelForm):

    password = ReadOnlyPasswordHashField(
        label=_("Password"),
        help_text=_("Raw passwords are not stored, so there is no way to see "
                    "this user's password, but you can change the password "
                    "using <a href=\"../password/\">this form</a>."))

    class Meta:
        model = CUser
        fields = (
            'email',
            'password',
            'date_joined',
            'is_active',
            'is_admin',
            'daily_reports',
        )

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #25
0
class UserChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """
    email = forms.EmailField(max_length=60)
    username = forms.CharField(max_length=30)
    first_name = forms.CharField(max_length=50)
    last_name = forms.CharField(max_length=50)
    health_id = forms.CharField(max_length=15)
    birth = forms.DateField()
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = Account
        fields = ('username', 'first_name', 'last_name', 'health_id', 'email',
                  'password', 'birth', 'is_active', 'is_admin', 'is_doctor',
                  'is_patient', 'profile_pic', 'phone')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #26
0
class UserAdminChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
    the user, but replaces the password field with admin's
    password hash display field.
    """

    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = (
            "email",
            "password",
            "active",
            "is_superuser",
            "first_name",
            "last_name",
        )

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #27
0
class UserChangeForm(forms.ModelForm):
    """A form for updating users. Includes all the fields on
	the user, but replaces the password field with admin's
	password hash display field.
	"""
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = CustomUser
        fields = ('first_name', 'work_email', 'middle_name', 'phone',
                  'last_name', 'bio', 'email_confirmed', 'phone_confirmed',
                  'dob', 'gender', 'timezone', 'two_factor_auth',
                  'client_rating', 'is_banned', 'use_work_email_incbookings',
                  'use_work_email_outbookings',
                  'show_work_email_in_contact_info',
                  'show_main_email_in_contact_info', 'additional_info',
                  'tos_version', 'is_active', 'is_admin', 'is_staff',
                  'is_superuser')

    def clean_password(self):
        # Regardless of what the user provides, return the initial value.
        # This is done here, rather than on the field, because the
        # field does not have access to the initial value
        return self.initial["password"]
Beispiel #28
0
class CustomUserChangeForm(UserChangeForm):
    password = ReadOnlyPasswordHashField(label="Password", widget=HiddenInput())

    class Meta:
        model = CustomUser
        fields = ('first_name', 'last_name', 'address', 'city', 'zip_code', 'phone_number', 'user_photo')
 def test_readonly_field_has_changed(self):
     field = ReadOnlyPasswordHashField()
     self.assertFalse(field.has_changed('aaa', 'bbb'))
Beispiel #30
0
class UserAdminChangeForm(forms.ModelForm):
    password1 = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = ('phone', 'password', 'admin', 'active')