Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #31 from TechAtNYU/brenton/add_validation
Browse files Browse the repository at this point in the history
Add Validation
  • Loading branch information
AbhiAgarwal committed Apr 6, 2016
2 parents 90c8f65 + 9a794db commit a3301d3
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 25 deletions.
59 changes: 57 additions & 2 deletions app/js/controllers/entry-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,92 @@ angular
$scope.dirty.nNumber = ""
$scope.dirty.name = ""
$scope.person = {attributes:{}};

$scope.nyuStudent = true;


//booleans for opening up new parts of the form
$scope.rsvpd = false;
$scope.needId = true;
$scope.needName = false;
$scope.needEmail = false;
$scope.allEntered = false;

$scope.nFailValidation = false;
$scope.nameFailValidation = false;
$scope.emailFailValidation = false;

$scope.validateNNumber = function(number) {
var re = /N[0-9]{8}$/;
return re.test(number);
}

$scope.validateFullName = function(name) {
var re = /[A-Z][a-z]*\s[A-Z][a-z]*/;
return re.test(name);
}

$scope.validateEmail = function(email) {
var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
return re.test(email);
}

$scope.findPersonNumber = function(number) {
$scope.nFailValidation = false;
if (number.indexOf('=') > -1) {
number = 'N' + number.substring(2, number.indexOf('='));
}
else if (number.indexOf('N') < 0) {
number = 'N' + number;
}

$scope.dirty.nNumber = number

if (!$scope.validateNNumber(number)) {
$scope.nFailValidation = true;
return;
}

personExists('people?filter[simple][nNumber]=' + number, function() {
$scope.needName = true;
});
}

$scope.notAStudent = function() {
$scope.needName = true;
$scope.notAStudent = function() {
$scope.dirty.nNumber = ""
$scope.nyuStudent = !$scope.nyuStudent;
if ($scope.nyuStudent) {
$scope.needId = true;
$scope.needName = false;
}
else {
$scope.needId = false;
$scope.needName = true;
}
}

$scope.findPersonName = function(name) {
$scope.nameFailValidation = false;
$scope.dirty.name = name;
if (!$scope.validateFullName(name)) {
$scope.nameFailValidation = true;
return;
}
personExists('people?filter[simple][name]=' + name, function() {
$scope.needEmail = true;
});
}

$scope.findPersonEmail = function(email) {
$scope.emailFailValidation = false;

if (!$scope.validateEmail(email)) {
$scope.emailFailValidation = true;
return;
}

$scope.allEntered = true;

personExists('people?filter[simple][contact.email]=' + email, function() {
$scope.person.attributes.name = $scope.dirty.name
createAccount($scope.dirty.name, $scope.dirty.email, $scope.dirty.nNumber).then(function(data) {
Expand Down
56 changes: 33 additions & 23 deletions app/partials/entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,39 @@
<div ng-if="events">
<h2>{{events.attributes.title}}</h2>
<p>{{events.attributes.description}}</p>
<form name="idNumber" ng-submit="findPersonNumber(dirty.nNumber)">
<input class="button flatButton" type="text" placeholder="Swipe your id" ng-model="dirty.nNumber" ng-disabled="person.attributes.name || needName" autofocus />
</form>
<br>
<p ng-click="notAStudent()" role="button" class="button flatButton">Not a student</a>
</div>
<div ng-if="needName">
<h2>Welcome! Can I have your name?</h2>
<div mass-autocomplete>
<form name="name" ng-submit="findPersonName(dirty.value)">
<input class="button flatButton" placeholder="Enter your name" ng-model="dirty.value" mass-autocomplete-item="autocomplete_options" ng-disabled="person.attributes.name || needEmail" />
<div ng-if="needId">
<form name="idNumber" ng-submit="findPersonNumber(dirty.nNumber)" novalidate>
<input class="button flatButton" type="text" placeholder="Swipe your id" ng-model="dirty.nNumber" ng-disabled="person.attributes.name || needName" autofocus />
<p ng-if="nFailValidation"> Something is wrong with the id number entered</p>
</form>
<br>
</div>
<p ng-click="notAStudent()" role="button" class="button flatButton">
<span ng-show="nyuStudent">Not an NYU Student?</span>
<span ng-hide="nyuStudent">NYU Student?</span>
</p>

<div ng-if="needName">
<h2>Welcome! Can I have your name?</h2>
<div mass-autocomplete>
<form name="name" ng-submit="findPersonName(dirty.value)" novalidate>
<input class="button flatButton" placeholder="Enter your name" ng-model="dirty.value" mass-autocomplete-item="autocomplete_options" ng-disabled="person.attributes.name || needEmail" />
<p ng-if="nameFailValidation"> Something is wrong with the name entered</p>
</form>
</div>
</div>
<div ng-if="needEmail">
<h2>...and your email?</h2>
<form name="email" ng-submit="findPersonEmail(dirty.email)" novalidate>
<input class="button flatButton" type="email" ng-model="dirty.email" ng-disabled="person.attributes.name || allEntered" />
<p ng-if="emailFailValidation"> Something is wrong with the email entered</p>
</form>

</div>
<div ng-if="person.attributes.name">
<h2>Hello {{person.attributes.name}}!</h2>
<p ng-show="rsvpd">You have been successfully signed in!</p>
<p ng-hide="rsvpd">Checking you in now...</p>
</div>
</div>
<div ng-if="needEmail">
<h2>...and your email?</h2>
<form name="email" ng-submit="findPersonEmail(dirty.email)">
<input class="button flatButton" type="text" ng-model="dirty.email" ng-disabled="person.attributes.name || allEntered" />
</form>
</div>
<div ng-if="person.attributes.name">
<h2>Hello {{person.attributes.name}}!</h2>
<p ng-show="rsvpd">You have been successfully signed in!</p>
<p ng-hide="rsvpd">Checking you in now...</p>
</div>
</div>
</div>

0 comments on commit a3301d3

Please sign in to comment.