public function __construct()
    {
        $user_id = IsSetPost(USERS_USERID);
        if (!$user_id)
        {
            throw new UserActionException("a user must be selected to update");
        }
        if (!is_numeric($user_id))
        {
            throw new UserActionException("a user id must be numeric");
        }

        $password = IsSetPost(USERS_PASSWORD);
        if (!$password)
        {
            throw new UserActionException("a password must be set");
        }
        if (!is_string($password))
        {
            throw new UserActionException("a password must a string");
        }
        if (strlen($password) > 20)
        {
            throw new UserActionException("a password cannot be longer than 20 characters");
        }
        if (strlen($password) < 5)
        {
            throw new UserActionException("a password cannot be shorter than 5 characters");
        }
        
        $new_data[USERS_SALT] = GetNewSalt();
        $new_data[USERS_PASSWORD] = GetSecondOrderHash(
                $password,
                $new_data[USERS_SALT]);

        try
        {
            $user_factory =& FCore::LoadDBFactory(BN_DBFACTORY_USERMODEL);
            $user_factory->update($new_data, $user_id);
        }
        catch(Exception $e)
        {
            throw new UserActionException($e->getMessage());
        }
    }
Example #2
0
    public function do_create()
    {
        $user_factory =& FCore::LoadDBFactory(BN_DBFACTORY_USERMODEL);
        $data_rules = $user_factory->get_db_data_rules(
                DataRules::METHOD_POST, false);
        $this->data = GrabDataFromGlobal($data_rules);

        $this->data[USERS_ISMASTER]       = "0";
        $this->data[USERS_SCHEMEUSING]    = 'default';
        $this->data[USERS_CREATEDWHEN]    = array(
            DBFactory::INSERT_ESCAPE_VAL    => false,
            DBFactory::INSERT_QUOTE         => false,
            DBFactory::INSERT_VALUE         => "NOW()"
        );

        $password = IsSetPost(USERS_PASSWORD);
        $this->data[USERS_SALT]     = GetNewSalt();
        $this->data[USERS_PASSWORD] = GetSecondOrderHash($password, $this->data[USERS_SALT]);

        try
        {
            $data_rules->validate_data($this->data);
        }
        catch(Exception $e)
        {
            $this->data[USERS_PASSWORD] = $password;
            throw new UserActionException($e->getMessage());
        }

        try
        {
            $this->data[USERS_USERID] = $user_factory->insert($this->data);
        }
        catch(DBFactoryException $e)
        {
            $this->data[USERS_PASSWORD] = $password;
            throw new UserActionException($e->getPrevious()->getMessage());
        }
        catch(Exception $e)
        {
            $this->data[USERS_PASSWORD] = $password;
            throw new UserActionException($e->getMessage());
        }
    }