Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone validation #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
<script type="text/javascript" src="scripts/filters/removePassedEventsFilter.js"></script>
<script type="text/javascript" src="scripts/filters/startFromFilter.js"></script>
<script type="text/javascript" src="scripts/filters/yearSearchFilter.js"></script>
<script type="text/javascript" src="scripts/filters/phoneNumberFilter.js"></script>

<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/unminified.js -->
<script type="text/javascript" src="scripts/directives/externalHref.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions app/indexios.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@
<script type="text/javascript" src="scripts/filters/removePassedEventsFilter.js"></script>
<script type="text/javascript" src="scripts/filters/startFromFilter.js"></script>
<script type="text/javascript" src="scripts/filters/yearSearchFilter.js"></script>
<script type="text/javascript" src="scripts/filters/phoneNumberFilter.js"></script>

<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/unminified.js -->
<script type="text/javascript" src="scripts/ios/initializeCordova.js"></script>
Expand Down
34 changes: 26 additions & 8 deletions app/scripts/controllers/accountInfoController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
App.controller('accountinfoController', ['$scope', 'RESTService', '$rootScope', '$timeout', 'Organization', 'AUTH_EVENTS', 'Session', 'Directory', '$location', function($scope, RESTService, $rootScope, $timeout, Organization, AUTH_EVENTS, Session, Directory, $location){
$scope.session = Session;
$scope.updatedInfo = false;
$scope.item = Session.me;
$scope.checkAlumni = Session.perms == 'alumni';
if ($scope.item.dob){
$scope.item.dob = moment($scope.item.dob).format('MM/DD/YYYY');
initialize();
$scope.checkAlumni = Session.perms === 'alumni';

function initialize(){
var me = JSON.parse(JSON.stringify(Session.me));
if(me.dob){
me.dob = moment(me.dob).format('MM/DD/YYYY');
}
if(me.phone){
me.phone = me.phone.replace(/[^0-9.]/g, '');
if (me.phone.length === 10){
me.phone = me.phone.slice(0, 3) + '-' + me.phone.slice(3, 6) + '-' + me.phone.slice(6, 10);
}
else{
me.phone = "";
}
}
$scope.item = me;
}

$scope.changePassword = function(old_pass, new_pass) {
Expand Down Expand Up @@ -34,20 +48,24 @@ App.controller('accountinfoController', ['$scope', 'RESTService', '$rootScope',
$location.path('app/directory/'+Session.user_name);
}

$scope.checkAlumni = function(){
$scope.checkAlumni = function() {
return Session.perms != 'alumni';
}


$scope.updateAccount = function(isValid){
console.log(isValid);
debugger;
var to_send = JSON.parse(JSON.stringify($scope.item));
to_send.phone = to_send.phone.replace(/[^0-9.]/g, '');

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reference to my previous comment, removing formatting for storage in database

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to get rid of that debugger?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, makes it more interesting for the sorority girls.

if(isValid){
RESTService.post(ENDPOINTS_DOMAIN + '/_ah/api/netegreek/v1/user/update_user_directory_info', $scope.item)
RESTService.post(ENDPOINTS_DOMAIN + '/_ah/api/netegreek/v1/user/update_user_directory_info', to_send)
.success(function(data){
if (!RESTService.hasErrors(data))
{
$scope.updatedInfo = true;
Directory.updateMe($scope.item);
Directory.updateMe(to_send);
Session.updateMe(to_send);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/controllers/calendarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ App.controller('calendarController', ['Session', '$scope', 'RESTService', '$root
}
};

$scope.goToEvent = function(event) {
$location.path('app/events/' + event);
$scope.goToEvent = function(key) {
$location.path('app/events/' + key);

};

$scope.$watch('search', function() {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/memberProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ App.controller('memberprofileController', ['$scope', '$rootScope', '$stateParams
$scope.lastName = $scope.member.last_name;
$scope.email = $scope.member.email;
$scope.birthday = $scope.member.dob;
$scope.phone = $scope.member.phone;
$scope.phone = $scope.member.phone.replace(/[^0-9.]/g, '');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to allow dashes in the phone number here?

$scope.currentAddress = $scope.member.address + " " + $scope.member.city + " " + $scope.member.state + " " + $scope.member.zip;
$scope.position = $scope.member.position;
$scope.permanentAddress = $scope.member.perm_address + " " + $scope.member.perm_city + " " + $scope.member.perm_state + " " + $scope.member.perm_zip;
Expand Down
13 changes: 13 additions & 0 deletions app/scripts/filters/phoneNumberFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
App.filter('phoneNumber', function() {
return function(number) {
if (number){
if (number.length === 10) {
return number.slice(0, 3) + '-' + number.slice(3, 6) + '-' + number.slice(6, 10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the phone number requires dashes with our pattern and we don't get rid of the dashes, then this filter isn't necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we have validation on the number with dashes, the database was storing just numbers. I'd rather store just the raw number without formatting because it is much easier to add formatting, than remove it if we decide to change the formatting later. Ex: 1-832-221-5607 or 832-221-5607, Opening text service on the phone is: "sms://+18322215607". It's easier to inject those '-' on just the raw american 10 digit number than remove whatever formatting and figure out when country code is already added.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we either need a filter for adding dashes, or removing them. It may be a good thing to go ahead and require the country code for storage and for the time being just assume america, and hide the country code for viewing

}
else{
return number;
}
}
return number;
};
});
19 changes: 19 additions & 0 deletions app/scripts/ios/pushNotificationConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,23 @@ angular.module("App").run(function($rootScope, AUTH_EVENTS) {
alert('error = ' + error);
}
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore me

// $rootScope.$on('sendSMS', function(event, data){
// var parsed = JSON.parse(data);
// var number = parsed.number;

// //CONFIGURATION
// var options = {
// replaceLineBreaks: false, // true to replace \n by a new line, false by default
// android: {
// intent: 'INTENT' // send SMS with the native android SMS messaging
// //intent: '' // send SMS without open any other app
// }
// };

// var success = function () { alert('Message sent successfully'); };
// var error = function (e) { alert('Message Failed:' + e); };
// sms.send(number, message, options, success, error);
// }
// });
});
2 changes: 1 addition & 1 deletion app/views/accountinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ <h1>Account Info</h1>
</md-input-container>
<md-input-container class="md-default-theme required" ng-class="{ 'md-input-invalid' : (memberAccount.phone.$invalid && !memberAccount.phone.$pristine) || (memberAccount.phone.$invalid && submitted)}">
<label for="phone">###-###-####</label>
<input type="tel" name="phone" ng-model="item.phone" required/>
<input type="tel" name="phone" ng-model="item.phone" pattern="\d{3}-\d{3}-\d{4}" required/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we require a pattern, then the filter is just for the current numbers in our system?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, just for displaying the numbers.

<p class="text-danger invalid-text">Please select a valid phone number.</p>
</md-input-container>
<div class="form-group" ng-class="{ 'md-input-invalid' : (memberAccount.dob.$invalid && !memberAccount.dob.$pristine) || (memberAccount.dob.$invalid && submitted)}">
Expand Down
6 changes: 3 additions & 3 deletions app/views/memberprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ <h5 ng-show="position.length">{{position}}</h5>
<span id="info"><br><br>
<div class="row">
<div class="col-xs-12 col-sm-6" ng-show="phone">
<a ng-href="sms://{{phone}}">
<div layout="row" layout-align="start center"><i class="fa fa-fw fa-phone fa-3x theme-color" flex="30"></i><p flex>{{phone}}</p></div>
<a external-href="sms:+1{{phone}}">
<div layout="row" layout-align="start center"><i class="fa fa-fw fa-phone fa-3x theme-color" flex="30"></i><p flex>{{phone | phoneNumber}}</p></div>
</a>
</div>
<div class="col-xs-12 col-sm-6" ng-show="email">
<a ng-href="mailto://{{email}}">
<a external-href="mailto:{{email}}">
<div layout="row" layout-align="start center"><i class="fa fa-fw fa-envelope-o fa-3x theme-color" flex="30"></i><p flex>{{email}}</p></div>
</a>
</div>
Expand Down
3 changes: 2 additions & 1 deletion plugins/ios.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"xml": false,
"count": 1
}
]
],
"MessageUI.framework": []
}
}
}
Expand Down