# Path: sendinel/backend/models.py
# class AuthenticationCall(models.Model):
#     """
#     Queues all calls that were made to authenticate a user via his 
#     mobile phone number. These calls get deleted once the user has
#     been authenticated successfully.
#     """
#     
#     number = models.CharField(max_length = 20)
#     time = models.DateTimeField(auto_now_add = True)
# 
# Path: sendinel/settings.py
# AUTHENTICATION_ENABLED = False
# 
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# 
# COUNTRY_CODE_PHONE = "0049" #"0027" for South Africa
# 
# START_MOBILE_PHONE = "0" # "0" for South Africa (07/08..), "01" for Germany


import re
from datetime import datetime
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from sendinel.backend.models import AuthenticationCall
from sendinel.settings import AUTHENTICATION_ENABLED, \
                              AUTHENTICATION_CALL_TIMEOUT, \
                              COUNTRY_CODE_PHONE, \
                              START_MOBILE_PHONE



def format_and_validate_phonenumber(number):
    """
    Replaces all number specific characters like
    "+", "-" and "/" and checks that there are no
    letters included. Checks also if the number is 
    the number of a mobile phone.
    
    @param  number:     The phone number that will be checked
    @type   number:     string
    
    @raise  ValueError
    """
   
    if number.startswith('+'):
        number = number.replace('+', '00', 1)
    
    regex = re.compile('(\/|\+|-| )')
    number = regex.sub('', number)
    
    if number.startswith(COUNTRY_CODE_PHONE):

# Path: sendinel/backend/models.py
# class AuthenticationCall(models.Model):
#     """
#     Queues all calls that were made to authenticate a user via his 
#     mobile phone number. These calls get deleted once the user has
#     been authenticated successfully.
#     """
#     
#     number = models.CharField(max_length = 20)
#     time = models.DateTimeField(auto_now_add = True)
# 
# Path: sendinel/settings.py
# AUTHENTICATION_ENABLED = False
# 
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# 
# COUNTRY_CODE_PHONE = "0049" #"0027" for South Africa
# 
# START_MOBILE_PHONE = "0" # "0" for South Africa (07/08..), "01" for Germany


# Path: sendinel/backend/authhelper.py
import re
from datetime import datetime
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext as _
from sendinel.backend.models import AuthenticationCall
from sendinel.settings import AUTHENTICATION_ENABLED, \
                              AUTHENTICATION_CALL_TIMEOUT, \
                              COUNTRY_CODE_PHONE, \
                              START_MOBILE_PHONE




def format_and_validate_phonenumber(number):
    """
    Replaces all number specific characters like
    "+", "-" and "/" and checks that there are no
    letters included. Checks also if the number is 
    the number of a mobile phone.
    
    @param  number:     The phone number that will be checked
    @type   number:     string
    
    @raise  ValueError
    """
   
    if number.startswith('+'):
        number = number.replace('+', '00', 1)
    
    regex = re.compile('(\/|\+|-| )')
    number = regex.sub('', number)
    
    if number.startswith(COUNTRY_CODE_PHONE):

        number = number.replace(COUNTRY_CODE_PHONE, '0', 1)