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,6 +19,22 @@
invite_email: invite_email invite_email: invite_email
}, },
callback: (data) => { callback: (data) => {
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>`;
}
$("#invite-request-form").append(message);
}
else {
$("#invite-request-form").hide(); $("#invite-request-form").hide();
if (data.message == "OK") { if (data.message == "OK") {
@@ -40,6 +57,7 @@
$(".jumbotron").append(message); $(".jumbotron").append(message);
} }
}
}) })
}) })
}) })