コード例 #1
0
ファイル: forms.py プロジェクト: Nomanod/django-orchestra
 def render(self, name, value, attrs):
     original = ReadOnlyPasswordHashField.widget().render(name, value, attrs)
     if 'Invalid' not in original:
         return original
     encoded = value
     if not encoded:
         summary = mark_safe("<strong>%s</strong>" % _("No password set."))
     else:
         size = len(value)
         summary = value[:int(size/2)] + '*'*int(size-size/2)
         summary = "<strong>hash</strong>: %s" % summary
         if value.startswith('*'):
             summary = "<strong>algorithm</strong>: sha1_bin_hex %s" % summary
     return format_html("<div>%s</div>" % summary)
コード例 #2
0
class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = (
            "email",
            "password",
            "firstname",
            "lastname",
            "profile_photo",
            "description",
            "website",
            "following",
            "is_superuser",
        )

    def clean_password(self):
        return self.initial["password"]
コード例 #3
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', 'password', 'is_active', 'is_staff')

    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"]
コード例 #4
0
class UserAdminChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = (
            'email',
            'password',
            'first_name',
            'last_name',
            '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"]
コード例 #5
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 = get_user_model()
        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):
        return self.initial['password']
コード例 #6
0
class UserChangeForm(BaseUserChangeForm):
    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=\"{}\">this form</a>."
        ),
    )

    class Meta:
        model = User
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def clean_password(self):
        return self.initial['password']
コード例 #7
0
class UserChangeForm(forms.ModelForm):
    #只读的哈希字段
    password = ReadOnlyPasswordHashField(label=_('密码'))

    class Meta:
        model = get_user_model()
        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):
        try:
            return self.initial['password']
        except KeyError:
            pass
コード例 #8
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"),
        help_text=('<a href="../password/">Change Password</a>.'))

    class Meta:
        model = CustomUser
        fields = ('email', 'password', 'first_name', 'last_name', 'is_active',
                  'is_staff')

    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"]
コード例 #9
0
class PersonForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields["password"].help_text = (
            "Raw passwords are not stored, so there is no way to see "
            "this user's 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"]

    class Meta:
        model = Person
        fields = "__all__"
コード例 #10
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
        if DJANGO_VERSION >= (1, 6):
            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"]
コード例 #11
0
class AuPairUserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = AuPairUser
        fields = (
            'username',
            'email',
            'password',
            'first_name',
            'last_name',
            'agency',
            'active',
            'admin',
            'staff',
        )

    def clean_password(self):
        return self.initial['password']
コード例 #12
0
class FUtilisateurUpdate(forms.ModelForm):

    # Import
    from django.contrib.auth.forms import ReadOnlyPasswordHashField

    # Champ
    password = ReadOnlyPasswordHashField(help_text='''
        Les mots de passe ne sont pas enregistrés en clair, ce qui ne permet pas d'afficher le mot de passe de cet
        utilisateur, mais il est possible de le changer en utilisant <a href="../password/">ce formulaire</a>.
        ''',
                                         label='Mot de passe')

    class Meta:
        fields = [
            'email', 'first_name', 'is_active', 'is_staff', 'is_superuser',
            'last_name', 'username'
        ]
        labels = {'email': 'Courriel principal', 'last_name': 'Nom de famille'}
        model = TUtilisateur

    def __init__(self, *args, **kwargs):
        super(FUtilisateurUpdate, self).__init__(*args, **kwargs)

        # Passage de certains champs à l'état requis
        self.fields['email'].required = True
        self.fields['first_name'].required = True
        self.fields['last_name'].required = True

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

    def save(self, *args, **kwargs):

        # Modification d'une instance TUtilisateur
        obj = super(FUtilisateurUpdate, self).save(*args, **kwargs).save()

        # Liaison obligatoire avec la table t_roles_utilisateur
        if 'A' not in obj.get_type_util__list():
            TRolesUtilisateur.objects.create(
                code_type_util=TTypeUtilisateur.objects.get(pk='A'),
                id_util=obj)

        return obj
コード例 #13
0
class MedicoChangeForm(UserChangeForm):
    crm = forms.CharField(
        min_length=5, widget=forms.TextInput(attrs={'readonly': 'readonly'}))
    email = forms.CharField(min_length=6)
    first_name = forms.CharField(min_length=6)
    last_name = forms.CharField(min_length=6)
    password = forms.CharField()
    date_joined = forms.DateTimeField()
    #occupation = forms.ChoiceField()
    avatar = forms.ImageField(required=False, widget=forms.FileInput())

    password = ReadOnlyPasswordHashField()

    class Meta:
        model = Medico
        fields = [
            'crm', 'email', 'first_name', 'last_name', 'date_joined',
            'occupation', 'avatar'
        ]
コード例 #14
0
ファイル: admin.py プロジェクト: mj-huang/pdf-app-site
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', 'first_name', 'last_name', 'citizenship', 'address',
                  'city', 'province', 'postal', 'country', '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"]
コード例 #15
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",
        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 = UserProfile
        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"]
コード例 #16
0
ファイル: forms.py プロジェクト: nurmakhanow/django-docker
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()
    password1 = forms.CharField(label='Password',
                                widget=forms.PasswordInput,
                                required=False)
    password2 = forms.CharField(label='Password confirmation',
                                widget=forms.PasswordInput,
                                required=False)

    class Meta:
        model = User
        fields = ('email', 'password', 'first_name', 'last_name',
                  'date_joined', 'is_superuser', 'is_admin', '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"]

    def clean_password2(self):
        # Check that the two password entries match
        password1 = self.cleaned_data.get("password1")
        password2 = self.cleaned_data.get("password2")
        if not password1 and not password2:
            return None
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match")
        return password2

    def save(self, commit=True):
        # Save the provided password in hashed format
        user = super().save(commit=False)
        if self.cleaned_data['password2']:
            user.set_password(self.cleaned_data["password1"])
            if commit:
                user.save()
        return user
コード例 #17
0
class UserChangeForm(forms.ModelForm):
    username = forms.RegexField(
        label=_("Username"),
        max_length=75,
        regex=r"^[\w.@+-]+$",
        help_text=
        _("Required. 75 characters or fewer.  Letters, digits and @/./+/-/_ only"
          ),
        error_message=_(
            "This value must contain only letters, digits and @/./+/-/_."))
    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>."))
    noc_user_permissions = forms.CharField(label="User Access",
                                           widget=AccessWidget,
                                           required=False)

    class Meta:
        model = User

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        if "instance" in kwargs:
            self.initial[
                "noc_user_permissions"] = "user:"******"username"]
        self.new_perms = set()
        if args:
            self.new_perms = set(
                [p[5:] for p in args[0] if p.startswith("perm_")])

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

    def save(self, commit=True):
        model = super(UserChangeForm, self).save(commit)
        model.is_staff = True
        #if not model.id:
        model.save()
        Permission.set_user_permissions(model, self.new_perms)
        return model
コード例 #18
0
class BoxmeUserChangeForm(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.

    """

    # In Django 1.9 the url for changing the password was changed (#15779)
    # A url name was also added in 1.9 (same issue #15779),
    # so reversing the url is not possible for Django < 1.9
    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=\"%(url)s\">this form</a>.") %
        {'url': 'password/' if django.VERSION < (1, 9) else '../password/'})

    class Meta:  # noqa: D101
        model = get_user_model()
        exclude = ()

    def __init__(self, *args, **kwargs):
        """Init the form."""
        super(BoxmeUserChangeForm, 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"]
コード例 #19
0
class UserChangeForm(CleanNamesForm):
    '''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=_('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 = MyUser
        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']
コード例 #20
0
ファイル: forms.py プロジェクト: askmhx/django-blog
class PostUserChangeForm(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 = PostUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(PostUserChangeForm, 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"]
コード例 #21
0
class UserAdminChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        fields = ('password', 'username', 'first_name', 'last_name',
                  'is_active', 'is_staff', 'is_admin')

    username = forms.RegexField(
        regex=r'^[\w._-]+$',
        label='Pseudonyme',
        min_length=3,
        error_messages={
            'invalid':
            "Votre ne pseudonyme ne peut contenir que des lettres,"
            "nombres ou caractères suivants : ./_/-"
        },
        widget=TextInput(attrs={'class': 'form-control'}))

    def clean_password(self):
        return self.initial["password"]
コード例 #22
0
class UserChangeForm(forms.ModelForm):

    password = ReadOnlyPasswordHashField(
        label=_('Password'),
        help_text=_(u'密码经过加密,因此不可见 ,'
                    u'但是使用 <a href=\"/accounts/password_change/\">这个</a>'
                    u'链接可以修改密码.'))

    class Meta:
        model = get_user_model()
        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):
        return self.initial['password']
コード例 #23
0
class UserChangeForm(forms.ModelForm):
    # 사용자 변경 폼
    email = forms.EmailField(
        label=_('이메일'),
        disabled=True,
    )

    password = ReadOnlyPasswordHashField(label=_('비밀번호'))

    profile_img = forms.ImageField(label=_('프로필 이미지'))

    class Meta:
        model = User
        fields = ('email', 'password', 'profile_img', '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"]
コード例 #24
0
class UserAdminChangeForm(forms.ModelForm):

    password = ReadOnlyPasswordHashField()

    class Meta:

        model = Users
        fields = [
            'email',
            'password',
            'first_name',
            'last_name',
            'cedula',
            'licencia',
            'active',
            'admin'
        ]

    def clean_password(self):
        return self.initial['password']
コード例 #25
0
ファイル: admin.py プロジェクト: roldy/SharedRecords
class PersonnelChangeForm(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 = Personnel
        fields = ('email', 'first_name', 'last_name', 'sex', 'date_of_birth',
                  'address', 'qualification', 'is_doctor', '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"]
コード例 #26
0
ファイル: forms.py プロジェクト: NLPDev/Sport-Django
class UserChangeForm(UserFormMixin, 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>."))
    last_name = forms.CharField(label='Last name', required=False)

    class Meta:
        model = BaseCustomUser
        exclude = ('id',)

    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"]
コード例 #27
0
ファイル: forms.py プロジェクト: yananda93/registration
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"),
        help_text=(
            "Passwords are not stored in plaintext, so there is no way to see "
            "this user's password"))

    class Meta:
        model = User
        exclude = []

    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"]
コード例 #28
0
class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField(
        label=("Senha"),
        help_text=(
            "Esta é a senha criptografada do usuário, mas você pode alterar "
            'acessando <a href="../password/">este formulário</a>.'
        ),
    )

    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)

        self.fields["groups"].required = True

    class Meta:
        model = User
        fields = "__all__"

    def clean_password(self):
        return self.initial["password"]
コード例 #29
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 = (
            'email',
            'password',
            'contact_number',
            'employee_id',
            'name',
        )

    def clean_password(self):

        return self.initial["password"]
コード例 #30
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
        widgets = {
            'groups': FilteredSelectMultiple('groups', 1),
        }
        fields = ('name', 'mobile', 'district', 'password', 'available_date',
                  'score', 'avatar', '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"]
コード例 #31
0
class MemberChangeForm(forms.ModelForm):
    """
    A form for updating member info. Includes all the fields
    on the member, but replaces the password field with
    admin"s password hash display field.
    """
    class Meta:
        model = Member

    password = ReadOnlyPasswordHashField(
        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>."))

    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"]
コード例 #32
0
 def test_readonly_field_has_changed(self):
     field = ReadOnlyPasswordHashField()
     self.assertFalse(field.has_changed('aaa', 'bbb'))
コード例 #33
0
ファイル: forms.py プロジェクト: HiddenData/django
 def test_readonly_field_has_changed(self):
     field = ReadOnlyPasswordHashField()
     self.assertFalse(field._has_changed("aaa", "bbb"))