Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify address when users change their e-mail #3504

Merged
merged 2 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion redash/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require_permission_or_owner, require_admin
from redash.handlers.base import BaseResource, require_fields, get_object_or_404, paginate, order_results as _order_results

from redash.authentication.account import invite_link_for_user, send_invite_email, send_password_reset_email
from redash.authentication.account import invite_link_for_user, send_invite_email, send_password_reset_email, send_verify_email
from redash.settings import parse_boolean


Expand Down Expand Up @@ -225,10 +225,17 @@ def post(self, user_id):
if domain.lower() in blacklist or domain.lower() == 'qq.com':
abort(400, message='Bad email address.')

email_changed = 'email' in params and params['email'] != user.email
if email_changed:
user.is_email_verified = False

try:
self.update_model(user, params)
models.db.session.commit()

if email_changed:
send_verify_email(user, self.current_org)

# The user has updated their email or password. This should invalidate all _other_ sessions,
# forcing them to log in again. Since we don't want to force _this_ session to have to go
# through login again, we call `login_user` in order to update the session with the new identity details.
Expand Down
6 changes: 6 additions & 0 deletions tests/handlers/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ def test_returns_200_for_non_admin_changing_his_own(self):
rv = self.make_request('post', "/api/users/{}".format(self.factory.user.id), data={"name": "New Name"})
self.assertEqual(rv.status_code, 200)

def test_marks_email_as_not_verified_when_changed(self):
user = self.factory.user
user.is_email_verified = True
rv = self.make_request('post', "/api/users/{}".format(user.id), data={"email": "donald@trump.biz"})
self.assertFalse(user.is_email_verified)

def test_returns_200_for_admin_changing_other_user(self):
admin = self.factory.create_admin()

Expand Down