Merge pull request #81 from fossunited/flow-fixes
fix: username and email validations
This commit is contained in:
@@ -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'],
|
||||
@@ -74,7 +77,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):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{% set color = member.get_palette() %}
|
||||
<a href="/{{member.username}}">
|
||||
<span class="avatar {{ avatar_class }}" title="{{ member.full_name }}">
|
||||
{% if member.photo %}
|
||||
<img class="avatar-frame standard-image" src="{{ member.photo }}" title="{{ member.full_name }}">
|
||||
{% if member.get_photo_url() %}
|
||||
<img class="avatar-frame standard-image" src="{{ member.get_photo_url() }}" title="{{ member.full_name }}">
|
||||
</img>
|
||||
{% else %}
|
||||
<span class="avatar-frame standard-image" title="{{ member.full_name }}"
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
<input class="form-control w-100 mr-5 mb-5 mt-2" id="invite_email" type="email" placeholder="Email Address">
|
||||
</div>
|
||||
<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>
|
||||
</form>
|
||||
@@ -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 = `<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") {
|
||||
var message = `<div>
|
||||
$("#invite-request-form").append(message);
|
||||
}
|
||||
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>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
else if (data.message == "invite") {
|
||||
var message = `<div>
|
||||
else if (data.message == "invite") {
|
||||
var message = `<div>
|
||||
<p class="lead alert alert-secondary">Email ${invite_email} has already been used to request an invitation.</p>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
else if (data.message == "user") {
|
||||
var message = `<div>
|
||||
else if (data.message == "user") {
|
||||
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>
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
$(".jumbotron").append(message);
|
||||
$(".jumbotron").append(message);
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
|
||||
{% for m in batch.get_mentors() %}
|
||||
<div>
|
||||
{% if m.photo_url %}
|
||||
<img class="profile-photo" src="{{m.photo_url}}">
|
||||
{% endif %}
|
||||
{{ widgets.Avatar(member=m, avatar_class="avatar-medium" ) }}
|
||||
<span class="instructor-title">{{m.full_name}}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
@@ -88,7 +88,8 @@
|
||||
{% if can_manage %}
|
||||
<a href="/courses/{{course.name}}/{{batch.name}}/about" class="btn btn-secondary">Manage</a>
|
||||
{% 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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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(() => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user