def edit_user(request, user): """Edits a user.""" user = User.query.filter_by(username=user).first() if user is None: raise NotFound() form = EditUserForm(user) if request.method == 'POST' and form.validate(): form.apply_changes() request.flash(_(u'The user details where changed.')) session.commit() return form.redirect('admin.edit_users') return render_template('admin/edit_user.html', form=form.as_widget(), user=user)
def ban_user(user): """Bans a user if it was not already banned. This also sends the user an email that he was banned. """ if user.is_banned: return user.is_banned = True send_email(_(u'User account banned'), render_template('mails/user_banned.txt', user=user), user.email) session.commit()
def unban_user(user): """Unbans the user. What this actually does is sending the user an email with a link to reactivate his account. For reactivation he has to give himself a new password. """ if not user.is_banned: return if settings.REQUIRE_NEW_PASSWORD_ON_UNBAN: user.is_active = False user.is_banned = False reset_url = url_for('core.reset_password', email=user.email, key=user.password_reset_key, _external=True) send_email(_(u'Your ban was lifted'), render_template('mails/user_unbanned.txt', user=user, reset_url=reset_url), user.email) session.commit()
def test_model_signals(self): """Model signalling""" from solace.models import User, session model_changes = [] def listen(changes): model_changes.append(changes) signals.after_models_committed.connect(listen) me = User('A_USER', '*****@*****.**') self.assertEqual(model_changes, []) session.rollback() self.assertEqual(model_changes, []) me = User('A_USER', '*****@*****.**') self.assertEqual(model_changes, []) session.commit() self.assertEqual(model_changes, [[(me, 'insert')]]) del model_changes[:] session.delete(me) session.commit() self.assertEqual(model_changes, [[(me, 'delete')]])