/** * Extract validation * validations.type = configuration * validations.required = configuration * * validations.required * validations.required.message */ protected function _validation($action = null) { $section = zbase_section(); if (empty($action)) { $action = zbase_route_input('action'); } $validations = $this->_v('validations.' . $action . '.' . $section, $this->_v('validations.' . $action, $this->_v('validations', []))); $this->_fixValidation = true; if (!empty($validations)) { foreach ($validations as $type => $config) { $enable = zbase_data_get($config, 'enable'); // $enable = $enable ? true : false; if (!empty($enable)) { if (!empty($config['text'])) { $this->_validationRules[] = zbase_data_get($config, 'text'); } else { if (!in_array($type, $this->_validationRules)) { $this->_validationRules[] = $type; } } if (!empty($config['message'])) { $this->_validationMessages[$this->name() . '.' . $type] = zbase_data_get($config, 'message'); } } } } }
public function reset() { if (!$this->authEnabled()) { return $this->notfound('User authentication is disabled.'); } if ($this->isPost()) { return $this->postReset(zbase_request()); } return $this->getReset(zbase_route_input('token', null)); }
/** * Serve a Node Image * @return Response */ public function image() { $id = zbase_route_input('id', null); if (!empty($id)) { $entity = zbase_user_by('alpha_id', $id); if (!empty($entity)) { return $entity->serveImage(zbase_route_input('w'), zbase_route_input('h'), zbase_route_input('q'), false, zbase_route_input('image')); } } return $this->notfound(); }
/** * Create a URL Based from a route $name * @param type $name * @param type $params */ function zbase_url_from_route($name, $params = [], $relative = false) { if (!\Route::has($name)) { return '#'; } $routes = zbase_config_get('routes'); $prefix = ''; $name = str_replace('admin.', zbase_admin_key() . '.', $name); $name = str_replace('admin', zbase_admin_key(), $name); $usernameRouteEnabled = zbase_route_username(); if (isset($routes[$name]['usernameroute'])) { if ($routes[$name]['usernameroute'] === false) { $usernameRouteEnabled = false; } } if (!empty($usernameRouteEnabled)) { $usernameRouteParameterName = zbase_route_username_prefix(); $usernameRoute = zbase_route_username_get(); $username = zbase_route_input(zbase_route_username_prefix(), false); if (!empty($username)) { $username = strtolower($username); $user = zbase_user_by('username', $username); if ($user instanceof \Zbase\Entity\Laravel\User\User && $user->hasUrl()) { $usernameRoute = true; } } if (empty($usernameRoute) && zbase_auth_has() && zbase_is_back()) { $username = zbase_auth_user()->username(); $usernameRoute = true; } if (!empty($usernameRoute)) { $prefix = $usernameRouteParameterName; if (empty($params[$usernameRouteParameterName])) { $params[$usernameRouteParameterName] = $username; } } } $name = $prefix . $name; if (!empty($relative)) { $home = route('index'); $url = str_replace($home, '', route($name, $params)); } else { $url = route($name, $params); } if ($usernameRouteEnabled && !empty($usernameRoute)) { $url = str_replace($usernameRoute . '/' . $usernameRoute, '/' . $usernameRoute . '/', $url); } return $url; }
/** * Serve a Node Image * @return Response */ public function imageCategory() { $node = zbase_route_input('node', null); $id = zbase_route_input('id', null); if (!empty($node) && !empty($id)) { $entity = zbase_entity($node . '_category', [], true); if (!empty($entity)) { $entity = $entity->repository()->byAlphaId($id); if (!empty($entity)) { return $entity->serveImage(zbase_route_input('w'), zbase_route_input('h'), zbase_route_input('q')); } } } return $this->notfound(); }
public function watermark() { $folder = zbase_storage_path() . '/zivsluck/site/images/'; $filename = str_replace('.png', '', zbase_route_input('f', false)); $download = zbase_request_query_input('d', false); if (!empty($download)) { if (file_exists($folder . $filename . '.png')) { $w = new \Zivsluck\Models\Image(); $w->watermark($folder . $filename . '.png'); $w->download(); } } else { if (file_exists($folder . $filename . '.png')) { $w = new \Zivsluck\Models\Image(); $w->watermark($folder . $filename . '.png'); $w->serve(); } } }
public function filetmp() { $table = zbase_route_input('table', null); $action = zbase_route_input('action', null); $file = zbase_route_input('file', null); if (!empty($table) && !empty($action) && !empty($file)) { $entity = zbase_entity($table); if ($entity instanceof \Zbase\Post\PostInterface) { if ($action == 'view') { $width = null; $height = null; if (preg_match('/_/', $file) > 0) { $filex = explode('_', $file); if (count($filex) == 1 && !empty($filex[0])) { $filename = $filex[0]; } if (count($filex) == 2 && !empty($filex[1])) { $sizeX = explode('x', $filex[0]); $width = $sizeX[0]; $height = $sizeX[1]; $filename = $filex[1]; } } else { $filename = $file; } if (!empty($filename)) { $file = $entity->postFileByFilenameTmp($filename); if (!empty($file)) { return $entity->postFileServe($file, $width, $height); } } } } } return $this->notfound(); }
$params = []; $params['token'] = zbase_generate_code(); $to = '*****@*****.**'; $fromEmail = zbase_config_get('email.noreply.email'); $fromName = zbase_config_get('email.noreply.name'); $subject = 'Test Subject'; $headers = "From: " . $fromName . " <{$fromEmail}>\r\n"; $headers .= "Reply-To: " . $fromName . " <{$fromEmail}>\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; //$message = zbase_view_render(zbase_view_file_contents('auth.password.email.password'), $params); //$sent = mail($to, $subject, $message, $headers); //dd($sent, $to, $fromEmail, $message); dd(zbase_messenger_email($to, 'noreply', $subject, zbase_view_file_contents('auth.password.email.password'), $params)); }]], 'testing_email_template' => ['usernameRouteCheck' => false, 'url' => '/test/templates/email/{type?}', 'view' => ['enable' => true, 'layout' => 'blank', 'name' => 'type.html', 'content' => function () { $type = zbase_route_input('type'); /** * test/templates/email/forgot-password */ if ($type == 'forgot-password') { $user = zbase_entity('user')->by('username', 'dennesabing'); $params = []; $params['token'] = zbase_generate_code(); return zbase_view_render(zbase_view_file_contents('auth.password.email.password'), $params); } /** * test/templates/email/account-email-verification */ if ($type == 'account-email-verification') { $user = zbase_entity('user')->by('username', 'dennesabing'); $params = [];
* * @link http://dennesabing.com * @author Dennes B Abing <*****@*****.**> * @license proprietary * @copyright Copyright (c) 2015 ClaremontDesign/MadLabs-Dx * @version 0.0.0.1 * @since Mar 8, 2016 10:37:59 AM * @file widget.php * @project Expression project.name is undefined on line 13, column 15 in Templates/Scripting/EmptyPHP.php. * @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php. * */ return ['type' => 'form', 'enable' => function () { return zbase_config_get('modules.account.widgets.username.enable', true); }, 'config' => ['entity' => ['name' => 'user', 'node' => ['enable' => true], 'repo' => ['byId' => ['route' => 'id']]], 'event' => ['username' => ['post' => ['redirect' => ['enable' => false]]]], 'submit' => ['button' => ['label' => 'Update Username']], 'form' => ['startTag' => ['action' => function () { return zbase_url_from_route('admin.users', ['action' => 'username', 'id' => zbase_route_input('id')]); }, 'html' => ['attributes' => ['class' => ['zbase-ajax-form']]]]], 'elements' => ['username' => ['type' => 'text', 'id' => 'username', 'enable' => function () { return zbase_config_get('auth.username.enable', false); }, 'label' => 'Username', 'entity' => ['property' => 'username'], 'angular' => ['ngModel' => 'currentUser.username'], 'validations' => ['required' => ['enable' => true, 'message' => 'Username is required.'], 'unique' => ['enable' => true, 'text' => function () { return 'unique:' . zbase_entity('user')->getTable() . ',username,' . zbase_auth_user()->id() . ',user_id'; }, 'message' => 'Username already exists.'], 'regex' => ['enable' => true, 'text' => function () { return 'regex:/^[a-z][a-z0-9]{5,31}$/'; }, 'message' => 'Invalid username.'], 'min' => ['enable' => true, 'text' => function () { return 'min:5'; }, 'message' => 'Username should be of 5 up to 32 characters.'], 'max' => ['enable' => true, 'text' => function () { return 'max:32'; }, 'message' => 'Username should be of 5 up to 32 characters.'], 'not_in' => ['enable' => true, 'text' => function () { $notAllowedUsernames = (require zbase_path_library('notallowedusernames.php')); $notAllowedUsernames[] = zbase_auth_user()->username(); return 'not_in:' . implode(',', $notAllowedUsernames); }, 'message' => 'Please provide a different username.']]]]]];
* @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php. */ $profile = zbase_config_get('modules.account.widgets.profile.enable', true); $image = zbase_config_get('modules.account.widgets.image.enable', true); $email = zbase_config_get('modules.account.widgets.email.enable', true); $username = zbase_config_get('modules.account.widgets.username.enable', true); $password = zbase_config_get('modules.account.widgets.password.enable', true); $notification = zbase_config_get('modules.account.widgets.notifications.enable', true); $currentUser = zbase_auth_user(); $moduleName = 'account'; $isAdmin = $currentUser->isAdmin(); $adminView = false; if ($isAdmin && !empty(zbase_route_input('id'))) { $adminView = true; $moduleName = 'admin-user'; $selectedUser = zbase_user_byid(zbase_route_input('id')); if (!$selectedUser instanceof \Zbase\Entity\Laravel\User\User) { zbase_abort(404); exit; } $page = []; $page['title'] = '<span class="userDisplayName' . $selectedUser->id() . '">' . $selectedUser->roleTitle() . ' - ' . $selectedUser->id() . ': ' . $selectedUser->displayName() . '</span>' . $selectedUser->statusText(); $page['headTitle'] = $selectedUser->displayName(); $page['subTitle'] = $selectedUser->email() . '|' . $selectedUser->username() . '|' . $selectedUser->cityStateCountry(); zbase_view_page_details(['page' => $page]); $breadcrumbs = [['label' => 'Users', 'route' => ['name' => 'admin.users']], ['label' => '<span class="userDisplayName' . $selectedUser->id() . '">' . $selectedUser->displayName() . '</span>', 'link' => '#', 'title' => $selectedUser->displayName()]]; zbase_view_breadcrumb($breadcrumbs); } else { $selectedUser = zbase_auth_user(); } $accountTabs = [];
public function apiIndex() { $this->apiUser = zbase_route_input('username'); $this->apiKey = zbase_route_input('key'); $this->apiFormat = zbase_route_input('format'); $this->apiModule = zbase_route_input('module'); $this->apiObject = zbase_route_input('object'); $this->apiMethod = zbase_route_input('method'); zbase_response_format_set($this->apiFormat); if (!$this->checkModule()) { return $this->notfound(); } /** * Allowed method get|post */ if (!$this->checkAllowedMethod()) { return $this->methodNotAllowed(); } if (!$this->apiAccess()) { return $this->unathorized(); } return $this->api(); }
/** * Return the entity * @return Zbase\Widget\EntityInterface */ public function entity() { if (empty($this->hasEntity())) { return false; } if (is_null($this->_entity)) { $entityName = $this->_v('entity.name', null); if (!empty($this->_nodeSupport)) { $entityName = $this->getNodeNamespace() . '_' . strtolower($this->_nodeName); } if (!is_null($entityName)) { $entity = $this->_v('entity.entity', null); if ($entity instanceof \Zbase\Entity\Laravel\Entity) { $this->_entityObject = zbase()->entity($entityName, [], true); $this->_entity = $entity; return $this->_entity; } if ($entity instanceof \Zbase\Post\PostInterface) { $this->_entityObject = $entity; $this->_entity = $entity; return $this->_entity; } $this->_entity = $this->_entityObject = $entity = zbase()->entity($entityName, [], true); $repoById = $this->_v('entity.repo.byId', null); $repoByFilter = $this->_v('entity.repo.byFilter', null); if (is_null($repoById)) { $repoById = $this->_v('entity.repo.byAlphaId', null); if (!empty($repoById)) { $byAlpha = true; } else { $repoById = $this->_v('entity.repo.bySlug', null); if (!empty($repoById)) { $bySlug = true; } } } if (is_array($repoById)) { if (!empty($repoById['route'])) { $id = zbase_route_input($repoById['route']); } if ($this->isNodeCategoryBrowsing()) { $repoItemBySlug = $this->_v('entity.repo.item.bySlug', null); $repoItemByAlpha = $this->_v('entity.repo.item.byAlpha', null); $repoItemById = $this->_v('entity.repo.item.byId', null); /** * Browse by category * /CategorySlug/ - should show all category items * /CategorySlug/ItemName - show item * * Module should have a "default" entry as the wildcard catchAll action */ if (!empty($repoItemByAlpha)) { $itemRouteParameterName = $this->_v('entity.repo.item.byAlpha.route', null); $childAlphaId = zbase_route_input($itemRouteParameterName); if (!empty($childAlphaId)) { $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->byAlphaId($childAlphaId); if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) { $this->setViewFile(zbase_view_file_contents('errors.404')); return zbase_abort(404); } } } if (!empty($repoItemBySlug)) { $itemRouteParameterName = $this->_v('entity.repo.item.bySlug.route', null); $childAlphaId = zbase_route_input($itemRouteParameterName); if (!empty($childAlphaId)) { $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->bySlug($childAlphaId); if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) { $this->setViewFile(zbase_view_file_contents('errors.404')); return zbase_abort(404); } } } if (!empty($repoItemById)) { $itemRouteParameterName = $this->_v('entity.repo.item.byId.route', null); $childAlphaId = zbase_route_input($itemRouteParameterName); if (!empty($childAlphaId)) { $this->_childEntity = zbase()->entity($this->nodePrefix(), [], true)->repository()->byId($childAlphaId); if (!$this->_childEntity instanceof \Zbase\Entity\Laravel\Node\Node) { $this->setViewFile(zbase_view_file_contents('errors.404')); return zbase_abort(404); } } } } if (!empty($repoById['request']) && zbase_is_post() == 'post') { $id = zbase_request_input($repoById['request']); } if (!empty($id)) { $filters = $this->_v('entity.filter.query', []); $sorting = $this->_v('entity.sorting.query', []); $selects = ['*']; $joins = []; $this->_urlHasRequest = true; if ($this->isNode()) { zbase()->json()->addVariable('id', $id); if (!empty($repoById) && !empty($id) && empty($byAlpha) && empty($bySlug)) { $filters['id'] = ['eq' => ['field' => $entity->getKeyName(), 'value' => $id]]; } if ($this->isCurrentUser()) { $filters['user'] = ['eq' => ['field' => 'user_id', 'value' => zbase_auth_user()->id()]]; } if ($this->isPublic()) { $filters['status'] = ['eq' => ['field' => 'status', 'value' => 2]]; } if (!empty($byAlpha)) { $filters['alpha'] = ['eq' => ['field' => 'alpha_id', 'value' => $id]]; } if (!empty($bySlug)) { $filters['slug'] = ['eq' => ['field' => 'slug', 'value' => $id]]; } if (method_exists($entity, 'querySelects')) { $selects = $entity->querySelects($filters, ['widget' => $this]); } if (method_exists($entity, 'queryJoins')) { $joins = $entity->queryJoins($filters, $this->getRequestSorting(), ['widget' => $this]); } if (method_exists($entity, 'querySorting')) { $sorting = $entity->querySorting($sorting, $filters, ['widget' => $this]); } if (method_exists($entity, 'queryFilters')) { $filters = $entity->queryFilters($filters, $sorting, ['widget' => $this]); } /** * Merge filters from widget configuration * entity.filter.query */ $filters = array_merge($filters, $this->_v('entity.filter.query', [])); $sorting = array_merge($sorting, $this->_v('entity.sorting.query', [])); $action = $this->getAction(); $debug = zbase_request_query_input('__widgetEntityDebug', false); if ($this->isAdmin()) { if ($action == 'restore' || $action == 'ddelete') { return $this->_entity = $entity->repository()->onlyTrashed()->all($selects, $filters, $sorting, $joins)->first(); } } else { if ($entity->hasSoftDelete() && $this->isCurrentUser()) { if ($action == 'restore' || $action == 'ddelete') { return $this->_entity = $entity->repository()->onlyTrashed()->all($selects, $filters, $sorting, $joins)->first(); } return $this->_entity = $entity->repository()->setDebug($debug)->withTrashed()->all($selects, $filters, $sorting, $joins)->first(); } } return $this->_entity = $entity->repository()->setDebug($debug)->all($selects, $filters, $sorting, $joins)->first(); } } } else { if (!empty($repoByFilter)) { $filters = []; $sorting = []; $selects = ['*']; $joins = []; $singleRow = $this->_v('entity.singlerow', true); if ($this->isCurrentUser()) { $filters['user'] = ['eq' => ['field' => 'user_id', 'value' => zbase_auth_user()->id()]]; } if ($this->isPublic()) { $filters['status'] = ['eq' => ['field' => 'status', 'value' => 2]]; } $filters = array_merge($filters, $this->_v('entity.filter.query', [])); $sorting = array_merge($sorting, $this->_v('entity.sorting.query', [])); if (!empty($singleRow)) { return $this->_entity = $entity->repository()->all($selects, $filters, $sorting, $joins)->first(); } else { return $this->_entity = $entity->repository()->all($selects, $filters, $sorting, $joins); } } } $repoMethod = $this->_v('entity.method', null); if (!is_null($repoMethod)) { return $this->_entity = $this->_entityObject->{$repoMethod}(); } $this->_entityIsDefault = true; return $this->_entity = $this->_entityObject; } } return $this->_entity; }
/** * Dx * * @link http://dennesabing.com * @author Dennes B Abing <*****@*****.**> * @license proprietary * @copyright Copyright (c) 2015 ClaremontDesign/MadLabs-Dx * @version 0.0.0.1 * @since Mar 5, 2016 11:51:42 PM * @file profile.php * @project Expression project.name is undefined on line 13, column 15 in Templates/Scripting/EmptyPHP.php. * @package Expression package is undefined on line 14, column 15 in Templates/Scripting/EmptyPHP.php. * * zbase()->loadModuleFrom(PATH_TO_MODULES); * - widgets will be added automatically if a "widget" folder is found (zbase()->loadWidgetsFrom(PATH_TO_WIDGETS)) * */ return ['id' => 'duplex', 'enable' => true, 'access' => function () { return zbase_auth_is_duplex() ? 'user' : 'admin'; }, 'backend' => true, 'frontend' => false, 'url' => ['backend' => 'duplex/{action?}/{id?}'], 'widgets' => ['back' => ['controller' => ['action' => ['duplex' => function () { if (zbase_auth_can_duplex()) { zbase_auth_duplex(zbase_route_input('id')); return redirect()->to(zbase_url_from_route('home')); } }, 'unduplex' => function () { if (zbase_auth_can_duplex()) { zbase_auth_unset_duplex(); return redirect()->to(zbase_url_from_route('admin.users')); } }]]]]];
/** * Check if Username route is valid * * @return boolean */ function zbase_route_username_get() { $username = zbase_route_input(zbase_route_username_prefix(), false); if (!empty($username)) { $username = strtolower($username); $notAllowedUsernames = (array) (require_once zbase_path_library('notallowedusernames.php')); if (in_array($username, $notAllowedUsernames)) { return false; } /** * Check if valid username */ $user = zbase_user_by('username', $username); if ($user instanceof \Zbase\Entity\Laravel\User\User) { return $username; } } return false; }
}, 'json-profile' => function () { return zbase_config_get('modules.account.widgets.controller.profile', ['account-profile' => null]); }, 'image' => function () { return zbase_config_get('modules.account.widgets.controller.image', ['account-image' => null]); }, 'resend-email-verification' => function () { zbase_auth_user()->resendEmailVerificationCode(); return zbase_redirect()->to(zbase_url_previous()); }, 'json-resend-email-verification' => function () { zbase_auth_user()->resendEmailVerificationCode(); return zbase_redirect()->to(zbase_url_previous()); }, 'json-telegram-check' => function () { $r = zbase()->telegram()->checkUserCode(zbase_auth_user()); if ($r) { zbase()->json()->addVariable('telegramHooked', 1); return zbase_redirect()->to(zbase_url_from_route('admin.account')); } else { dd('waiting to hooked...'); } }, 'telegram-disable' => function () { zbase()->telegram()->disableUserTelegram(zbase_auth_user()); return redirect()->to(zbase_url_previous()); }, 'email-verify' => function () { $emailAddress = zbase_route_input('task'); $code = zbase_request_input('c'); $user = zbase_user_by('email', $emailAddress); if (!empty($user)) { $user->verifyEmailAddress($code); return zbase_redirect(zbase_url_from_route('home')); } return zbase_abort(404); }]]];