From b3c67a3f3453cb71b032e3ca6e5fa0a43507313c Mon Sep 17 00:00:00 2001 From: pateljannat Date: Fri, 7 May 2021 13:47:33 +0530 Subject: [PATCH 1/3] fix: username and email validations --- .../community_member/community_member.py | 2 +- .../doctype/invite_request/invite_request.py | 3 ++ community/lms/widgets/RequestInvite.html | 42 +++++++++++++------ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py index dd7bed8b..0a36a91b 100644 --- a/community/community/doctype/community_member/community_member.py +++ b/community/community/doctype/community_member/community_member.py @@ -74,7 +74,7 @@ def create_member_from_user(doc, method): if ( doc.username and username_exists(doc.username)) or not doc.username: username = create_username_from_email(doc.email) - elif len(doc.username) < 4: + elif len(doc.username) < 4 and doc.send_welcome_email == 1: username = adjust_username(doc.username) if username_exists(username): diff --git a/community/lms/doctype/invite_request/invite_request.py b/community/lms/doctype/invite_request/invite_request.py index c271c740..00bc18c2 100644 --- a/community/lms/doctype/invite_request/invite_request.py +++ b/community/lms/doctype/invite_request/invite_request.py @@ -47,6 +47,9 @@ class InviteRequest(Document): @frappe.whitelist(allow_guest=True) def create_invite_request(invite_email): + if not frappe.utils.validate_email_address(invite_email): + return "invalid email" + if frappe.db.exists("User", invite_email): return "user" diff --git a/community/lms/widgets/RequestInvite.html b/community/lms/widgets/RequestInvite.html index ce3d8799..053cbcbc 100644 --- a/community/lms/widgets/RequestInvite.html +++ b/community/lms/widgets/RequestInvite.html @@ -4,7 +4,8 @@
- Request Invite + Request + Invite
@@ -18,27 +19,44 @@ invite_email: invite_email }, callback: (data) => { - $("#invite-request-form").hide(); + if (data.message == "invalid email") { + $(".email-validation") && $(".email-validation").remove(); + if (invite_email) { + var message = `
+ +
`; + } + else { + var message = `
+ +
`; + } - if (data.message == "OK") { - var message = `
+ $("#invite-request-form").append(message); + } + else { + $("#invite-request-form").hide(); + + if (data.message == "OK") { + var message = `

Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.

`; - } + } - else if (data.message == "invite") { - var message = `
+ else if (data.message == "invite") { + var message = `

Email ${invite_email} has already been used to request an invitation.

`; - } + } - else if (data.message == "user") { - var message = `
+ else if (data.message == "user") { + var message = `

Looks like there is already an account with email ${invite_email}. Would you like to login?

`; - } + } - $(".jumbotron").append(message); + $(".jumbotron").append(message); + } } }) }) From 5edceb25627309609f33a75bab41fbac5131cd03 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Fri, 7 May 2021 17:14:33 +0530 Subject: [PATCH 2/3] fix: photo from user --- .../community/doctype/community_member/community_member.py | 3 +++ community/community/widgets/Avatar.html | 4 ++-- community/www/courses/about/index.html | 4 +--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py index 0a36a91b..0c1ecdb3 100644 --- a/community/community/doctype/community_member/community_member.py +++ b/community/community/doctype/community_member/community_member.py @@ -47,6 +47,9 @@ class CommunityMember(Document): 'member_type': 'Mentor' }) + def get_photo_url(self): + return frappe.db.get_value("User", self.email, ["user_image"]) + def get_palette(self): palette = [ ['--orange-avatar-bg', '--orange-avatar-color'], diff --git a/community/community/widgets/Avatar.html b/community/community/widgets/Avatar.html index e0c88cf5..fac236df 100644 --- a/community/community/widgets/Avatar.html +++ b/community/community/widgets/Avatar.html @@ -1,8 +1,8 @@ {% set color = member.get_palette() %} - {% if member.photo %} - + {% if member.get_photo_url() %} + {% else %} - {% if m.photo_url %} - - {% endif %} + {{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }} {{m.full_name}}
{% endfor %} From 911c85bfc8b2a97fcc35ced14187e458a4a9f087 Mon Sep 17 00:00:00 2001 From: pateljannat Date: Fri, 7 May 2021 18:27:18 +0530 Subject: [PATCH 3/3] fix: redirect after login --- community/www/courses/course.html | 3 ++- community/www/courses/course.js | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/community/www/courses/course.html b/community/www/courses/course.html index b0ecb270..c3fd5f8d 100644 --- a/community/www/courses/course.html +++ b/community/www/courses/course.html @@ -88,7 +88,8 @@ {% if can_manage %} Manage {% else %} - + {% endif %}
diff --git a/community/www/courses/course.js b/community/www/courses/course.js index 3ac859b8..ae77bdb0 100644 --- a/community/www/courses/course.js +++ b/community/www/courses/course.js @@ -17,7 +17,7 @@ frappe.ready(() => { $("#apply-now").click((e) => { e.preventDefault(); if (frappe.session.user == "Guest") { - window.location.href = "/login"; + window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`; return; } frappe.call({ @@ -53,7 +53,7 @@ frappe.ready(() => { $(".join-batch").click((e) => { e.preventDefault() if (frappe.session.user == "Guest") { - window.location.href = "/login"; + window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`; return; } batch = decodeURIComponent($(e.currentTarget).attr("data-batch")) @@ -70,4 +70,3 @@ frappe.ready(() => { }) }) }) -