superset icon indicating copy to clipboard operation
superset copied to clipboard

Add Admin Reset Password Capability

Open csc5k opened this issue 8 years ago • 7 comments

Administrators should be able to reset users' passwords

csc5k avatar Mar 02 '18 11:03 csc5k

You should be able to do that from the fabmanager cli.

xrmx avatar Mar 02 '18 11:03 xrmx

OK - administrators should be able to reset users' passwords in Superset's UI

csc5k avatar Mar 02 '18 11:03 csc5k

Shouldn't users be able to reset that on their own?

xrmx avatar Mar 02 '18 11:03 xrmx

If a user forgets their password, an admin should be able to reset it via the UI

csc5k avatar Mar 02 '18 11:03 csc5k

Would be great to be able to change user's passwords via the UI. Admins can create users with new passwords via the UI and it would make sense to allow creating a new password as well.

evgenyfadeev avatar Mar 09 '18 20:03 evgenyfadeev

The best place for these features would be in Flask App Builder itself, we regularly update our dependencies to use the latest FAB.

mistercrunch avatar Mar 12 '18 05:03 mistercrunch

currently available in the menu below. "Security > List Users > Show record > Reset Password"

OR customizing if you want to edit on page "Edit record"

  • views.py

      from werkzeug.datastructures import ImmutableMultiDict
      from werkzeug.security import generate_password_hash
      from flask_appbuilder.security.views import UserDBModelView
      from flask_appbuilder.fieldwidgets import BS3PasswordFieldWidget
      from wtforms.validators import EqualTo
      from wtforms import PasswordField
      from flask_babel import lazy_gettext
    
    
      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)
    
  • security.py

      from superset.security import SupersetSecurityManager
      from .views import MyUserDBModelView
    
      class MySecurityManager(SupersetSecurityManager):
          userdbmodelview = MyUserDBModelView
    
  • config.py

      CUSTOM_SECURITY_MANAGER = MySecurityManager
    

yamoe avatar Jul 02 '18 11:07 yamoe