def change_pw(ctx, rd): user = rd.username or None if user is None: raise HTTPForbidden('Anonymous users are not allowed to change passwords') try: pw = json.loads(rd.request_body_file.read()) oldpw, newpw = pw['oldpw'], pw['newpw'] except Exception: raise HTTPBadRequest('No decodable password found') if oldpw != ctx.user_manager.get(user): raise HTTPBadRequest(_('Existing password is incorrect')) err = validate_password(newpw) if err: raise HTTPBadRequest(err) try: ctx.user_manager.change_password(user, newpw) except Exception as err: raise HTTPBadRequest(as_unicode(err)) ctx.log.warn('Changed password for user', user) return 'password for {} changed'.format(user)
def accept(self): if not self.uw.isReadOnly(): un = self.username if not un: return error_dialog( self, _('Empty username'), _('You must enter a username'), show=True ) if un in self.user_data: return error_dialog( self, _('Username already exists'), _( 'A user with the username {} already exists. Please choose a different username.' ).format(un), show=True ) err = validate_username(un) if err: return error_dialog(self, _('Username is not valid'), err, show=True) p1, p2 = self.password, self.p2.text() if p1 != p2: return error_dialog( self, _('Password do not match'), _('The two passwords you entered do not match!'), show=True ) if not p1: return error_dialog( self, _('Empty password'), _('You must enter a password for this user'), show=True ) err = validate_password(p1) if err: return error_dialog(self, _('Invalid password'), err, show=True) return QDialog.accept(self)
def change_pw(ctx, rd): user = rd.username or None if user is None: raise HTTPForbidden( 'Anonymous users are not allowed to change passwords') try: pw = json.loads(rd.request_body_file.read()) oldpw, newpw = pw['oldpw'], pw['newpw'] except Exception: raise HTTPBadRequest('No decodable password found') if oldpw != ctx.user_manager.get(user): raise HTTPBadRequest(_('Existing password is incorrect')) err = validate_password(newpw) if err: raise HTTPBadRequest(err) try: ctx.user_manager.change_password(user, newpw) except Exception as err: raise HTTPBadRequest(as_unicode(err)) ctx.log.warn('Changed password for user', user) return 'password for {} changed'.format(user)