/** * 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; }
/** * Return a site Admin * * @return User */ public function postAdmin() { if (method_exists($this, 'admin')) { $user = $this->admin(); if (!$user instanceof User) { return $user; } throw new \Zbase\Exceptions\ConfigNotFoundException('Given admin is not a User. ' . __CLASS__); } if (property_exists($this, 'adminUserId')) { if (!empty($this->adminUserId)) { $user = zbase_user_byid($this->adminUserId); if (!$user instanceof User) { return $user; } throw new \Zbase\Exceptions\ConfigNotFoundException('Given adminUserId is not a User. ' . __CLASS__); } } if (property_exists($this, 'adminUsername')) { if (!empty($this->adminUsername)) { $user = zbase_user_by('username', $this->adminUsername); if (!$user instanceof User) { return $user; } throw new \Zbase\Exceptions\ConfigNotFoundException('Given adminUsername is not a User. ' . __CLASS__); } } $admin = zbase_config_get($this->postModuleName() . '.admin.username', zbase_config_get($this->postModuleName() . '.admin.userid', false)); if (!empty($admin) && is_numeric($admin)) { $user = zbase_user_byid($admin); if (!$user instanceof User) { return $user; } throw new \Zbase\Exceptions\ConfigNotFoundException('Given admin via config by admin.userid is not a User. ' . __CLASS__); } if (!empty($admin)) { $user = zbase_user_by('username', $admin); if (!$user instanceof User) { return $user; } throw new \Zbase\Exceptions\ConfigNotFoundException('Given admin via config by admin.username is not a User. ' . __CLASS__); } /** * All else, return the default admin */ return zbase_user_by('username', 'adminx'); }
/** * Update email Address Request * Process the link that was sent into the email when * a user wanted to update his email address to a new email address * * routename: update-email-request, expect: email and token * @return */ public function emailUpdateRequestVerify() { $email = $this->getRouteParameter('email', false); $token = $this->getRouteParameter('token', false); if (!empty($email) && !empty($token)) { $user = zbase_user_by('email', $email); if ($user instanceof \Zbase\Entity\Laravel\User\User) { if (zbase_auth_has()) { $updated = $user->checkEmailRequestUpdate($token); if (!empty($updated)) { zbase_session_set('update-email-address', true); return redirect()->to(zbase_url_from_route('home')); } else { zbase_alert('error', 'There was an error updating your email address. Kindly try again.'); } } else { zbase_session_set('__loginRedirect', zbase_url_from_current()); return redirect()->to(zbase_url_from_route('login')); } } } return $this->notfound(); }
/** * 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); }]]];