Пример #1
0
    def get(self):
        """Account activation via email"""

        values = {'error_message': "Activation not successful.", 'error': True}

        id = self.request.get("activate")
        error_message = self.request.get("error_msg")
        if id == None or id == "":
            if error_message:
                values['error_message'] = error_message
            logging.error("Activation attempted without ID")
        else:
            """Look up the account in pending creates table"""
            try:
                pending_entity = Pending_Create.get_by_key_name(id)
                account = None
                if pending_entity != None:
                    """ Look up corresponding account entity """
                    email = pending_entity.email
                    account = memcache_db.get_entity(email, "Accounts")
                else:
                    logging.error("Pending entity could not be looked up.")

                if account != None:
                    if account.isEnabled == ACCOUNT_STATUS.PENDING_CREATE:
                        update_fields = {"isEnabled": ACCOUNT_STATUS.ENABLED}
                        memcache_db.update_fields(email, "Accounts",
                                                  update_fields)

                        try:
                            """ remove item from pending creates """
                            pending_entity.delete()
                        except NotSavedError:
                            logging.error("Entity with id: " + id +
                                          " was not in data store...")

                        values = {'activation': True}
                    else:
                        logging.error("Account status is not pending create")

            except:
                logging.error("Activation tried and failed with ID: " + id)
        """ render with values set above """
        self.response.out.write(
            template.render(constants.TEMPLATE_PATHS.CONSOLE_LOGIN, values))
Пример #2
0
 def get(self):
   """Account activation via email"""
   
   values = {'error_message' : "Activation not successful.",
             'error': True}
   
   id = self.request.get("activate")
   error_message = self.request.get("error_msg") 
   if id == None or id == "":
     if error_message:
       values['error_message'] = error_message
     logging.error("Activation attempted without ID")
   else:
     """Look up the account in pending creates table"""
     try:
       pending_entity = Pending_Create.get_by_key_name(id)
       account = None
       if pending_entity != None:
         """ Look up corresponding account entity """
         email = pending_entity.email
         account = memcache_db.get_entity(email, "Accounts")
       else:
         logging.error("Pending entity could not be looked up.")
         
       if account != None:
         if account.isEnabled == ACCOUNT_STATUS.PENDING_CREATE:
           update_fields = {"isEnabled" : ACCOUNT_STATUS.ENABLED }
           memcache_db.update_fields(email, "Accounts", update_fields)
           
           try:
             """ remove item from pending creates """
             pending_entity.delete()
           except NotSavedError:
             logging.error("Entity with id: " + id + " was not in data store...")
             
           values = {'activation' : True}
         else:
           logging.error("Account status is not pending create")
           
     except:
       logging.error("Activation tried and failed with ID: " + id)
   
   """ render with values set above """
   self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_LOGIN, values))
Пример #3
0
  def post(self):
    email = self.request.get("email")
    password = self.request.get("password")
    repeat_password = self.request.get('repeat_password')
    show_links = self.request.get("show_links")
    if not utils.validEmail(email):
      values = {"success" : False,
                "message" : "ERROR: You need to provide a valid email address."}
      if show_links == "yes":
        values['givelinks'] = True 
      self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))
      logging.error("Bad email %s"%email)
      return
    if password != repeat_password:
      values = {"success" : False,
                "message" : "ERROR: Passwords did not match."}
      if show_links == "yes":
        values['givelinks'] = True 
      logging.error("Bad passwords for email %s"%email)
      self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))
      return   
    ent_type = 'Accounts'
    existing_account = memcache_db.get_entity(email, ent_type)
    if existing_account != None:
      logging.error('An account already exists with that email: ' + existing_account.email)
 
      """ if the account is a test account, activate the account """
      if email in constants.TEST_ACCOUNTS and environment.is_dev():
        logging.debug("Account is a valid test account")
        
        memcache_db.delete_entity(existing_account, email)
        accounts_dao.create_account(email, password, True)
        
        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 [email protected]"
        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@appscale 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)
      
      """Add email to pending creates table"""
      id = str(uuid.uuid4())
      pending_create = Pending_Create(key_name=id, id=id, email=email)
      pending_create.put()
          
      
      """send an email to user to complete set up, get arguments in the string will be email and cookie ID"""
      activate_url = get_activate_url(id)
      logging.info("Activation URL for account: " + email + " is " + activate_url)
      email_sent = send_email(email, activate_url)
  
      message = ""
      if email_sent:
        message = "Sign up was a success. An activation link has been sent to your email address."
      else:
        message = "There was an error during account creation. Please send an email to [email protected]"
      values = {"success" : True,
                "message" : message}
      if show_links == "yes":
        values['givelinks'] = True 
    """ Render result with whatever values were filled in above """  
    self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))
Пример #4
0
  def post(self):
    email = self.request.get("email")
    password = self.request.get("password")
    repeat_password = self.request.get('repeat_password')
    show_links = self.request.get("show_links")
    if not utils.validEmail(email):
      values = {"success" : False,
                "message" : "ERROR: You need to provide a valid email address."}
      if show_links == "yes":
        values['givelinks'] = True 
      self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))
      logging.error("Bad email %s"%email)
      return
    if password != repeat_password:
      values = {"success" : False,
                "message" : "ERROR: Passwords did not match."}
      if show_links == "yes":
        values['givelinks'] = True 
      logging.error("Bad passwords for email %s"%email)
      self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))
      return   
    ent_type = 'Accounts'
    existing_account = memcache_db.get_entity(email, ent_type)
    if existing_account != None:
      logging.error('An account already exists with that email: ' + existing_account.email)
 
      """ if the account is a test account, activate the account """
      if email in constants.TEST_ACCOUNTS and environment.is_dev():
        logging.debug("Account is a valid test account")
        
        memcache_db.delete_entity(existing_account, email)
        accounts_dao.create_account(email, password, True)
        
        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 [email protected]"
        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)
      
      """Add email to pending creates table"""
      id = str(uuid.uuid4())
      pending_create = Pending_Create(key_name=id, id=id, email=email)
      pending_create.put()
          
      
      """send an email to user to complete set up, get arguments in the string will be email and cookie ID"""
      activate_url = get_activate_url(id)
      logging.info("Activation URL for account: " + email + " is " + activate_url)
      email_sent = send_email(email, activate_url)
  
      message = ""
      if email_sent:
        message = "Sign up was a success. An activation link has been sent to your email address."
      else:
        message = "There was an error during account creation. Please send an email to [email protected]"
      values = {"success" : True,
                "message" : message}
      if show_links == "yes":
        values['givelinks'] = True 
    """ Render result with whatever values were filled in above """  
    self.response.out.write(template.render(constants.TEMPLATE_PATHS.CONSOLE_SIGN_UP, values))