Giter Club home page Giter Club logo

mojito's Introduction

Mojito

Mojito 是基于 Laravel 开发的 Mojito Admin 的服务端。

3.0 版本开始, 已将原来的项目分离为两个代码库,分别为以Vue3、Element Plus、Vite 开发的前端模板 mojito -admin 和服务端 mojito 。如果是需要使用 vue2 版本,请访问 2.0 分支。

Mojito Admin 截图

mojito.png

特性

  • 前后端分离,提供 Mojito Admin 前端模板
  • 基于 laravel-permission 权限管理
  • 基于 sanctum 鉴权
  • 提供角色,权限,用户,菜单管理等功能的API
  • 多个后台支持统一管理权限,菜单和角色
  • 完善的PHPUnit测试

要求

  • Laravel >= 7.0.0
  • PHP >= 7.2.0

安装

首先安装laravel,并且确保你配置了正确的数据库连接。

composer require moell/mojito

然后运行下面的命令来发布资源:

php artisan mojito:install

命令执行成功会生成配置文件,数据迁移和构建SPA的文件。

修改 app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $routeMiddleware = [
        ...
        'mojito.permission' => \Moell\Mojito\Http\Middleware\Authenticate::class,
    ];

    protected $middlewareGroups = [
            ...
            'api' => [
                ...
                \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            ],
        ];
}

执行数据迁移,数据填充

php artisan migrate

php artisan db:seed --class="Moell\Mojito\Database\MojitoTableSeeder"

后台登录的账号 admin , 密码 secret

路由中间件

  • auth:sanctum 用于鉴权
  • mojito.permission 权限验证

mojito.php 可选配置

return [
    'guards' => [
        // laravel-permission 相对应的 guard
        'admin' => [
            'model' => \Moell\Mojito\Models\AdminUser::class, //登录鉴权的模型
            'login_fields' => [	// 登录验证的字段,支持多个
                'username',
            ],
            'conditions' => [ // 登录验证的额外条件
                ['status', '=', 1]
            ]
        ]
    ],
    'route_prefix' => "api", //路由前缀
    
    'middleware' => [
        'basic' => 'api', //基础中间件

        'auth' => ['auth:sanctum'], //鉴权中间件

        'permission' => ['auth:sanctum', 'mojito.permission'] //包含权限检测的中间件
    ]
];

依赖扩展包

  • spatie/laravel-permission
  • laravel/sanctum

常见错误

  • csrf token missing or incorrect , 请修改 sanctum.php 中的 stateful , 如 vite 使用的 localhost:3000 去除即可。更多详细请访问laravel/sanctum文档。

打赏

License

Apache License Version 2.0 see http://www.apache.org/licenses/LICENSE-2.0.html

mojito's People

Contributors

eddiclin avatar moell-peng avatar samnela avatar sy-dante avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mojito's Issues

CSRF token mismatch.

\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,这个有什么用,增加了这个,登录报错,移除才能登录

{message: "CSRF token mismatch.", exception: "Symfony\Component\HttpKernel\Exception\HttpException",…} exception: "Symfony\Component\HttpKernel\Exception\HttpException" file: "/Users/admin/code/laravel8/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php" line: 369

如何分配角色?

用户分配角色
user-assign-role 组件实现了用户的角色分配,只需要你再 admin 后台传递必要的参数调用即可实现分配。
这个角色如何增加?我加了一个member的角色,但是登录后显示POST http://leader2.test/oauth/token 401 (Unauthorized)

权限分配

目前的权限分配是只能做到菜单,没有做到用户吗?

后台用户无法被禁用

因为代码中使用 request_intersect 过滤请求参数,导致禁用用户时的 status: false 请求参数被过滤掉了

    public function update(CreateOrUpdateRequest $request, $id)
    {
        $adminUser = $this->adminUserModel->findOrFail($id);

        // 此处过滤了 status 等于 false 的情况,导致无法禁用用户
        $data = request_intersect([
            'name', 'status'
        ]);

        if ($request->filled('password')) {
            $data['password'] = bcrypt($request->password);
        }

        $adminUser->fill($data);
        $adminUser->save();

        return $this->noContent();
    }

request_intersect 使用的 array_filter,而 array_filter 会过滤所有等值为 false 的参数

我建议在此处直接使用 $request->only 就好

最新版数据库迁移报错

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table users add unique users_email_unique(email))

安装时,执行编译报错

laravel version: v8.35.1
mojito version: v2.0.1
环境: windows 10,node 运行在宿主机上,版本 v14.16.0

➜  mojito (master) npm run watch

> @ watch E:\dnmp\www\mojito
> mix watch


× Mix
  Compiled with some errors in 2.72s

ERROR in ./resources/js/router/routers.js 13:0-46
Module not found: Error: Can't resolve '../views/admin/main/index' in 'E:\dnmp\www\mojito\resources\js\router'

ERROR in ./resources/js/views/admin/role/routes.js 1:0-67
Module not found: Error: Can't resolve '../../../components/ParentView/ParentView' in 'E:\dnmp\www\mojito\resources\js\views\admin\role'

ERROR in ./resources/js/Admin.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div id="app">
|     <router-view/>

ERROR in ./resources/js/views/admin/dashboard/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <h1>Hello! Mojito Admin</h1>

ERROR in ./resources/js/views/admin/login/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div id="login">
|     <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="login-container">

ERROR in ./resources/js/views/admin/menu/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <el-form :inline="true" :model="queryParams"  size="mini">

ERROR in ./resources/js/views/admin/permission-group/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <el-form :inline="true" :model="queryParams"  size="mini">

ERROR in ./resources/js/views/admin/permission/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <el-form :inline="true" :model="queryParams"  size="mini">

ERROR in ./resources/js/views/admin/role/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <el-form :inline="true" :model="queryParams"  size="mini">

ERROR in ./resources/js/views/admin/role/permission.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div v-loading="loading">
|     <el-card v-for="group in guardNameByPermissions" :key="group.id" style="margin-bottom:20px;">

ERROR in ./resources/js/views/admin/user/index.vue 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <template>
|   <div>
|     <el-form :inline="true" :model="queryParams"  size="mini">

webpack compiled with 11 errors

laravel5.7安装后登陆就报错

首先“将 admin.js 添加到 webpack.mix.js”,格式不对,按照注释掉的“ //.js('resources/js/admin.js', 'public/js') laravel5.7+”添加后,启动运行,登陆时报错:

admin.js:12489 Uncaught (in promise) TypeError: Cannot read property 'data' of undefined
at admin.js:12489
(anonymous) @ admin.js:12489
Promise.then (async)
(anonymous) @ 6.js:147
(anonymous) @ admin.js:35647
(anonymous) @ admin.js:35968
complete @ admin.js:60579
(anonymous) @ admin.js:60715
next @ admin.js:621
next @ admin.js:589
cb @ admin.js:60663
required @ admin.js:62321
(anonymous) @ admin.js:60706
next @ admin.js:587
asyncSerialArray @ admin.js:593
(anonymous) @ admin.js:627
asyncMap @ admin.js:624
validate @ admin.js:60631
validate @ admin.js:35964
(anonymous) @ admin.js:35641
validate @ admin.js:35640
submitForm @ 6.js:143
click @ 6.js:234
invoker @ admin.js:2694
Vue.$emit @ admin.js:3205
handleClick @ admin.js:25560
invoker @ admin.js:2694
fn._withTask.fn._withTask @ admin.js:2493

无法使用运转,白白浪费功夫,真是无奈,这个想法解决吧。

Sample laravel model, controller, api, crud operator

Hello,

First of all thanks a lot for your awesome package. Would you please create a sample SCRUD using Laravel model, controller like SCRUD for example, employee or todo?

I am not sure how are you accessing the API using postman or insomnia? Where are you getting your laravel backend API? I've found the js/api directory where you have the endpoints. But are you generating those endpoints from the Spatie package?

Thanks

php artisan db:seed --class="Moell\Mojito\Database\MojitoTableSeeder"

at /Users/zhangfan/project/php/laravel58/vendor/moell/mojito/src/Database/MojitoTableSeeder.php:215
211| * @author moell[email protected]
212| */
213| private function createdAdminUser()
214| {

215| AdminUserFactory::adminUser()->truncate();
216|
217| AdminUserFactory::adminUser()->create([
218| 'name' => 'admin',
219| 'email' => '[email protected]',

Exception trace:

1 Moell\Mojito\Database\MojitoTableSeeder::createdAdminUser()
/Users/zhangfan/project/php/laravel58/vendor/moell/mojito/src/Database/MojitoTableSeeder.php:197

2 Moell\Mojito\Database\MojitoTableSeeder::run()
/Users/zhangfan/project/php/laravel58/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32

Please use the argument -v to see more details.

访问是空白的

全部安装成功,没有报告错误。
放在web目录下,路由设置访问 dashboard,但是是空白的。

安装后登录失败

php artisan passport:install
Encryption keys generated successfully.
Personal access client created successfully.
Client ID: 1
Client secret: ZfkFZ9Q2MKoHPCPNNVaqkwImFc4ma07abClKX4b9
Password grant client created successfully.
Client ID: 2
Client secret: 5gYmgJnvGYDuk56GzZ9UwlWrRWdK9utJMCy2e5bB

cat resources/config/index.js
export default {
admin: {
authorize: {
clientId: 1,
clientSecret: ZfkFZ9Q2MKoHPCPNNVaqkwImFc4ma07abClKX4b9
}
}

登录时, 输入用户名 [email protected] 密码 ZfkFZ9Q2MKoHPCPNNVaqkwImFc4ma07abClKX4b9 返回401
{"error":"invalid_client","message":"Client authentication failed"}

about the icon

i'd like to know which icon library dose the project use.Ali's icon library is very big.i can't find it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.