本文整理汇总了PHP中Pagekit\Application::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::user方法的具体用法?PHP Application::user怎么用?PHP Application::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagekit\Application
的用法示例。
在下文中一共展示了Application::user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getNext
/**
* @param File $file
* @return mixed
*/
public static function getNext($file)
{
$module = App::module('bixie/download');
return self::where(['title < ?', 'status = ?'], [$file->title, '1'])->where(function ($query) {
return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR');
})->orderBy($module->config('ordering'), $module->config('ordering_dir'))->first();
}
示例2: uploadAction
/**
* @param FieldValueBase $fieldValue
* @return array
*/
public function uploadAction(FieldValueBase $fieldValue)
{
try {
if (!($path = $this->getPath($fieldValue->field->get('path')))) {
return $this->error(__('Invalid path.'));
}
if (!is_dir($path) || !App::user()->hasAccess('system: manage storage | bixframework: upload files')) {
return $this->error(__('Permission denied.'));
}
$fileInfo = [];
$files = App::request()->files->get('files');
if (!$files) {
return $this->error(__('No files uploaded.'));
}
/** @var UploadedFile $file */
foreach ($files as $file) {
if (!$file->isValid()) {
return $this->error(sprintf(__('Uploaded file invalid. (%s)'), $file->getErrorMessage()));
}
if (!($ext = $file->guessExtension()) or !in_array($ext, $fieldValue->field->get('allowed', []))) {
return $this->error(__('File extension not allowed.'));
}
if (!($size = $file->getClientSize()) or $size > $fieldValue->field->get('max_size', 0) * 1024 * 1024) {
return $this->error(__('File is too large.'));
}
//give file unique name
$localFile = $file->move($path, sprintf('%d%d-%s', microtime(true) * 10000, rand(), preg_replace("/[^a-zA-Z0-9\\.]/", "-", $file->getClientOriginalName())));
$fileInfo[] = ['name' => $file->getClientOriginalName(), 'size' => $localFile->getSize(), 'path' => str_replace(App::path(), '', $localFile->getPathname()), 'url' => ltrim(App::url()->getStatic($localFile->getPathname(), [], 'base'), '/')];
}
return ['message' => __('Upload complete.'), 'files' => $fileInfo];
} catch (\Exception $e) {
return $this->error(__('Unable to upload.'));
}
}
示例3: requestAction
/**
* @Request({"email": "string"})
*/
public function requestAction($email)
{
try {
if (App::user()->isAuthenticated()) {
return App::redirect();
}
if (!App::csrf()->validate()) {
throw new Exception(__('Invalid token. Please try again.'));
}
if (empty($email)) {
throw new Exception(__('Enter a valid email address.'));
}
if (!($user = User::findByEmail($email))) {
throw new Exception(__('Unknown email address.'));
}
if ($user->isBlocked()) {
throw new Exception(__('Your account has not been activated or is blocked.'));
}
$user->activation = App::get('auth.random')->generateString(32);
$url = App::url('@user/resetpassword/confirm', ['user' => $user->username, 'key' => $user->activation], 0);
try {
$mail = App::mailer()->create();
$mail->setTo($user->email)->setSubject(__('Reset password for %site%.', ['%site%' => App::module('system/site')->config('title')]))->setBody(App::view('system/user:mails/reset.php', compact('user', 'url', 'mail')), 'text/html')->send();
} catch (\Exception $e) {
throw new Exception(__('Unable to send confirmation link.'));
}
$user->save();
return ['message' => __('Check your email for the confirmation link.')];
} catch (Exception $e) {
App::abort(400, $e->getMessage());
}
}
示例4: saveAction
/**
* @Request({"user": "array"}, csrf=true)
*/
public function saveAction($data)
{
$user = App::user();
if (!$user->isAuthenticated()) {
App::abort(404);
}
try {
$user = User::find($user->id);
if ($password = @$data['password_new']) {
if (!App::auth()->getUserProvider()->validateCredentials($user, ['password' => @$data['password_old']])) {
throw new Exception(__('Invalid Password.'));
}
if (trim($password) != $password || strlen($password) < 3) {
throw new Exception(__('Invalid Password.'));
}
$user->password = App::get('auth.password')->hash($password);
}
if (@$data['email'] != $user->email) {
$user->set('verified', false);
}
$user->name = @$data['name'];
$user->email = @$data['email'];
$user->validate();
$user->save();
return ['message' => 'success'];
} catch (Exception $e) {
App::abort(400, $e->getMessage());
}
}
示例5: indexAction
/**
* @Route("/", methods="GET")
* @Request({"filter": "array", "post":"int", "page":"int", "limit":"int"})
*/
public function indexAction($filter = [], $post = 0, $page = 0, $limit = 0)
{
$query = Comment::query();
$filter = array_merge(array_fill_keys(['status', 'search', 'order'], ''), $filter);
extract($filter, EXTR_SKIP);
if ($post) {
$query->where(['post_id = ?'], [$post]);
} elseif (!$this->user->hasAccess('blog: manage comments')) {
App::abort(403, __('Insufficient user rights.'));
}
if (!$this->user->hasAccess('blog: manage comments')) {
$query->where(['status = ?'], [Comment::STATUS_APPROVED]);
if ($this->user->isAuthenticated()) {
$query->orWhere(function ($query) {
$query->where(['status = ?', 'user_id = ?'], [Comment::STATUS_PENDING, App::user()->id]);
});
}
} elseif (is_numeric($status)) {
$query->where(['status = ?'], [(int) $status]);
} else {
$query->where(function ($query) {
$query->orWhere(['status = ?', 'status = ?'], [Comment::STATUS_APPROVED, Comment::STATUS_PENDING]);
});
}
if ($search) {
$query->where(function ($query) use($search) {
$query->orWhere(['author LIKE ?', 'email LIKE ?', 'url LIKE ?', 'ip LIKE ?', 'content LIKE ?'], array_fill(0, 5, "%{$search}%"));
});
}
$count = $query->count();
$pages = ceil($count / ($limit ?: PHP_INT_MAX));
$page = max(0, min($pages - 1, $page));
if ($limit) {
$query->offset($page * $limit)->limit($limit);
}
if (preg_match('/^(created)\\s(asc|desc)$/i', $order, $match)) {
$order = $match;
} else {
$order = [1 => 'created', 2 => App::module('blog')->config('comments.order')];
}
$comments = $query->related(['post' => function ($query) {
return $query->related('comments');
}])->related('user')->orderBy($order[1], $order[2])->get();
$posts = [];
foreach ($comments as $i => $comment) {
$p = $comment->post;
if ($post && (!$p || !$p->hasAccess($this->user) || !($p->isPublished() || $this->user->hasAccess('blog: manage comments')))) {
App::abort(403, __('Post not found.'));
}
$comment->content = App::content()->applyPlugins($comment->content, ['comment' => true]);
$posts[$p->id] = $p;
$comment->special = count(array_diff($comment->user ? $comment->user->roles : [], [0, 1, 2]));
$comment->post = null;
$comment->user = null;
}
$comments = array_values($comments);
$posts = array_values($posts);
return compact('comments', 'posts', 'pages', 'count');
}
示例6: jsonSerialize
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
$form = $this->toArray();
if (is_array($form['data']) && !App::user()->isAdministrator()) {
unset($form['data']['submitEmail']);
}
return $form;
}
示例7: loginAction
/**
* @Route(defaults={"_maintenance"=true})
* @Request({"redirect"})
*/
public function loginAction($redirect = '')
{
if (App::user()->isAuthenticated()) {
App::message()->info(__('You are already logged in.'));
return App::redirect();
}
return ['$view' => ['title' => __('Login'), 'name' => 'system/user/login.php'], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => $redirect];
}
示例8: load
/**
* @param User|null $user
* @return ProfileUser
*/
public static function load(User $user = null)
{
$user = $user ?: App::user();
$class = get_called_class();
if (!isset(self::$instances[$user->id]) || !self::$instances[$user->id] instanceof $class) {
self::$instances[$user->id] = new $class($user);
}
return self::$instances[$user->id];
}
示例9: registrationAction
/**
* registration override page
* @Route("/registration")
*/
public function registrationAction()
{
$user = App::user();
$userprofile = App::module('bixie/userprofile');
if ($user->isAuthenticated()) {
return App::redirect('@userprofile');
}
return ['$view' => ['title' => __('User registration'), 'name' => 'bixie/userprofile/registration.php'], '$data' => ['config' => $userprofile->config(), 'user' => ['id' => null, 'username' => '', 'name' => '', 'email' => '']]];
}
示例10: deleteAction
/**
* @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
* @Request({"id": "int"}, csrf=true)
*/
public function deleteAction($id)
{
if ($project = Project::find($id)) {
if (!App::user()->hasAccess('portfolio: manage portfolio')) {
return ['error' => __('Access denied.')];
}
$project->delete();
}
return ['message' => 'success'];
}
示例11: deleteAction
/**
* @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
* @Request({"id": "int"}, csrf=true)
*/
public function deleteAction($id)
{
if ($project = File::find($id)) {
if (!App::user()->hasAccess('download: manage downloads')) {
return ['error' => __('Access denied.')];
}
$project->delete();
}
return ['message' => 'success'];
}
示例12: adminMenuAction
/**
* @Access(admin=true)
* @Request({"order": "array"})
*/
public function adminMenuAction($order)
{
if (!$order) {
App::abort(400, __('Missing order data.'));
}
$user = User::find(App::user()->id);
$user->set('admin.menu', $order);
$user->save();
return ['message' => __('Order saved.')];
}
示例13: loginAction
/**
* @Route(defaults={"_maintenance"=true})
* @Request({"redirect"})
*/
public function loginAction($redirect = '')
{
if (!$redirect) {
$redirect = App::url(App::config('system/user')['login_redirect']);
}
if (App::user()->isAuthenticated()) {
return App::redirect($redirect);
}
return ['$view' => ['title' => __('Login'), 'name' => 'system/user/login.php'], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => $redirect];
}
示例14: loginAction
/**
* @Route(defaults={"_maintenance"=true})
* @Request({"redirect"})
*/
public function loginAction($redirect = '')
{
if (App::user()->isAuthenticated()) {
$module = App::module('system/user');
$url = App::url($module->config['login_redirect']);
return App::redirect($url);
}
return self::loginView(['last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => $redirect]);
return ['$view' => ['title' => __('Login'), 'name' => 'system/user/login.php'], 'last_username' => App::session()->get(Auth::LAST_USERNAME), 'redirect' => $redirect];
}
示例15: indexAction
public function indexAction($id = 0)
{
if (!($page = Page::find($id))) {
App::abort(404, __('Page not found.'));
}
if (!App::node()->hasAccess(App::user())) {
App::abort(403, __('Insufficient User Rights.'));
}
$page->content = App::content()->applyPlugins($page->content, ['page' => $page, 'markdown' => $page->get('markdown')]);
return ['$view' => ['title' => $page->title, 'name' => 'system/site/page.php'], 'page' => $page, 'node' => App::node()];
}