fix: use vmodel for confirm password widget input
since previously this did not work at all for butterball (vue3 + oruga) - although it was never clear why per se.. Refs: #1
This commit is contained in:
		
							parent
							
								
									993f066f2c
								
							
						
					
					
						commit
						7171c7fb06
					
				
					 2 changed files with 19 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
<div i18n:domain="deform" tal:omit-tag=""
 | 
			
		||||
      tal:define="oid oid|field.oid;
 | 
			
		||||
                  name name|field.name;
 | 
			
		||||
                  vmodel vmodel|'field_model_' + name;
 | 
			
		||||
                  css_class css_class|field.widget.css_class;
 | 
			
		||||
                  style style|field.widget.style;">
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8,7 +9,7 @@
 | 
			
		|||
    ${field.start_mapping()}
 | 
			
		||||
    <b-input type="password"
 | 
			
		||||
             name="${name}"
 | 
			
		||||
             value="${field.widget.redisplay and cstruct or ''}"
 | 
			
		||||
             v-model="${vmodel}"
 | 
			
		||||
             tal:attributes="class string: form-control ${css_class or ''};
 | 
			
		||||
                             style style;
 | 
			
		||||
                             attributes|field.widget.attributes|{};"
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +19,6 @@
 | 
			
		|||
    </b-input>
 | 
			
		||||
    <b-input type="password"
 | 
			
		||||
             name="${name}-confirm"
 | 
			
		||||
             value="${field.widget.redisplay and confirm or ''}"
 | 
			
		||||
             tal:attributes="class string: form-control ${css_class or ''};
 | 
			
		||||
                             style style;
 | 
			
		||||
                             confirm_attributes|field.widget.confirm_attributes|{};"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,28 +44,6 @@ class UserLogin(colander.MappingSchema):
 | 
			
		|||
                                   widget=dfwidget.PasswordWidget())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@colander.deferred
 | 
			
		||||
def current_password_correct(node, kw):
 | 
			
		||||
    request = kw['request']
 | 
			
		||||
    app = request.rattail_config.get_app()
 | 
			
		||||
    auth = app.get_auth_handler()
 | 
			
		||||
    user = kw['user']
 | 
			
		||||
    def validate(node, value):
 | 
			
		||||
        if not auth.authenticate_user(Session(), user.username, value):
 | 
			
		||||
            raise colander.Invalid(node, "The password is incorrect")
 | 
			
		||||
    return validate
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ChangePassword(colander.MappingSchema):
 | 
			
		||||
 | 
			
		||||
    current_password = colander.SchemaNode(colander.String(),
 | 
			
		||||
                                           widget=dfwidget.PasswordWidget(),
 | 
			
		||||
                                           validator=current_password_correct)
 | 
			
		||||
 | 
			
		||||
    new_password = colander.SchemaNode(colander.String(),
 | 
			
		||||
                                       widget=dfwidget.CheckedPasswordWidget())
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AuthenticationView(View):
 | 
			
		||||
 | 
			
		||||
    def forbidden(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -181,7 +159,23 @@ class AuthenticationView(View):
 | 
			
		|||
                self.request.user))
 | 
			
		||||
            return self.redirect(self.request.get_referrer())
 | 
			
		||||
 | 
			
		||||
        schema = ChangePassword().bind(user=self.request.user, request=self.request)
 | 
			
		||||
        def check_user_password(node, value):
 | 
			
		||||
            auth = self.app.get_auth_handler()
 | 
			
		||||
            user = self.request.user
 | 
			
		||||
            if not auth.check_user_password(user, value):
 | 
			
		||||
                node.raise_invalid("The password is incorrect")
 | 
			
		||||
 | 
			
		||||
        schema = colander.Schema()
 | 
			
		||||
 | 
			
		||||
        schema.add(colander.SchemaNode(colander.String(),
 | 
			
		||||
                                       name='current_password',
 | 
			
		||||
                                       widget=dfwidget.PasswordWidget(),
 | 
			
		||||
                                       validator=check_user_password))
 | 
			
		||||
 | 
			
		||||
        schema.add(colander.SchemaNode(colander.String(),
 | 
			
		||||
                                       name='new_password',
 | 
			
		||||
                                       widget=dfwidget.CheckedPasswordWidget()))
 | 
			
		||||
 | 
			
		||||
        form = forms.Form(schema=schema, request=self.request)
 | 
			
		||||
        if form.validate():
 | 
			
		||||
            auth = self.app.get_auth_handler()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue