Merge pull request #81 from fossunited/flow-fixes

fix: username and email validations
This commit is contained in:
Anand Chitipothu
2021-05-07 18:53:58 +05:30
committed by GitHub
7 changed files with 44 additions and 22 deletions

View File

@@ -47,6 +47,9 @@ class CommunityMember(Document):
'member_type': 'Mentor' 'member_type': 'Mentor'
}) })
def get_photo_url(self):
return frappe.db.get_value("User", self.email, ["user_image"])
def get_palette(self): def get_palette(self):
palette = [ palette = [
['--orange-avatar-bg', '--orange-avatar-color'], ['--orange-avatar-bg', '--orange-avatar-color'],
@@ -74,7 +77,7 @@ def create_member_from_user(doc, method):
if ( doc.username and username_exists(doc.username)) or not doc.username: if ( doc.username and username_exists(doc.username)) or not doc.username:
username = create_username_from_email(doc.email) 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) username = adjust_username(doc.username)
if username_exists(username): if username_exists(username):

View File

@@ -1,8 +1,8 @@
{% set color = member.get_palette() %} {% set color = member.get_palette() %}
<a href="/{{member.username}}"> <a href="/{{member.username}}">
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}"> <span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
{% if member.photo %} {% if member.get_photo_url() %}
<img class="avatar-frame standard-image" src="{{ member.photo }}" title="{{ member.full_name }}"> <img class="avatar-frame standard-image" src="{{ member.get_photo_url() }}" title="{{ member.full_name }}">
</img> </img>
{% else %} {% else %}
<span class="avatar-frame standard-image" title="{{ member.full_name }}" <span class="avatar-frame standard-image" title="{{ member.full_name }}"

View File

@@ -47,6 +47,9 @@ class InviteRequest(Document):
@frappe.whitelist(allow_guest=True) @frappe.whitelist(allow_guest=True)
def create_invite_request(invite_email): 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): if frappe.db.exists("User", invite_email):
return "user" return "user"

View File

@@ -4,7 +4,8 @@
<input class="form-control w-100 mr-5 mb-5 mt-2" id="invite_email" type="email" placeholder="Email Address"> <input class="form-control w-100 mr-5 mb-5 mt-2" id="invite_email" type="email" placeholder="Email Address">
</div> </div>
<div class="col-md"> <div class="col-md">
<a type="submit" id="submit-invite-request" class="btn btn-primary btn-lg" href="#" role="button">Request Invite</a> <a type="submit" id="submit-invite-request" class="btn btn-primary btn-lg" role="button">Request
Invite</a>
</div> </div>
</div> </div>
</form> </form>
@@ -18,27 +19,44 @@
invite_email: invite_email invite_email: invite_email
}, },
callback: (data) => { callback: (data) => {
$("#invite-request-form").hide(); if (data.message == "invalid email") {
$(".email-validation") && $(".email-validation").remove();
if (invite_email) {
var message = `<div>
<small class="email-validation" style="color: red;">${invite_email} is not a valid email address.</small>
</div>`;
}
else {
var message = `<div>
<small class="email-validation" style="color: red;">Please enter an email address.</small>
</div>`;
}
if (data.message == "OK") { $("#invite-request-form").append(message);
var message = `<div> }
else {
$("#invite-request-form").hide();
if (data.message == "OK") {
var message = `<div>
<p class="lead alert alert-secondary">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p> <p class="lead alert alert-secondary">Thanks for your interest in Mon School. We have recorded your interest and we will get back to you shortly.</p>
</div>`; </div>`;
} }
else if (data.message == "invite") { else if (data.message == "invite") {
var message = `<div> var message = `<div>
<p class="lead alert alert-secondary">Email ${invite_email} has already been used to request an invitation.</p> <p class="lead alert alert-secondary">Email ${invite_email} has already been used to request an invitation.</p>
</div>`; </div>`;
} }
else if (data.message == "user") { else if (data.message == "user") {
var message = `<div> var message = `<div>
<p class="lead alert alert-secondary">Looks like there is already an account with email ${invite_email}. Would you like to <a href="/login">login</a>?</p> <p class="lead alert alert-secondary">Looks like there is already an account with email ${invite_email}. Would you like to <a href="/login">login</a>?</p>
</div>`; </div>`;
} }
$(".jumbotron").append(message); $(".jumbotron").append(message);
}
} }
}) })
}) })

View File

@@ -46,9 +46,7 @@
{% for m in batch.get_mentors() %} {% for m in batch.get_mentors() %}
<div> <div>
{% if m.photo_url %} {{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
<img class="profile-photo" src="{{m.photo_url}}">
{% endif %}
<span class="instructor-title">{{m.full_name}}</span> <span class="instructor-title">{{m.full_name}}</span>
</div> </div>
{% endfor %} {% endfor %}

View File

@@ -88,7 +88,8 @@
{% if can_manage %} {% if can_manage %}
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a> <a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
{% else %} {% else %}
<button class="join-batch" data-batch="{{ batch.name | urlencode }}">Join this Batch</button> <button class="join-batch" data-batch="{{ batch.name | urlencode }}"
data-course="{{ course.name | urlencode }}">Join this Batch</button>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@@ -17,7 +17,7 @@ frappe.ready(() => {
$("#apply-now").click((e) => { $("#apply-now").click((e) => {
e.preventDefault(); e.preventDefault();
if (frappe.session.user == "Guest") { if (frappe.session.user == "Guest") {
window.location.href = "/login"; window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
return; return;
} }
frappe.call({ frappe.call({
@@ -53,7 +53,7 @@ frappe.ready(() => {
$(".join-batch").click((e) => { $(".join-batch").click((e) => {
e.preventDefault() e.preventDefault()
if (frappe.session.user == "Guest") { if (frappe.session.user == "Guest") {
window.location.href = "/login"; window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
return; return;
} }
batch = decodeURIComponent($(e.currentTarget).attr("data-batch")) batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
@@ -70,4 +70,3 @@ frappe.ready(() => {
}) })
}) })
}) })