Skip to content

Commit

Permalink
Added initial check for valid email on password reset (publiclab#2315)
Browse files Browse the repository at this point in the history
* Added initial check through jquery

* Made the code more object oriented

* Modified the code according to ES6 rules
  • Loading branch information
Souravirus authored and jywarren committed Feb 20, 2018
1 parent 216625c commit 0159929
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
17 changes: 17 additions & 0 deletions app/assets/javascripts/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ var Profile = {
});
}
}

class Reset {
validateEmail(sEmail){
const filter = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return filter.test(sEmail);
}

runValidation(event){
const email = $('#validEmail').val();

if(!this.validateEmail(email)) {
$("#validPrint").attr("style", "display:block");
$("#validPrint").html("<p>Invalid email address</p>");
event.preventDefault();
}
}
}
14 changes: 11 additions & 3 deletions app/views/users/reset.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@
</form>

<% else %>

<p><%= t('users.reset.enter_email_reset_password') %>:</p>

<form action="/reset/" class='form'>

<input class="form-control" name="email" placeholder="you@example.com" tabindex='2' type="text" /> <br />
<div class="alert alert-danger" id="validPrint" style="display:none"> </div>

<input class="form-control" name="email" id='validEmail' placeholder="you@example.com" tabindex='2' type="text" /> <br />

<button class="btn btn-lg btn-primary" type="submit" tabindex="3"><%= t('users.reset.reset') %></button>
<button class="btn btn-lg btn-primary" id="validBtn" type="submit" tabindex="3"><%= t('users.reset.reset') %></button>

</form>

<% end %>

</div>

<script type="text/javascript">
$("#validBtn").click(function(event) {
const reset = new Reset;
reset.runValidation(event);
});
</script>

0 comments on commit 0159929

Please sign in to comment.