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

fix: Auth failing #12637

Merged
merged 2 commits into from Mar 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions frappe/core/doctype/user/user.py
Expand Up @@ -536,9 +536,15 @@ def find_by_credentials(cls, user_name: str, password: str, validate_password: b
"""Find the user by credentials.
"""
login_with_mobile = cint(frappe.db.get_value("System Settings", "System Settings", "allow_login_using_mobile_number"))
filter = {"mobile_no": user_name} if login_with_mobile else {"name": user_name}

user = frappe.db.get_value("User", filters=filter, fieldname=['name', 'enabled'], as_dict=True) or {}
user = None
if login_with_mobile:
filter = {"mobile_no": user_name}
user = frappe.db.get_value("User", filters=filter, fieldname=['name', 'enabled'], as_dict=True)
if not user:
filter = {"name": user_name}
user = frappe.db.get_value("User", filters=filter, fieldname=['name', 'enabled'], as_dict=True)

if not user:
return

Expand Down
17 changes: 17 additions & 0 deletions frappe/tests/test_auth.py
Expand Up @@ -4,7 +4,24 @@

import time
import unittest

import frappe
from frappe.auth import LoginAttemptTracker
from frappe.frappeclient import FrappeClient


class TestAuth(unittest.TestCase):
def test_admin_login(self):
# Make sure that authentication works when allow_login_using_mobile_number is set to 0
frappe.db.set_value("System Settings", "System Settings", "allow_login_using_mobile_number", 0)
frappe.db.commit()
FrappeClient(frappe.get_site_config().host_name, "Administrator", "admin", verify=False)

# Make sure that authentication works when allow_login_using_mobile_number is set to 1
frappe.db.set_value("System Settings", "System Settings", "allow_login_using_mobile_number", 1)
frappe.db.commit()
FrappeClient(frappe.get_site_config().host_name, "Administrator", "admin", verify=False)


class TestLoginAttemptTracker(unittest.TestCase):
def test_account_lock(self):
Expand Down