fix: username and email validations

This commit is contained in:
pateljannat
2021-05-07 13:47:33 +05:30
parent 84b4833fed
commit b3c67a3f34
3 changed files with 34 additions and 13 deletions

View File

@@ -74,7 +74,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

@@ -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);
}
} }
}) })
}) })