# Path: serverside/constants.py
# class TEMPLATE_PATHS:
#   CONSOLE_LOGIN = os.path.join(os.path.dirname(__file__), '../static/console_templates/login.html')
#   CONSOLE_FORGOTTEN_PASSWORD = os.path.join(os.path.dirname(__file__), '../static/console_templates/forgot.html')
#   CONSOLE_DASHBOARD =  os.path.join(os.path.dirname(__file__), '../static/console_templates/dashboard.html')
#   CONSOLE_USERS =  os.path.join(os.path.dirname(__file__), '../static/console_templates/users.html')
#   CONSOLE_SIGN_UP =  os.path.join(os.path.dirname(__file__), '../static/console_templates/signup_console.html')
#   
#   RENDER_TROPHY_CASE = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/trophy_case.html')
#   RENDER_NOTIFIER = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/notifier.html')
#   RENDER_MILESTONES = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/milestones.html')
#   RENDER_POINTS = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/points.html')
#   RENDER_RANK = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/rank.html')
#   RENDER_LEADERBOARD = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/leaderboard.html')


from google.appengine.ext.webapp import template
from serverside.constants import TEMPLATE_PATHS
from serverside.session import Session
import re
import logging
import string
import random
  import string
  for i in range(len(s)):
    if str(s[i]).isupper():
      ret_str += s[j:i] + " "
      j=i
  ret_str += s[j:]
  
  ret_str = string.capitalize(ret_str[0]) + ret_str[1:]
  return ret_str
  

def validEmail(email):
  """Check to see if the string is formatted as a valid email address.
  """
  
  if len(email) > 7:
    if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
      return 1
    return 0

def account_login_required(handler_method):
  """
  Decorator to check if user is logged in. If user is not logged in they will be redirect to login screen.
  """

  def check_login(self, *args):
    if self.request.method != 'GET' and self.request.method != 'POST':
      self.response.out.write(template.render(TEMPLATE_PATHS.CONSOLE_LOGIN, None))
    else:
      user_session = Session().get_current_session(self)
      if user_session == None:

# Path: serverside/constants.py
# class TEMPLATE_PATHS:
#   CONSOLE_LOGIN = os.path.join(os.path.dirname(__file__), '../static/console_templates/login.html')
#   CONSOLE_FORGOTTEN_PASSWORD = os.path.join(os.path.dirname(__file__), '../static/console_templates/forgot.html')
#   CONSOLE_DASHBOARD =  os.path.join(os.path.dirname(__file__), '../static/console_templates/dashboard.html')
#   CONSOLE_USERS =  os.path.join(os.path.dirname(__file__), '../static/console_templates/users.html')
#   CONSOLE_SIGN_UP =  os.path.join(os.path.dirname(__file__), '../static/console_templates/signup_console.html')
#   
#   RENDER_TROPHY_CASE = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/trophy_case.html')
#   RENDER_NOTIFIER = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/notifier.html')
#   RENDER_MILESTONES = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/milestones.html')
#   RENDER_POINTS = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/points.html')
#   RENDER_RANK = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/rank.html')
#   RENDER_LEADERBOARD = os.path.join(os.path.dirname(__file__), 'api/widgets/v1.0/leaderboard.html')


# Path: serverside/tools/utils.py
from google.appengine.ext.webapp import template
from serverside.constants import TEMPLATE_PATHS
from serverside.session import Session
import re
import logging
import string
import random
  import string

  for i in range(len(s)):
    if str(s[i]).isupper():
      ret_str += s[j:i] + " "
      j=i
  ret_str += s[j:]
  
  ret_str = string.capitalize(ret_str[0]) + ret_str[1:]
  return ret_str
  

def validEmail(email):
  """Check to see if the string is formatted as a valid email address.
  """
  
  if len(email) > 7:
    if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) != None:
      return 1
    return 0

def account_login_required(handler_method):
  """
  Decorator to check if user is logged in. If user is not logged in they will be redirect to login screen.
  """

  def check_login(self, *args):
    if self.request.method != 'GET' and self.request.method != 'POST':
      self.response.out.write(template.render(TEMPLATE_PATHS.CONSOLE_LOGIN, None))
    else:
      user_session = Session().get_current_session(self)
      if user_session == None:

        self.response.out.write(template.render(TEMPLATE_PATHS.CONSOLE_LOGIN, None))  