예제 #1
0
파일: forms.py 프로젝트: sckrs/archivoDgtl
class UserChangeForm(forms.ModelForm):

    password = auth_forms.ReadOnlyPasswordHashField(
        label="Contraseña",  #)
        help_text="Puede cambiar la contraseña activando este checkbox"
        "&nbsp;&nbsp;&nbsp;<input id=\"one\" type=\"checkbox\" value=\"Cambiar Contraseña\" name=\"changePass\">"
    )

    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')

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

    def save(self, commit=True):
        data = self.cleaned_data
        user = super(UserChangeForm, self).save(commit=False)
        if data['changePass'] == 'change':
            passW = User.objects.make_random_password()
            sender(passW, data['email'],
                   'Su clave de acceso al Archivo Digital ha sido modificada',
                   'Su usuario ha sido creado exitosamente.')
            user.set_password(passW)
        if commit:
            user.save()
        return user
예제 #2
0
class CustomUserChangeForm(UserChangeForm):
    password = auth_forms.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>."))
    # pdb.set_trace()
    # obtains: http://es.localhost:8000/gestion/users/customuser/1/change/password/
    # want: http://es.localhost:8000/gestion/users/customuser/1/password/

    class Meta:
        model = CustomUser
        fields = ('username', 'email', 'first_name', 'last_name', 'dirrection1',\
                  'dirrection2', 'town', 'zipcode', 'state', 'country',\
                  'telephone1', 'telephone2', 'is_staff', 'is_active') 
        # 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')

    def clean_password(self):
        return self.initial["password"]
예제 #3
0
class MyUserChangeForm(forms.ModelForm):
    password = auth_forms.ReadOnlyPasswordHashField()

    class Meta:
        model = MyUser
        fields = ['email', 'password']

    def clean_password(self):
        return self.initial['password']
예제 #4
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = '__all__'

    def clean_password(self):
        return self.initial["password"]
예제 #5
0
class UserChangeForm(forms.ModelForm):
    """
    Replicate the form shown when the user model supplied by Django is not
    replaced with our own by copying most of the code
    """

    username = auth_forms.UsernameField(
        help_text="This username is optional because authentication is "
                  "generalized to work with other attributes such as email "
                  "addresses and phone numbers.",
        required=False,
    )

    password = auth_forms.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>.",
    )
    secret_answer = auth_forms.ReadOnlyPasswordHashField(
        help_text="Raw answers are not stored, so there is no way to see "
                  "this user's answer, but you can change the answer "
                  "using the shell.",
    )

    class Meta:
        """
        Meta class for UserChangeForm
        """

        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')

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

    def clean_secret_answer(self):
        return self.initial["secret_answer"]
예제 #6
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.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 it by "
            "using <a href='../password/'>this form</a>. "
            "<a onclick='return showAddAnotherPopup(this);' href='../hash/'>Show hash</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"]
예제 #7
0
class UserChangeForm(UserForm):
    password = auth_forms.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>."))

    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"] if 'password' in self.initial else None
예제 #8
0
class UserChangeForm(forms.ModelForm):
    """A form for updating user objects in the admin interface. Includes all
    fields on the user, but replaces the password field with the password hash
    display field. Use the admin interface to change passwords.
    """
    password = auth_forms.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"]
예제 #9
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.ReadOnlyPasswordHashField(
        label="Password", help_text="Raw password are not stored...")

    class Meta:
        model = MyUser
        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')

    def clean_password(self):
        return self.initial["password"]
예제 #10
0
class ClientUpdateForm(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 = auth_forms.ReadOnlyPasswordHashField()

    class Meta:
        model = Client
        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 UserChangeForm(forms.UserChangeForm):
    password = forms.ReadOnlyPasswordHashField(label=_('Password'))

    class Meta:
        model = User
        fields = ['image', 'username', 'password']
        labels = {
            'image': "프로필 이미지",
            'username': "******",
        }

    # 사용자이름 글자수 제한
    def __init__(self, *args, **kwargs):
        super(UserChangeForm, self).__init__(*args, **kwargs)
        self.fields['username'].widget.attrs['maxlength'] = 15

    def clean_password(self):
        return self.initial["password"]
예제 #12
0
class CustomUserChangeForm(forms.ModelForm):
    password = auth_forms.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 = CustomUser
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        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"]
예제 #13
0
class CustomUserChangeForm(UserChangeForm):
    password = auth_forms.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_reset/\">this form</a>.")

    class Meta(UserChangeForm.Meta):
        model = CustomUser
        fields = ('username', 'first_name', 'last_name', 'password','street', 'city', 'country', 'phone')
    
    def __init__(self, *args, **kwargs):
        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"]
예제 #14
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.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):
        return self.initial["password"]


    def clean_email(self):
        return self.cleaned_data.get('email', None) or None


    class Meta:
        model = auth_models.User
예제 #15
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.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>."))

    customfields = JSONField(label=_("Extra info"),
                             required=False,
                             widget=JsonPairUserInputs(
                                 val_attrs={'size': 35},
                                 key_attrs={'class': 'large'}))

    organizations = forms.ModelMultipleChoiceField(
        queryset=Organization.objects.all(),
        required=False,
        widget=FilteredSelectMultiple(_('institutions'), False),
        label=_("Institution"))

    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')
        if self.instance.pk:
            self.fields[
                'organizations'].initial = self.instance.organizations.all()

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

    def save(self, commit=True):
        super(UserChangeForm, self).save(commit=False)
        if commit:
            self.instance.save()
        if self.instance.pk:
            self.instance.organizations.set(self.cleaned_data['organizations'])
        return self.instance
예제 #16
0
파일: forms.py 프로젝트: mindcrimer/geolead
class UserAdminForm(forms.ModelForm):
    password = auth_forms.ReadOnlyPasswordHashField(
        label='Пароль',
        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.User
        fields = '__all__'

    def __init__(self, *args, **kwargs):
        super(UserAdminForm, self).__init__(*args, **kwargs)
        self.fields['username'].label = 'Логин'

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

    def clean_username(self):
        return str(self.cleaned_data.get('username'))
예제 #17
0
class UserChangeForm(forms.ModelForm):
    password = auth_forms.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:
        fields = ('full_name', 'email', 'phone', 'password')
        model = User

    def __init__(self, *args, **kwargs):
        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']
예제 #18
0
파일: forms.py 프로젝트: yopiti/authserver
class MNServiceUserChangeForm(forms.ModelForm):
    password = auth_forms.ReadOnlyPasswordHashField(
        label="Password",
        help_text=
        "Password plaintext is never stored. To get a new password, please create a new service user."
    )

    class Meta:
        model = MNServiceUser
        fields = forms.ALL_FIELDS

    def clean_password(self) -> str:
        # 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_username(self) -> str:
        # make sure nobody edits the hidden input field
        try:
            parsed = uuid.UUID(self.cleaned_data["username"], version=4)
        except ValueError:
            raise ValidationError("Username must be a valid UUID4.")
        return self.cleaned_data["username"]
예제 #19
0
파일: forms.py 프로젝트: sckrs/adc
class UserChangeForm(forms.ModelForm):

    password = auth_forms.ReadOnlyPasswordHashField(
        label="Contraseña",  #)
        help_text="Puede cambiar la contraseña activando este checkbox"
        "&nbsp;&nbsp;&nbsp;<input id=\"one\" type=\"checkbox\" value=\"Cambiar Contraseña\" name=\"changePass\">"
    )

    password_admin = forms.CharField(label='Password de administrador',
                                     widget=forms.PasswordInput,
                                     required=False)

    class Meta:
        model = User
        fields = '__all__'

        widgets = {
            'phone':
            forms.NumberInput(attrs={
                'minlength': 10,
                'maxlength': 15,
                'type': 'number',
            }),
            'extension':
            forms.NumberInput(attrs={
                'minlength': 3,
                'maxlength': 15,
                'type': 'number',
            }),
        }

    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_changePass(self):
        change = self.cleaned_data.get('changePass')
        pswdadmin = self.cleaned_data.get("password_admin")
        if change == 'change':
            if not check_password(pswdadmin, self.request.user.password):
                raise forms.ValidationError(
                    "El password de administrador incorrecto, intentelo nuevamente"
                )
                return pswdadmin
        return change

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

    def save(self, commit=True):
        data = self.cleaned_data
        user = super(UserChangeForm, self).save(commit=False)
        if data['changePass'] == 'change':
            passW = User.objects.make_random_password()
            sender(4, data['email'],
                   'Restablecimiento de contraseña del Archivo Digital', passW,
                   'su usuario')
            user.set_password(passW)
        if commit:
            user.save()
        return user
예제 #20
0
파일: forms.py 프로젝트: diogolor/EC
class UpdateUserFormAdmin(CreateUserFormAdmin):
    password = auth_forms.ReadOnlyPasswordHashField(
        label=("Password"),
        help_text=("Raw passwords are not stored, instead "
                   "a hash is created from them, and is "
                   "saved in the database. "))