Пример #1
0
 /**
  * Enter description here...
  *
  * @param unknown_type $userId
  * @param unknown_type $props
  * @return unknown
  */
 public static function createNetwork($userId, $props)
 {
     if (empty($userId) || Api_Dao_User::isUserAdmin($userId)) {
         //create unique network key
         $uniqueKey = false;
         $netKey = '';
         while (!$uniqueKey) {
             $netKey = '';
             for ($k = 0; $k < 32; $k++) {
                 $netKey .= dechex(mt_rand(1, 15));
             }
             $uniqueKey = Api_Dao_Network::checkUniqueKey($netKey);
         }
         $eprops = array();
         foreach ($props as $name => $val) {
             $eprops[$name] = $val;
         }
         if (!isset($eprops['name'])) {
             $eprops['name'] = $netKey;
         }
         $ret = Api_Dao_Network::createNetwork($userId, $netKey, $eprops);
         $netSecret = '';
         for ($k = 0; $k < 32; $k++) {
             $netSecret .= dechex(mt_rand(1, 15));
         }
         $ret = $ret && Api_Bo_DomainService::create()->createDomain($netKey, $eprops['web_url'], $netKey, $netSecret);
         if ($ret !== false) {
             return array($netKey, $netSecret);
         }
         return false;
     }
     throw new Exception('Only the administrator can create networks. (' . $userId . ')');
 }
Пример #2
0
 public static function getUser4()
 {
     static $user;
     if (!isset($user)) {
         $user = new Api_Dao_User();
         $user->setId(10004);
         $user->setUsername("test user 4");
         $user->setPassword("test password 4");
     }
     return $user;
 }
Пример #3
0
 public function testautoincrementIntoDb()
 {
     $dbCon = RsOpenFBDbTestUtils::getDbCon();
     $password = "******";
     $username = "******";
     $user = new Api_Dao_User();
     $user->setUsername($username);
     $user->setPassword($password);
     try {
         $numRows = $this->getNumAllUsers($dbCon);
         $this->assertNull($user->getId());
         $user->insertIntoDb($dbCon);
         $this->assertEquals($numRows + 1, $this->getNumAllUsers($dbCon));
         $this->assertNotNull($user->getId());
         $row = $this->getUser($dbCon, $user->getId());
         $this->assertEquals($user->getId(), $row[id]);
         $this->assertEquals($password, $row['password']);
         $this->assertEquals($username, $row['username']);
     } catch (Exception $exception) {
         $user->deleteFromDb($dbCon);
         throw $exception;
     }
     $user->deleteFromDb($dbCon);
     $this->assertEquals($numRows, $this->getNumAllUsers($dbCon));
 }
Пример #4
0
 /**
  * Creates the user if it's not in the DB.  Throws an exception if the user already exists!
  *
  * @return Array[user][id]
  * @throws Exception
  */
 public function execute()
 {
     //make sure calling application is a default application
     $this->checkDefaultApp();
     require_once AUTH_PLUGINS . $type . '.php';
     $method = new $className();
     $userid = $method->findUser($apiParams);
     if (!empty($userid)) {
         throw new OpenFBAPIException("User credentials already exist!", 1);
     }
     if (!empty($linked)) {
         // Link a give UID to a set of credentials.
         $user = RingsideOpenFBDbAuth::findUser($linked);
         if ($user === false) {
             throw new OpenFBAPIException("Linked UID does not exist", 1);
         }
         $method->linkUser($linked, $apiParams);
     } else {
         $user = new RingsideOpenFBDbAuth();
         $user->setNid($this->getNetworkId());
         $user->insertIntoDb($this->getDbCon());
     }
     $user = new Api_Dao_User();
     $user->setUsername($this->user_name);
     $user->setPassword($this->password);
     $response = array();
     if (!$user->initByUserName($this->user_name)) {
         $user->insertIntoDb($this->getDbCon());
         $response['user'] = array();
         $response['user']['id'] = $user->getId();
     } else {
         throw new Exception("User {$this->user_name} already exists!");
     }
     return $response;
 }
Пример #5
0
     loadErrorClass($flavor, 'Email validation failed.');
     return;
 }
 if (!validateName($name)) {
     loadErrorClass($flavor, 'Please specify a first and last name');
     return;
 }
 if (!validatePassword($password)) {
     loadErrorClass($flavor, 'Password must be specified');
     return;
 }
 $uid = null;
 try {
     $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
     //$client->api_client->admin_createUser($email, $password);
     $user = new Api_Dao_User();
     $user->setUsername($email);
     $user->setPassword(sha1($password));
     if (!$user->initByUserName($email, $dbCon)) {
         try {
             $user->insertIntoDb($dbCon);
             saveName($user->getId(), $name);
             $uid = $user->getId();
             error_log("REGISTERED NEW ONE " . $user->getId());
         } catch (Exception $e) {
             $error = 'Failed to create user: '******'User already exists!';
     }
 } catch (Exception $e) {
Пример #6
0
 /**
  * Enter description here...
  *
  * @param unknown_type $userId
  * @return unknown
  */
 public static function isUserAdmin($userId)
 {
     return Api_Dao_User::isUserAdmin($userId);
 }
Пример #7
0
/**
 * Authenticate a user.
 *
 * @param string $username
 * @param string $password
 * @return true if there were no errors and user was authenticated, error string if there was an error. 
 */
function authenticate($username, $password, $flavor)
{
    // Authenticate user.
    try {
        // TODO move to use PHP Auth?
        $dbCon = RingsideApiDbDatabase::getDatabaseConnection();
        $userDb = new Api_Dao_User();
        $uid = $userDb->login($username, $password, $dbCon);
        return $uid;
    } catch (Exception $e) {
        $error = '';
        $code = $e->getCode();
        if ($code == NO_USER) {
            $error = "No User with User Name {$username} exists!<BR><a href=\"register.php\">Sign Up!</a>";
        } else {
            if ($code == BAD_PASSWORD) {
                $error = 'Invalid Password';
            } else {
                $error = $e->getMessage();
            }
        }
        loadForm($flavor, $error, $_REQUEST);
    }
    return false;
}
Пример #8
0
 public function execute()
 {
     return Api_Dao_User::getInfo($this->getApiParams(), $this->getAppId(), $this->getUserId());
 }