def user_settings_otp_delete(ipa, username): form = UserSettingsOTPStatusChange() if form.validate_on_submit(): username = session.get('noggin_username') token = form.token.data try: ipa.otptoken_del(ipatokenuniqueid=token) except python_freeipa.exceptions.BadRequest as e: if (e.message == "Server is unwilling to perform: Can't delete last active token" ): flash(_('Sorry, You cannot delete your last active token.'), 'warning') else: flash(_('Cannot delete the token.'), 'danger') app.logger.error( f'Something went wrong deleting OTP token for user {username}: {e}' ) except python_freeipa.exceptions.FreeIPAError as e: flash(_('Cannot delete the token.'), 'danger') app.logger.error( f'Something went wrong deleting OTP token for user {username}: {e}' ) for field_errors in form.errors.values(): for error in field_errors: flash(error, 'danger') return redirect(url_for('user_settings_otp', username=username))
def user_settings_otp_disable(ipa, username): form = UserSettingsOTPStatusChange() if form.validate_on_submit(): token = form.token.data try: ipa.otptoken_mod(a_ipatokenuniqueid=token, o_ipatokendisabled=True) except python_freeipa.exceptions.BadRequest as e: if (e.message == "Server is unwilling to perform: Can't disable last active token" ): flash(_('Sorry, You cannot disable your last active token.'), 'warning') else: flash('Cannot disable the token.', 'danger') current_app.logger.error( f'Something went wrong disabling an OTP token for user {username}: {e}' ) except python_freeipa.exceptions.FreeIPAError as e: flash(_('Cannot disable the token.'), 'danger') current_app.logger.error( f'Something went wrong disabling an OTP token for user {username}: {e}' ) for field_errors in form.errors.values(): for error in field_errors: flash(error, 'danger') return redirect(url_for('.user_settings_otp', username=username))
def user_settings_otp_enable(ipa, username): form = UserSettingsOTPStatusChange() if form.validate_on_submit(): token = form.token.data try: ipa.otptoken_mod(ipatokenuniqueid=token, ipatokendisabled=None) except ( python_freeipa.exceptions.BadRequest, python_freeipa.exceptions.FreeIPAError, ) as e: flash( _('Cannot enable the token. %(errormessage)s', errormessage=e), 'danger') app.logger.error( f'Something went wrong enabling an OTP token for user {username}: {e}' ) for field_errors in form.errors.values(): for error in field_errors: flash(error, 'danger') return redirect(url_for('user_settings_otp', username=username))