本文整理汇总了PHP中Common::isUuid方法的典型用法代码示例。如果您正苦于以下问题:PHP Common::isUuid方法的具体用法?PHP Common::isUuid怎么用?PHP Common::isUuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Common
的用法示例。
在下文中一共展示了Common::isUuid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: archive
/**
* Archive a record
* @parma string $model reference of the model instance
* @param UUID $id of the record to archive
* @param boolean $restore, archive or restore?
*/
function archive(&$Model, $id, $restore = false)
{
$success = false;
if (Common::isUuid($id)) {
$Model->data = $Model->read(null, $id);
// check if exist
if (!isset($Model->data[$Model->alias][$this->__settings[$Model->alias]['archive_field']])) {
throw new Exception(__('The resource doesn\'t exist. It may have been deleted.', true));
} elseif ($Model->data[$Model->alias][$this->__settings[$Model->alias]['archive_field']] != $restore) {
if ($restore) {
throw new Exception(__('The resource is already active / restored.', true));
} else {
throw new Exception(__('The resource is already archived.', true));
}
} else {
$Model->data = array();
$Model->id = $id;
$Model->data[$Model->alias][$this->__settings[$Model->alias]['archive_field']] = !$restore;
$success = $Model->save($Model->data);
}
} else {
throw new Exception(__('The given ID is invalid.', true));
}
return $success;
}
示例2: beforeSave
/**
* Before Save callback
* @param $Model
*/
function beforeSave(&$Model)
{
$action = Common::isUuid($Model->id) ? 'update' : 'create';
$details = print_r($Model->data, true);
$this->__deferred = true;
$this->__log($Model->alias, $action, $details, $Model->id);
}
示例3: edit
/**
* Edit a given project
* @param $id project uuid
* @return void
* @access public
*/
function edit($id = null)
{
$this->uuid['action'] = 'df8e4a16-8141-11e0-a245-000ae4cc0097';
// some data where submited
if (!empty($this->data)) {
$this->Project->id = $id;
if ($this->Project->save($this->data)) {
$this->Message->success(sprintf(__('The project was sucessfully saved (%s)', true), $this->Project->id), array('action' => 'index'));
} else {
$this->Message->error('ERROR_PROJECT_EDIT_SAVE', sprintf(__('The project could not be saved, please correct the errors bellow (%)', true), $this->Project->id));
}
} else {
$error = true;
if (!empty($id) && Common::isUuid($id)) {
$project = $this->Project->read(null, $id);
if (!empty($project)) {
$error = false;
$this->data = $project;
}
}
if ($error) {
$this->Message->error('ERROR_INVALID_PROJECT_ID', __('Sorry, this project is invalid or have been deleted', true), array('action' => 'index'));
}
}
}
示例4: verify
/**
* undocumented function
*
* @param unknown $key
* @param unknown $userId
* @return void
* @access public
*/
static function verify($key, $user_id, $auth_key_type_id, $foreign_id = null)
{
$_this = ClassRegistry::init('AuthKey');
AuthKey::purgeExpired();
if (!Common::isUuid($auth_key_type_id)) {
$auth_key_type_id = $_this->AuthKeyType->lookup($auth_key_type_id, 'id', false);
}
if (!Common::isUuid($auth_key_type_id)) {
return false;
}
$options = compact('key', 'user_id', 'auth_key_type_id');
if (!empty($foreign_id)) {
$options = compact('key', 'user_id', 'auth_key_type_id', 'foreign_id');
}
return $_this->hasAny($options);
}
示例5: view
/**
* undocumented function
*
* @return void
* @access public
*/
function view($key)
{
$userId = $this->params['named']['user_id'];
$authKeyTypeId = $this->params['named']['auth_key_type_id'];
Assert::true(Common::isUuid($userId), '403');
Assert::true(Common::isUuid($authKeyTypeId), '403');
Assert::true(AuthKey::verify($key, $userId, $authKeyTypeId), '403');
$authKeyType = $this->AuthKey->AuthKeyType->lookup(array('id' => $authKeyTypeId), 'name', false);
User::login($userId);
switch ($authKeyType) {
case 'Lost Password':
$this->Session->write('lost_password', true);
$msg = __('Please go ahead and change your password now.', true);
$this->Message->add($msg, 'ok', true, '/admin/users/edit_password/' . $userId);
}
}
示例6: receipt
/**
* undocumented function
*
* @param string $key
* @param string $tId
* @return void
* @access public
*/
function receipt($key, $tId)
{
$userId = $this->params['named']['user_id'];
$authKeyTypeId = $this->params['named']['auth_key_type_id'];
Assert::true(Common::isUuid($authKeyTypeId), '403');
Assert::true(Common::isUuid($tId), '403');
Assert::true(AuthKey::verify($key, $userId, $authKeyTypeId, $tId), '403');
$transaction = $this->Transaction->find('first', array('conditions' => array('Transaction.id' => $tId), 'contain' => array('Gift.Contact.Address.Phone', 'Gift.Contact.Phone')));
$this->set(compact('transaction'));
}
示例7: setActive
/**
* Uses a given $user data array to make him the active user
*
* @param array $user A User data array as returned by User::read()
* @return boolean True on success, false on failure
* @access public
*/
static function setActive($user = null, $updateSession = false, $generateAuthCookie = false)
{
$_this = ClassRegistry::init('User');
if (Common::isUuid($user)) {
$user = $_this->find('first', array('conditions' => array('User.id' => $user), 'contain' => array('Role(permissions, name)', 'Contact.Address.State(id, name)', 'Contact.Address.Country(id, name)', 'Contact.Address.City(id, name)'), 'fields' => array('User.id', 'User.name', 'User.login', 'User.password', 'User.permissions', 'User.active', 'User.tooltips', 'User.role_id', 'User.office_id', 'User.contact_id', 'User.lang')));
}
Assert::true(Common::isUuid($user['User']['id']), '500');
Configure::write('User', $user);
Assert::identical(Configure::read('User'), $user);
if (!$updateSession && !$generateAuthCookie) {
return true;
}
if (!User::is('guest') && isset($user['User']['office_id'])) {
$_this->Office->activate($user['User']['office_id']);
}
$Session = Common::getComponent('Session');
Assert::true($Session->write('User', $user));
$Cookie = Common::getComponent('Cookie');
$Cookie->write('Auth.name', $user['User']['login'], false, Configure::read('App.loginCookieLife'));
// if ($user['User']['login'] != Configure::read('App.guestAccount')) {
// $oldDomain = $Cookie->domain;
// $Cookie->domain = '.greenpeace.org';
// $Cookie->write('User.name', $user['User']['name'], false, Configure::read('App.loginCookieLife'));
// $Cookie->write('User.country', $user['Address']['Country']['name'], false, Configure::read('App.loginCookieLife'));
// $Cookie->domain = $oldDomain;
// }
if (!$generateAuthCookie) {
return true;
}
$key = AuthKey::generate(array('auth_key_type_id' => 'Login Cookie'));
$Cookie->write('Auth.key', $key, true, Configure::read('App.loginCookieLife'));
return Assert::equal($Cookie->read('Auth.key'), $key);
}
示例8: setActive
/**
* Set the user as current
* @param array $user
* @param bool $updateSession
* @param bool $generateAuthCookie
*/
static function setActive($user = null, $find = true)
{
$_this = Common::getModel('User');
//@TODO only fetch if $user is incomplete compared to find conditions
if ($find) {
if ($user != 'guest' && isset($user['User']['id']) && Common::isUuid($user['User']['id'])) {
$user = $_this->find('first', $_this->getFindOptions('userActivation', $user));
}
if ($user == 'guest' || is_null($user) || empty($user)) {
$user = $_this->find('first', $_this->getFindOptions('guestActivation'));
}
}
if (isset($user['User']['password'])) {
unset($user['User']['password']);
// just to make sure
}
Configure::write('User', $user);
$Session = Common::getComponent('Session');
$Session->write('User', $user);
return $user;
}
示例9: isOwn
/**
* Returns if the parameter object belongs to the currently logged in user
*
* @param array $obj
* @param string $model
* @return boolean true if the $obj array contains a user_id key that is equal to User::get('id'), false if not
* @access public
*/
static function isOwn($obj, $model)
{
Assert::isArray($obj);
if (isset($obj[$model]['user_id'])) {
$userId = $obj[$model]['user_id'];
} else {
if (isset($obj['user_id'])) {
$userId = $obj['user_id'];
} else {
$userId = User::get('id');
}
}
if (!Common::isUuid($userId)) {
return false;
}
return $userId == User::get('id');
}