/** * Logs admin into the system * @param $login * @param $password * @return \SkullyAdmin\Models\Admin|null */ public function login($login, $password) { /** @var \RedBean_SimpleModel $adminBean */ $adminBean = R::findOne('admin', "status = ? and email = ?", array(Admin::STATUS_ACTIVE, $login)); if (!empty($adminBean)) { /** @var \SkullyAdmin\Models\Admin $admin */ $admin = $adminBean->box(); if ($admin->get('password_hash') == UtilitiesHelper::toHash($password, $admin->get('salt'), $this->app->config('globalSalt'))) { $adminSessions = R::find('adminsession', "admin_id = ?", array($admin->getID())); if (!empty($adminSessions)) { R::trashAll($adminSessions); } // when everything ok, regenerate session session_regenerate_id(true); // change session ID for the current session and invalidate old session ID $adminId = $admin->getID(); $sessionId = session_id(); $adminsession = $this->app->createModel('adminsession', array("admin_id" => $adminId, "session_id" => $sessionId)); $this->app->getSession()->set('adminId', $admin->getID()); R::store($adminsession); return $admin; } } return null; }
/** * Magic Setter. * Sets the value directly as a bean property. * Before setting bean value, try seeing if setProp method exists first. * * @param string $prop property * @param mixed $value value * * @return void */ public function __set($prop, $value) { $method = 'set' . UtilitiesHelper::toCamelCase($prop, true); if (method_exists($this, $method)) { $this->{$method}($value); } else { $this->bean->{$prop} = $value; } }
/** * @param $fieldName * @return array|mixed * It is imperative to use bean here */ protected function _getImageField($fieldName) { try { /** @var \Skully\App\Models\BaseModel $this */ return UtilitiesHelper::decodeJson($this->bean->{$fieldName}, true); } catch (\Exception $e) { return array(); } }
public function beforeSave() { if (!empty($this->password)) { $this->set('salt', time()); $this->set('password_hash', UtilitiesHelper::toHash($this->password, $this->get('salt'), $this->app->config('globalSalt'))); } $this->removeProperty('password'); $this->removeProperty('password_confirmation'); }
public function moveImage() { $id = $this->getParam('id'); $from = (int) $this->getParam('position'); $direction = $this->getParam('direction'); $settingName = $this->getParam('setting'); $fieldName = $this->getParam('field'); if ($direction == 'up') { $to = $from - 1; } else { $to = $from + 1; } $instanceBean = R::findOne($this->model(), 'id = ?', array($id)); $instance = $instanceBean->box(); $images = $instance->get($fieldName); if (!is_array($images)) { $images = UtilitiesHelper::decodeJson($images, true); } $imageFrom = $images[$from]; $images[$from] = $images[$to]; $images[$to] = $imageFrom; $instance->set($fieldName, json_encode($images)); R::store($instance); echo json_encode(array('settingName' => $settingName, 'from' => $from, 'to' => $to)); }
function testSuperArrayUnique() { $array = array('1', '1', array('2', '2')); $array = UtilitiesHelper::superArrayUnique($array); $this->assertEquals("Array\n(\n [0] => 1\n [1] => Array\n (\n [0] => 2\n )\n\n)\n", print_r($array, true)); }