You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/07/02 11:25:30 UTC

[GitHub] yamoe commented on issue #4518: Add Admin Reset Password Capability

yamoe commented on issue #4518: Add Admin Reset Password Capability
URL: https://github.com/apache/incubator-superset/issues/4518#issuecomment-401773665
 
 
   1. currently available in the menu below.
     "Security > List Users > Show record > Reset Password"
   
   OR 
   
   1. customizing if you want to edit on page Edit record
   class MyUserDBModelView(UserDBModelView):
       __class__ = UserDBModelView
   
       edit_form_extra_fields = {
           'password': PasswordField(lazy_gettext('Password'),
               description=lazy_gettext('Please use a good password policy, this application does not check this for you'),
               #validators=[validators.DataRequired()],
               widget=BS3PasswordFieldWidget()),
           'conf_password': PasswordField(lazy_gettext('Confirm Password'),
               description=lazy_gettext(
               'Please rewrite the user\'s password to confirm'),
               validators=[EqualTo('password', message=lazy_gettext(
               'Passwords must match'))],
               widget=BS3PasswordFieldWidget())}
       edit_columns = ['first_name', 'last_name', 'username', 'active', 'email', 'roles', 'password', 'conf_password']
   
       stat = type('', (object,), { 'none': 0, 'use': 1, 'notuse': 2 })()
   
       def __init__(self, **kwargs):
           super(MyUserDBModelView, self).__init__(**kwargs)
           self.edit_form.refresh = MyUserDBModelView.wrap_refresh(self, self.edit_form.refresh)
   
       @staticmethod
       def wrap_refresh(self, wfunc):
           wfunc = wfunc.__func__
           def _w(*args, **kwargs):
               pw = None
               s = self.stat.none
   
               obj = args[1] if len(args) >= 2 else None
               if isinstance(obj, ImmutableMultiDict):
                   pw = obj.get('password', None)
                   cpw = obj.get('conf_password', None)
   
                   if pw and cpw:
                       pw = pw.strip()
                       cpw = cpw.strip()
   
                       if pw and cpw and pw == cpw:
                           s = self.stat.use
                           pw = generate_password_hash(pw)
                   else:
                       s = self.stat.notuse
   
               form = wfunc(*args, **kwargs)
   
               if s == self.stat.use:
                   form._fields.get('password').process_data(pw)
                   form._fields.get('conf_password').process_data(pw)
               elif s == self.stat.notuse:
                   form._fields.pop('password')
                   form._fields.pop('conf_password')
               return form
           return classmethod(_w)
   
   
   class MySecurityManager(SupersetSecurityManager):
       userdbmodelview = MyUserDBModelView 
   
   -- config.py
   CUSTOM_SECURITY_MANAGER = MySecurityManager
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org