# Path: serverside/dao/accounts_dao.py
# def create_account(email, 
#                    password, 
#                    enable=False,
#                    account_type="bronze",
#                    payment_type="free"):
# def authenticate_web_account(account_id, password):
# def authenticate_web_account_hashed(account_id, hashedpassword):
# def change_account_password(email, new_password):
# def reset_password(email):
# def authorize_api(account_id, api_key):
# def delete_account(acc_key):
# def save(acc_ref):
# def get_all_accounts():
# def get(acc_key):


from constants import ACCOUNT_STATUS
from entities import memcache_db
from entities.pending_create import Pending_Create
from google.appengine.api import mail
from google.appengine.ext.db import NotSavedError
from google.appengine.ext.webapp import template
from serverside.dao import accounts_dao, pending_create_dao
from serverside.entities.emails import Email
from tools import utils
from tools.xss import XssCleaner
import webapp2
import constants
import environment
import logging
import messages
import uuid
import json
        message = "Your test account has been activated!"
        values = {"success" : True,
                "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
      elif existing_account.isEnabled == ACCOUNT_STATUS.PENDING_CREATE:
        """ REPEAT SIGN UP WITH UNACTIVATED ACCOUNT!!!!!!!!! """
        """ send the email again with the same activation ID """
        pc = pending_create_dao.get_id_by_email(email)
        activate_url = get_activate_url(pc.id)
        email_sent = send_email(email, activate_url)
        logging.info("Repeat sign up for account that was not activated yet. An email will be sent to with same activation link. Email: " + email + ", activation link: " + activate_url)
        message = ""
        if email_sent:
          message = "An email has been sent to you with a link to activate your account!"
        else:
          message = "There was an error during account creation. Please send an email to support@cloudcaptive.com"
        values = {"success" : True,
                  "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
        
      else:
        message = "ERROR: An account using this email address already exists. Contact support@cloudcaptive for support."
        values = {"success" : False,
                "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
    else:    
      """create an account and send an email for validation"""

# Path: serverside/dao/accounts_dao.py
# def create_account(email, 
#                    password, 
#                    enable=False,
#                    account_type="bronze",
#                    payment_type="free"):
# def authenticate_web_account(account_id, password):
# def authenticate_web_account_hashed(account_id, hashedpassword):
# def change_account_password(email, new_password):
# def reset_password(email):
# def authorize_api(account_id, api_key):
# def delete_account(acc_key):
# def save(acc_ref):
# def get_all_accounts():
# def get(acc_key):


# Path: serverside/signup.py
from constants import ACCOUNT_STATUS
from entities import memcache_db
from entities.pending_create import Pending_Create
from google.appengine.api import mail
from google.appengine.ext.db import NotSavedError
from google.appengine.ext.webapp import template
from serverside.dao import accounts_dao, pending_create_dao
from serverside.entities.emails import Email
from tools import utils
from tools.xss import XssCleaner
import webapp2
import constants
import environment
import logging
import messages
import uuid
import json

        message = "Your test account has been activated!"
        values = {"success" : True,
                "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
      elif existing_account.isEnabled == ACCOUNT_STATUS.PENDING_CREATE:
        """ REPEAT SIGN UP WITH UNACTIVATED ACCOUNT!!!!!!!!! """
        """ send the email again with the same activation ID """
        pc = pending_create_dao.get_id_by_email(email)
        activate_url = get_activate_url(pc.id)
        email_sent = send_email(email, activate_url)
        logging.info("Repeat sign up for account that was not activated yet. An email will be sent to with same activation link. Email: " + email + ", activation link: " + activate_url)
        message = ""
        if email_sent:
          message = "An email has been sent to you with a link to activate your account!"
        else:
          message = "There was an error during account creation. Please send an email to support@cloudcaptive.com"
        values = {"success" : True,
                  "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
        
      else:
        message = "ERROR: An account using this email address already exists. Contact support@cloudcaptive for support."
        values = {"success" : False,
                "message" : message}
        if show_links == "yes":
          values['givelinks'] = True 
    else:    
      """create an account and send an email for validation"""

      accounts_dao.create_account(email, password)