Merge pull request #519 from pateljannat/fix-username
fix: remove space from username
This commit is contained in:
@@ -20,14 +20,6 @@ class TestCustomUser(unittest.TestCase):
|
|||||||
user = new_user("Username", "test-without-username@example.com")
|
user = new_user("Username", "test-without-username@example.com")
|
||||||
self.assertTrue(user.username)
|
self.assertTrue(user.username)
|
||||||
|
|
||||||
def test_with_illegal_characters(self):
|
|
||||||
user = new_user("Username$$", "test_with_illegal_characters@example.com")
|
|
||||||
self.assertEqual(user.username[:8], "username")
|
|
||||||
|
|
||||||
def test_with_underscore_at_end(self):
|
|
||||||
user = new_user("Username___", "test_with_underscore_at_end@example.com")
|
|
||||||
self.assertNotEqual(user.username[-1], "_")
|
|
||||||
|
|
||||||
def test_with_short_first_name(self):
|
def test_with_short_first_name(self):
|
||||||
user = new_user("USN", "test_with_short_first_name@example.com")
|
user = new_user("USN", "test_with_short_first_name@example.com")
|
||||||
self.assertGreaterEqual(len(user.username), 4)
|
self.assertGreaterEqual(len(user.username), 4)
|
||||||
@@ -37,8 +29,6 @@ class TestCustomUser(unittest.TestCase):
|
|||||||
users = [
|
users = [
|
||||||
"test_with_basic_username@example.com",
|
"test_with_basic_username@example.com",
|
||||||
"test-without-username@example.com",
|
"test-without-username@example.com",
|
||||||
"test_with_illegal_characters@example.com",
|
|
||||||
"test_with_underscore_at_end@example.com",
|
|
||||||
"test_with_short_first_name@example.com",
|
"test_with_short_first_name@example.com",
|
||||||
]
|
]
|
||||||
frappe.db.delete("User", {"name": ["in", users]})
|
frappe.db.delete("User", {"name": ["in", users]})
|
||||||
|
|||||||
@@ -9,64 +9,29 @@ from frappe.core.doctype.user.user import User
|
|||||||
from frappe.utils import cint, escape_html, random_string
|
from frappe.utils import cint, escape_html, random_string
|
||||||
from frappe.website.utils import is_signup_disabled
|
from frappe.website.utils import is_signup_disabled
|
||||||
from lms.lms.utils import validate_image
|
from lms.lms.utils import validate_image
|
||||||
|
from frappe.website.utils import cleanup_page_name
|
||||||
|
from frappe.model.naming import append_number_if_name_exists
|
||||||
from lms.widgets import Widgets
|
from lms.widgets import Widgets
|
||||||
|
|
||||||
|
|
||||||
class CustomUser(User):
|
class CustomUser(User):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super().validate()
|
super().validate()
|
||||||
self.validate_username_characters()
|
self.validate_username_duplicates()
|
||||||
self.validate_completion()
|
self.validate_completion()
|
||||||
self.user_image = validate_image(self.user_image)
|
self.user_image = validate_image(self.user_image)
|
||||||
self.cover_image = validate_image(self.cover_image)
|
self.cover_image = validate_image(self.cover_image)
|
||||||
|
|
||||||
def validate_username_characters(self):
|
def validate_username_duplicates(self):
|
||||||
if self.username and len(self.username):
|
while not self.username or self.username_exists():
|
||||||
other_conditions = (
|
self.username = append_number_if_name_exists(
|
||||||
self.username[0] == "_" or self.username[-1] == "_" or "-" in self.username
|
self.doctype, cleanup_page_name(self.full_name), fieldname="username"
|
||||||
)
|
)
|
||||||
else:
|
if " " in self.username:
|
||||||
other_conditions = ""
|
self.username = self.username.replace(" ", "")
|
||||||
|
|
||||||
regex = re.compile(r"[@!#$%^&*()<>?/\|}{~:-]")
|
if len(self.username) < 4:
|
||||||
|
self.username = self.email.replace("@", "").replace(".", "")
|
||||||
if self.is_new():
|
|
||||||
if not self.username:
|
|
||||||
self.username = self.get_username_from_first_name()
|
|
||||||
|
|
||||||
if self.username.find(" "):
|
|
||||||
self.username.replace(" ", "")
|
|
||||||
|
|
||||||
if len(self.username) < 4:
|
|
||||||
self.username = self.email.replace("@", "").replace(".", "")
|
|
||||||
|
|
||||||
if regex.search(self.username) or other_conditions:
|
|
||||||
self.username = self.remove_illegal_characters()
|
|
||||||
|
|
||||||
while self.username_exists():
|
|
||||||
self.username = self.remove_illegal_characters() + str(random.randint(0, 99))
|
|
||||||
|
|
||||||
else:
|
|
||||||
if not self.username:
|
|
||||||
frappe.throw(_("Username already exists."))
|
|
||||||
|
|
||||||
if regex.search(self.username):
|
|
||||||
frappe.throw(_("Username can only contain alphabets, numbers and underscore."))
|
|
||||||
|
|
||||||
if other_conditions:
|
|
||||||
if "-" in self.username:
|
|
||||||
frappe.throw(_("Username cannot contain a Hyphen(-)"))
|
|
||||||
else:
|
|
||||||
frappe.throw(_("First and Last character of username cannot be Underscore(_)."))
|
|
||||||
|
|
||||||
if len(self.username) < 4:
|
|
||||||
frappe.throw(_("Username cannot be less than 4 characters"))
|
|
||||||
|
|
||||||
def get_username_from_first_name(self):
|
|
||||||
return frappe.scrub(self.first_name) + str(random.randint(0, 99))
|
|
||||||
|
|
||||||
def remove_illegal_characters(self):
|
|
||||||
return re.sub(r"[^\w]+", "", self.username).strip("_")
|
|
||||||
|
|
||||||
def validate_skills(self):
|
def validate_skills(self):
|
||||||
unique_skills = []
|
unique_skills = []
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ class ProfilePage(BaseRenderer):
|
|||||||
self.renderer = None
|
self.renderer = None
|
||||||
|
|
||||||
def can_render(self):
|
def can_render(self):
|
||||||
if "." in self.path:
|
"""if "." in self.path:
|
||||||
return False
|
return False"""
|
||||||
|
|
||||||
# has prefix and path starts with prefix?
|
# has prefix and path starts with prefix?
|
||||||
prefix = get_profile_url_prefix().lstrip("/")
|
prefix = get_profile_url_prefix().lstrip("/")
|
||||||
@@ -67,8 +67,8 @@ class ProfilePage(BaseRenderer):
|
|||||||
|
|
||||||
# not a userpage?
|
# not a userpage?
|
||||||
username = self.get_username()
|
username = self.get_username()
|
||||||
if RE_INVALID_USERNAME.search(username):
|
""" if RE_INVALID_USERNAME.search(username):
|
||||||
return False
|
return False """
|
||||||
# if there is prefix then we can allow all usernames
|
# if there is prefix then we can allow all usernames
|
||||||
if prefix:
|
if prefix:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
--text-3-5xl: 24px;
|
--text-3-5xl: 24px;
|
||||||
--text-3-8xl: 34px;
|
--text-3-8xl: 34px;
|
||||||
--text-4xl: 36px;
|
--text-4xl: 36px;
|
||||||
--checkbox-gradient: linear-gradient(180deg, #3d4142 -124.51%, var(--primary) 100%);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-link .course-list-count {
|
.nav-link .course-list-count {
|
||||||
@@ -651,8 +650,12 @@ input[type=checkbox] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.avatar-xl {
|
.avatar-xl {
|
||||||
width: 112px;
|
width: 8rem;
|
||||||
height: 112px;
|
height: 8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-xl .standard-image {
|
||||||
|
border: 4px solid #ffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 500px) {
|
@media (max-width: 500px) {
|
||||||
@@ -791,9 +794,9 @@ input[type=checkbox] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-banner {
|
.profile-banner {
|
||||||
height: 248px;
|
height: 248px;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-position: center;
|
background-position: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 500px) {
|
@media (max-width: 500px) {
|
||||||
@@ -803,24 +806,24 @@ input[type=checkbox] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-info {
|
.profile-info {
|
||||||
height: 90px;
|
height: 90px;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border-radius: 0px 0px 8px 8px;
|
border-radius: 0px 0px 8px 8px;
|
||||||
font-size: var(--text-sm);
|
font-size: var(--text-sm);
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
margin-bottom: 2.5rem;
|
margin-bottom: 2.5rem;
|
||||||
padding-left: 200px;
|
padding-left: 200px;
|
||||||
padding-right: 1rem;
|
padding-right: 1rem;
|
||||||
box-shadow: var(--shadow-sm);
|
border: 1px solid var(--gray-300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 550px) {
|
@media (max-width: 550px) {
|
||||||
.profile-info {
|
.profile-info {
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
height: 150px;
|
height: 150px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-avatar {
|
.profile-avatar {
|
||||||
@@ -1524,10 +1527,6 @@ pre {
|
|||||||
margin: 0 1rem;
|
margin: 0 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-page-body {
|
|
||||||
background-color: var(--gray-50);
|
|
||||||
}
|
|
||||||
|
|
||||||
.profile-column-grid {
|
.profile-column-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
|
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
|
||||||
@@ -1802,6 +1801,8 @@ li {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.role {
|
.role {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
|
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane active" id="profile" role="tabpanel" aria-labelledby="profile">
|
<div class="tab-pane active" id="profile" role="tabpanel" aria-labelledby="profile">
|
||||||
<div class="common-card-style column-card mt-5">
|
<div class="">
|
||||||
{{ About(member) }}
|
{{ About(member) }}
|
||||||
{{ EducationDetails(member) }}
|
{{ EducationDetails(member) }}
|
||||||
{{ WorkDetails(member) }}
|
{{ WorkDetails(member) }}
|
||||||
@@ -126,7 +126,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="profile-banner" style="background-image: url({{ cover_image | urlencode }})">
|
<div class="profile-banner" style="background-image: url({{ cover_image | urlencode }})">
|
||||||
<div class="profile-avatar">
|
<div class="profile-avatar">
|
||||||
{{ widgets.Avatar(member=member, avatar_class="avatar-square") }}
|
{{ widgets.Avatar(member=member, avatar_class="avatar-xl") }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -201,9 +201,9 @@
|
|||||||
{% macro RoleSettings(member) %}
|
{% macro RoleSettings(member) %}
|
||||||
{% if has_course_moderator_role() %}
|
{% if has_course_moderator_role() %}
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="common-card-style column-card">
|
<div class="">
|
||||||
<div class="course-home-headings"> {{ _("Role Settings") }} </div>
|
<div class="course-home-headings"> {{ _("Role Settings") }} </div>
|
||||||
<div class="medium">
|
<div class="d-flex">
|
||||||
<label class="role">
|
<label class="role">
|
||||||
<input type="checkbox" id="course-creator" data-role="Course Creator"
|
<input type="checkbox" id="course-creator" data-role="Course Creator"
|
||||||
{% if has_course_instructor_role(member.name) %} checked {% endif %}>
|
{% if has_course_instructor_role(member.name) %} checked {% endif %}>
|
||||||
|
|||||||
Reference in New Issue
Block a user