Пример #1
0
  def create_user_accounts(cls, email, password, uaserver_host, keyname):
    """Registers two new user accounts with the UserAppServer.

    One account is the standard account that users log in with (via their
    e-mail address. The other is their XMPP account, so that they can log into
    any jabber-compatible service and send XMPP messages to their application
    (and receive them).

    Args:
      email: The e-mail address that should be registered for the user's
        standard account.
      password: The password that should be used for both the standard and XMPP
        accounts.
      uaserver_host: The location of a UserAppClient, that can create new user
        accounts.
      keyname: The name of the SSH keypair used for this AppScale deployment.
    """
    uaserver = UserAppClient(uaserver_host, LocalState.get_secret_key(keyname))

    # first, create the standard account
    encrypted_pass = LocalState.encrypt_password(email, password)
    uaserver.create_user(email, encrypted_pass)

    # next, create the XMPP account. if the user's e-mail is [email protected], then that
    # means their XMPP account name is a@login_ip
    username_regex = re.compile('\A(.*)@')
    username = username_regex.match(email).groups()[0]
    xmpp_user = "******".format(username, LocalState.get_login_host(keyname))
    xmpp_pass = LocalState.encrypt_password(xmpp_user, password)
    uaserver.create_user(xmpp_user, xmpp_pass)
    AppScaleLogger.log("Your XMPP username is {0}".format(xmpp_user))
Пример #2
0
  def create_user_accounts(cls, email, password, public_ip, keyname):
    """Registers two new user accounts with the UserAppServer.

    One account is the standard account that users log in with (via their
    e-mail address. The other is their XMPP account, so that they can log into
    any jabber-compatible service and send XMPP messages to their application
    (and receive them).

    Args:
      email: The e-mail address that should be registered for the user's
        standard account.
      password: The password that should be used for both the standard and XMPP
        accounts.
      public_ip: The location where the AppController can be found.
      keyname: The name of the SSH keypair used for this AppScale deployment.
    """
    acc = AppControllerClient(public_ip, LocalState.get_secret_key(keyname))

    is_new_user = False
    # first, create the standard account
    encrypted_pass = LocalState.encrypt_password(email, password)
    if acc.does_user_exist(email):
      AppScaleLogger.log("User {0} already exists, so not creating it again.".
        format(email))
    else:
      acc.create_user(email, encrypted_pass)
      is_new_user = True

    # next, create the XMPP account. if the user's e-mail is [email protected], then that
    # means their XMPP account name is a@login_ip
    username_regex = re.compile('\A(.*)@')
    username = username_regex.match(email).groups()[0]

    try:
      login_host = acc.get_property('login')['login']
    except KeyError:
      raise AppControllerException('login property not found')

    xmpp_user = "******".format(username, login_host)
    xmpp_pass = LocalState.encrypt_password(xmpp_user, password)

    is_xmpp_user_exist = acc.does_user_exist(xmpp_user)

    if is_xmpp_user_exist and is_new_user:
      AppScaleLogger.log("XMPP User {0} conflict!".format(xmpp_user))

      generated_xmpp_username = LocalState.generate_xmpp_username(username)
      xmpp_user = "******".format(generated_xmpp_username, login_host)
      xmpp_pass = LocalState.encrypt_password(xmpp_user, password)

      acc.create_user(xmpp_user, xmpp_pass)
    elif is_xmpp_user_exist and not is_new_user:
      AppScaleLogger.log("XMPP User {0} already exists, so not creating it again.".format(xmpp_user))
    else:
      acc.create_user(xmpp_user, xmpp_pass)
    AppScaleLogger.log("Your XMPP username is {0}".format(xmpp_user))
Пример #3
0
    def create_new_user(self,
                        email,
                        password,
                        response,
                        account_type='xmpp_user'):
        """ Creates a new user account, by making both a standard login and an
    XMPP login account.

    Args:
      email: A str containing the e-mail address of the new user.
      password: A str containing the cleartext password for the new user.
      response: A webapp2 response that the new user's logged in cookie
        should be set in.
    Returns:
      True, if the user account was successfully created.
    Raises:
      AppHelperException: If the user account could not be created.
    """
        try:
            uaserver = self.get_uaserver()
            # First, create the standard account.
            encrypted_pass = LocalState.encrypt_password(email, password)
            result = uaserver.commit_new_user(email, encrypted_pass,
                                              account_type, GLOBAL_SECRET_KEY)
            if result != 'true':
                raise AppHelperException(result)

            # Next, create the XMPP account. if the user's e-mail is [email protected], then that
            # means their XMPP account name is a@login_ip.
            username_regex = re.compile(self.USERNAME_FROM_EMAIL_REGEX)
            username = username_regex.match(email).groups()[0]
            xmpp_user = "******".format(username, self.get_login_host())
            xmpp_pass = LocalState.encrypt_password(xmpp_user, password)
            result = uaserver.commit_new_user(xmpp_user, xmpp_pass,
                                              account_type, GLOBAL_SECRET_KEY)
            if result != 'true':
                raise AppHelperException(result)

            # TODO: We may not even be using this token since the switch to
            # full proxy nginx. Investigate this.
            self.create_token(email, email)
            self.set_appserver_cookie(email, self.get_user_app_list(email),
                                      response)
        except AppHelperException as err:
            logging.exception(err)
            raise AppHelperException(str(err))
        except Exception as err:
            logging.exception(err)
            raise AppHelperException(str(err))
        return True
Пример #4
0
    def login_user(self, email, password, response):
        """ Checks to see if the user has entered in a valid email and password,
    logging the user in if they have.

    Args:
      email: A str containing the e-mail address of the user to login.
      password: A str containing the cleartext password of the user to login.
      response: A webapp2 response that the new user's logged in cookie
        should be set in.
    Return:
      True if the user logged in successfully, and False otherwise.
    """
        user_data = self.query_user_data(email)
        server_re = re.search(self.USER_DATA_PASSWORD_REGEX, user_data)
        if not server_re:
            logging.error("Failed Login: {0} regex failed".format(email))
            return False
        server_pwd = server_re.group(1)
        encrypted_pass = LocalState.encrypt_password(email, password)
        if server_pwd != encrypted_pass:
            logging.info("Failed Login: {0} password mismatch".format(email))
            return False
        self.create_token(email, email)
        self.set_appserver_cookie(email, self.get_user_app_list(email),
                                  response)
        return True
Пример #5
0
  def login_user(self, email, password, response):
    """ Checks to see if the user has entered in a valid email and password,
    logging the user in if they have.

    Args:
      email: A str containing the e-mail address of the user to login.
      password: A str containing the cleartext password of the user to login.
      response: A webapp2 response that the new user's logged in cookie
        should be set in.
    Return:
      True if the user logged in successfully, and False otherwise.
    """
    user_data = self.query_user_data(email)
    server_re = re.search(self.USER_DATA_PASSWORD_REGEX, user_data)
    if not server_re:
      logging.error("Failed Login: {0} regex failed".format(email))
      return False
    server_pwd = server_re.group(1)
    encrypted_pass = LocalState.encrypt_password(email, password)
    if server_pwd != encrypted_pass:
      logging.info("Failed Login: {0} password mismatch".format(email))
      return False
    self.create_token(email, email)
    self.set_appserver_cookie(email, self.get_user_app_list(email), response)
    return True
Пример #6
0
  def create_new_user(self, email, password, response,
    account_type='xmpp_user'):
    """ Creates a new user account, by making both a standard login and an
    XMPP login account.

    Args:
      email: A str containing the e-mail address of the new user.
      password: A str containing the cleartext password for the new user.
      response: A webapp2 response that the new user's logged in cookie
        should be set in.
    Returns:
      True, if the user account was successfully created.
    Raises:
      AppHelperException: If the user account could not be created.
    """
    try:
      uaserver = self.get_uaserver()
      # First, create the standard account.
      encrypted_pass = LocalState.encrypt_password(email, password)
      result = uaserver.commit_new_user(email, encrypted_pass, account_type,
        GLOBAL_SECRET_KEY)
      if result != 'true':
        raise AppHelperException(result)

      # Next, create the XMPP account. if the user's e-mail is [email protected], then that
      # means their XMPP account name is a@login_ip.
      username_regex = re.compile(self.USERNAME_FROM_EMAIL_REGEX)
      username = username_regex.match(email).groups()[0]
      xmpp_user = "******".format(username,
        self.get_login_host())
      xmpp_pass = LocalState.encrypt_password(xmpp_user, password)
      result = uaserver.commit_new_user(xmpp_user, xmpp_pass, account_type,
        GLOBAL_SECRET_KEY)
      if result != 'true':
        raise AppHelperException(result)

      # TODO: We may not even be using this token since the switch to
      # full proxy nginx. Investigate this.
      self.create_token(email, email)
      self.set_appserver_cookie(email, self.get_user_app_list(email), response)
    except AppHelperException as err:
      logging.exception(err)
      raise AppHelperException(str(err))
    except Exception as err:
      logging.exception(err)
      raise AppHelperException(str(err))
    return True
Пример #7
0
  def create_user_accounts(cls, email, password, public_ip, keyname,
    clear_datastore):
    """Registers two new user accounts with the UserAppServer.

    One account is the standard account that users log in with (via their
    e-mail address. The other is their XMPP account, so that they can log into
    any jabber-compatible service and send XMPP messages to their application
    (and receive them).

    Args:
      email: The e-mail address that should be registered for the user's
        standard account.
      password: The password that should be used for both the standard and XMPP
        accounts.
      public_ip: The location where the AppController can be found.
      keyname: The name of the SSH keypair used for this AppScale deployment.
      clear_datastore: A bool that indicates if we expect the datastore to be
        emptied, and thus not contain any user accounts.
    """
    acc = AppControllerClient(public_ip, LocalState.get_secret_key(keyname))

    # first, create the standard account
    encrypted_pass = LocalState.encrypt_password(email, password)
    if not clear_datastore and acc.does_user_exist(email):
      AppScaleLogger.log("User {0} already exists, so not creating it again.".
        format(email))
    else:
      acc.create_user(email, encrypted_pass)

    # next, create the XMPP account. if the user's e-mail is [email protected], then that
    # means their XMPP account name is a@login_ip
    username_regex = re.compile('\A(.*)@')
    username = username_regex.match(email).groups()[0]
    xmpp_user = "******".format(username, LocalState.get_login_host(keyname))
    xmpp_pass = LocalState.encrypt_password(xmpp_user, password)

    if not clear_datastore and acc.does_user_exist(xmpp_user):
      AppScaleLogger.log(
        "XMPP User {0} already exists, so not creating it again.".
        format(xmpp_user))
    else:
      acc.create_user(xmpp_user, xmpp_pass)
    AppScaleLogger.log("Your XMPP username is {0}".format(xmpp_user))
Пример #8
0
    def create_user_accounts(cls, email, password, public_ip, keyname):
        """Registers two new user accounts with the UserAppServer.

    One account is the standard account that users log in with (via their
    e-mail address. The other is their XMPP account, so that they can log into
    any jabber-compatible service and send XMPP messages to their application
    (and receive them).

    Args:
      email: The e-mail address that should be registered for the user's
        standard account.
      password: The password that should be used for both the standard and XMPP
        accounts.
      public_ip: The location where the AppController can be found.
      keyname: The name of the SSH keypair used for this AppScale deployment.
    """
        acc = AppControllerClient(public_ip,
                                  LocalState.get_secret_key(keyname))

        # first, create the standard account
        encrypted_pass = LocalState.encrypt_password(email, password)
        if acc.does_user_exist(email):
            AppScaleLogger.log(
                "User {0} already exists, so not creating it again.".format(
                    email))
        else:
            acc.create_user(email, encrypted_pass)

        # next, create the XMPP account. if the user's e-mail is [email protected], then that
        # means their XMPP account name is a@login_ip
        username_regex = re.compile('\A(.*)@')
        username = username_regex.match(email).groups()[0]
        xmpp_user = "******".format(username,
                                     LocalState.get_login_host(keyname))
        xmpp_pass = LocalState.encrypt_password(xmpp_user, password)

        if acc.does_user_exist(xmpp_user):
            AppScaleLogger.log(
                "XMPP User {0} already exists, so not creating it again.".
                format(xmpp_user))
        else:
            acc.create_user(xmpp_user, xmpp_pass)
        AppScaleLogger.log("Your XMPP username is {0}".format(xmpp_user))
    def reset_password(cls, options):
        """Resets a user's password the currently running AppScale deployment.

    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    """
        secret = LocalState.get_secret_key(options.keyname)
        username, password = LocalState.get_credentials(is_admin=False)
        encrypted_password = LocalState.encrypt_password(username, password)

        uac = UserAppClient(LocalState.get_login_host(options.keyname), secret)

        try:
            uac.change_password(username, encrypted_password)
            AppScaleLogger.success("The password was successfully changed for the " "given user.")
        except Exception as exception:
            AppScaleLogger.warn(
                "Could not change the user's password for the " + "following reason: {0}".format(str(exception))
            )
            sys.exit(1)
Пример #10
0
    def reset_password(cls, options):
        """Resets a user's password the currently running AppScale deployment.

    Args:
      options: A Namespace that has fields for each parameter that can be
        passed in via the command-line interface.
    """
        secret = LocalState.get_secret_key(options.keyname)
        username, password = LocalState.get_credentials(is_admin=False)
        encrypted_password = LocalState.encrypt_password(username, password)

        uac = UserAppClient(LocalState.get_login_host(options.keyname), secret)

        try:
            uac.change_password(username, encrypted_password)
            AppScaleLogger.success("The password was successfully changed for the " \
              "given user.")
        except Exception as exception:
            AppScaleLogger.warn("Could not change the user's password for the " + \
              "following reason: {0}".format(str(exception)))
            sys.exit(1)