signup authentication with mobile and email using angularjs, ionic

I am building a hybrid app for chat application which comprises user registration and login.

app.controller('registerController', function($scope, $state, $localStorage, Utils, Popup, $window) { $scope.$on('$ionicView.enter', function() {

$scope.user = {
  username: '',
  name: '',
  email: '',
  phone:'',
  password: '',

  profilePic: 'img/profile.png'
};

$scope.profilePic = 'img/profile.png';

});

$scope.register = function(user) {

if (angular.isDefined(user)) {
  Utils.show();
  firebase.database().ref('accounts').orderByChild('email').equalTo(user.email).once('value').then(function(accounts) {
    if (accounts.exists()) {
      Utils.message(Popup.errorIcon, Popup.emailAlreadyExists);
    } else {
      firebase.database().ref('accounts').orderByChild('username').equalTo(user.username).once('value').then(function(accounts) {
        if (accounts.exists()) {
          Utils.message(Popup.errorIcon, Popup.usernameAlreadyExists);
        } else {

          firebase.auth().createUserWithEmailAndPassword(user.email, user.password)
            .then(function() {

              firebase.database().ref().child('accounts').push({
                name: user.name,
                phone: user.phone,
                username: user.username,
                profilePic: user.profilePic,
                email: user.email,
                status:user.status,
                otp:Math.floor(1000 + Math.random() * 9000),
                userId: firebase.auth().currentUser.uid,
                dateCreated: Date(),
                provider: 'Firebase'
              }).then(function(response) {

                Utils.message(Popup.successIcon, Popup.accountCreateSuccess)
                  .then(function() {
                    getAccountAndLogin(response.key);

                  })
                  .catch(function() {

                    getAccountAndLogin(response.key);
                  });
                $localStorage.loginProvider = "Firebase";
                $localStorage.email = user.email;
                $localStorage.phone= user.phone;
                $localStorage.password = user.password;
              });
            })

This is my code. I need to send the otp variable to mobile number and email. Then for login I need to validate the otp.