### Get CAPTCHA Image API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Generates and returns a graphical CAPTCHA image, typically used for security verification during login or registration processes. The `id` parameter can be used to differentiate CAPTCHA instances. ```bash # --- 获取图形验证码 --- curl "http://yourdomain.com/api/common/captcha?id=login_captcha_001" # 返回验证码图片(image/jpeg) ``` -------------------------------- ### App Initialization API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Retrieves application initialization data, including upload configurations, version information, and city data. This endpoint is useful for setting up the client application. ```bash # --- App 初始化(获取上传配置、版本信息、城市数据)--- curl "http://yourdomain.com/api/common/init?version=1.0.0&lng=116.40&lat=39.90" # 响应: # { # "code": 1, "msg": "", # "data": { # "citydata": {"city": "北京市", "district": "东城区"}, # "versiondata": {"url": "", "description": "", "has_new_version": false}, # "uploaddata": {"storage": "local", "cdnurl": "", "uploadurl": "/api/common/upload", "maxsize": 10485760} # } # } ``` -------------------------------- ### Admin Authentication with FastAdmin Auth Class Source: https://context7.com/fastadminnet/fastadmin/llms.txt Demonstrates how to use the Auth class for administrator login, status checks, permission verification, and menu generation. Ensure the Auth class is correctly instantiated. ```php auth) use app\admin\library\Auth; $auth = Auth::instance(); // 1. 管理员登录(keeptime 单位:秒,0 表示不记住) $result = $auth->login('admin', '123456', 3600 * 24); if ($result === true) { echo '登录成功,管理员ID:' . $auth->id; } else { echo '登录失败:' . $auth->getError(); // 输出示例:登录失败:Password is incorrect } // 2. 检测登录状态 if ($auth->isLogin()) { echo '当前管理员:' . $auth->username; } // 3. 权限检测(检查当前管理员是否有访问某路由的权限) if ($auth->check('auth/rule/index')) { echo '有权限'; } else { echo '无权限'; } // 4. 判断是否超级管理员 if ($auth->isSuperAdmin()) { echo '超级管理员,拥有所有权限'; } // 5. 获取当前管理员可管辖的子级管理员 ID 列表(含自身) $childrenAdminIds = $auth->getChildrenAdminIds(true); // 输出:[1, 2, 3] // 6. 获取侧边栏菜单和顶部导航(用于视图渲染) [$menulist, $navlist, $fixedmenu, $referermenu] = $auth->getSidebar([ 'dashboard' => 'hot', // dashboard 菜单显示 badge "hot" 'addon' => [5, 'red', 'badge'], // addon 菜单显示数字 5(红色) ], 'dashboard'); // 7. 获取面包屑导航 $breadcrumb = $auth->getBreadCrumb('auth/admin/index'); // 输出:[['title' => '权限管理', 'url' => '/admin/auth'], ['title' => '管理员', 'url' => '/admin/auth/admin']] // 8. 退出登录 $auth->logout(); ``` -------------------------------- ### User Authentication with Auth Library Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles user registration, login, logout, password changes, and token initialization. Token validity can be configured in the backend. ```php register('testuser', 'Test1234', 'test@example.com', '13800138000', [ 'nickname' => '测试用户', ]); if ($result) { $userinfo = $auth->getUserinfo(); echo '注册成功,Token:' . $auth->getToken(); // 输出:注册成功,Token:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx } else { echo $auth->getError(); // 如:Username already exist } // 2. 用户登录(账号可为用户名/邮箱/手机号) $result = $auth->login('testuser', 'Test1234'); if ($result) { echo '登录成功'; $user = $auth->getUser(); // 返回 User 模型实例 echo $user->nickname; } else { echo $auth->getError(); } // 3. 通过 Token 初始化登录状态(API 接口中使用) $token = $this->request->header('token', $this->request->request('token')); if ($auth->init($token)) { echo '已登录用户:' . $auth->nickname; } else { echo '未登录:' . $auth->getError(); } // 4. 直接通过用户 ID 登录(第三方登录/手机验证码注册后直接登录) $auth->direct($userId); // 5. 修改密码 if ($auth->changepwd('NewPass123', 'Test1234')) { echo '密码修改成功,所有设备已下线'; } else { echo $auth->getError(); // 如:Password is incorrect } // 6. 退出登录(删除 Token) $auth->logout(); ``` -------------------------------- ### User Registration API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Use this endpoint to register new users. Provide username, password, mobile number, and SMS verification code. Authentication is handled via `__token__` or `Authorization` Header for subsequent requests. ```bash # --- 会员注册 --- curl -X POST http://yourdomain.com/api/user/register \ -d "username=testuser&password=Test1234&mobile=13800138000&code=123456" # 响应: # {"code":1,"msg":"Sign up successful","data":{"userinfo":{"id":1,"username":"testuser","nickname":"用户8000","token":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}}} ``` -------------------------------- ### Generate API Documentation with `php think api` Source: https://context7.com/fastadminnet/fastadmin/llms.txt The `php think api` command parses `@ApiXxx` annotations in controllers to generate interactive HTML API documentation with online debugging capabilities. Ensure controller methods have proper annotations for accurate documentation generation. ```bash php think api --module=api ``` ```bash php think api --module=api --output=apidoc.html --title="FastAdmin API文档" ``` ```bash php think api --module=api --url=https://api.example.com ``` ```bash php think api --addon=myaddon ``` ```bash php think api --module=api --force=true ``` ```php /** * 会员登录 * @ApiMethod (POST) * @ApiRoute (/api/user/login) * @ApiParams (name="account", type="string", required=true, description="账号") * @ApiParams (name="password", type="string", required=true, description="密码") * @ApiReturn ({"code":1,"msg":"Logged in successful","data":{"userinfo":{...}}}) * @ApiReturnParams (name="code", type="integer", description="返回码,1成功0失败") */ public function login() { ... } ``` -------------------------------- ### Generate API Documentation with ThinkPHP CLI Source: https://context7.com/fastadminnet/fastadmin/llms.txt Leverage the ThinkPHP CLI to automatically generate API documentation for your project. This is useful for integrating with frontends or mobile apps. ```bash php think api ``` -------------------------------- ### Auth Library - User Registration Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles user registration with username, password, email, phone number, and optional extended fields. Returns true on success or an error message. ```APIDOC ## Auth::register() ### Description Registers a new user with provided credentials and optional extended fields. ### Method ```php Auth::register(string $username, string $password, string $email, string $mobile, array $extend = []) ``` ### Parameters - **username** (string) - Required - The username for the new account. - **password** (string) - Required - The password for the new account. - **email** (string) - Required - The email address for the new account. - **mobile** (string) - Required - The mobile phone number for the new account. - **extend** (array) - Optional - An associative array of additional user fields. ### Return Value - bool - Returns `true` on successful registration, `false` otherwise. ### Error Handling - Use `Auth::getError()` to retrieve the error message if registration fails. ``` -------------------------------- ### Generate Menu Rules with `php think menu` Source: https://context7.com/fastadminnet/fastadmin/llms.txt Use the `php think menu` command to automatically create permission menu nodes in the `auth_rule` table by reflecting controller methods and annotations. This avoids manual menu data maintenance. ```bash php think menu --controller=blog ``` ```bash php think menu --controller=blog --controller=article ``` ```bash php think menu --controller=all-controller ``` ```bash php think menu --controller=blog --delete=true ``` ```bash php think menu --controller=blog --delete=true --force=true ``` ```bash php think menu --controller=blog --equal=true ``` -------------------------------- ### Auth Library - Initialize Login Status via Token Source: https://context7.com/fastadminnet/fastadmin/llms.txt Initializes the login status for API requests by validating a provided token. Useful for maintaining user sessions across API calls. ```APIDOC ## Auth::init() ### Description Initializes the user's login status based on a provided token, typically used in API contexts. ### Method ```php Auth::init(string $token) ``` ### Parameters - **token** (string) - Required - The authentication token to validate. ### Return Value - bool - Returns `true` if the token is valid and the user is logged in, `false` otherwise. ### Usage If successful, user information like `Auth::nickname` can be accessed. ``` -------------------------------- ### Admin Login Process Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles backend administrator login, logout, and framework page rendering. Supports CAPTCHA, CSRF, and auto-login. ```javascript // 前端登录表单 POST 请求示例(JavaScript) $.ajax({ url: '/admin/index/login', type: 'POST', data: { username: 'admin', password: '123456', keeplogin: 1, // 1=记住我(24小时) captcha: '1a2b', // 开启验证码时必填 __token__: $('input[name="__token__"]').val() // CSRF Token(从页面获取) }, success: function(res) { if (res.code == 1) { // 登录成功,跳转 location.href = res.data.url || '/admin/index/index'; } else { // 登录失败,刷新 Token $('input[name="__token__"]').val(res.data.token); layer.msg(res.msg); } } }); // 成功响应示例: // { // "code": 1, // "msg": "Login successful", // "data": { // "url": "/admin/index/index", // "id": 1, // "username": "admin", // "avatar": "/uploads/avatar/admin.jpg" // } // } // 失败响应示例: // { // "code": 0, // "msg": "密码不正确", // "data": { "token": "new-csrf-token-here" } // } ``` -------------------------------- ### Common API Endpoints Source: https://context7.com/fastadminnet/fastadmin/llms.txt Provides utility functions for the application, including initialization settings, file uploads (with chunking support), and CAPTCHA generation. Authentication may be required for some operations. ```APIDOC ## GET /api/common/init ### Description Initializes the application by fetching configuration settings, version information, and city data. ### Method GET ### Endpoint /api/common/init ### Parameters #### Query Parameters - **version** (string) - Optional - The current app version - **lng** (string) - Optional - Longitude for location services - **lat** (string) - Optional - Latitude for location services ### Request Example ```bash curl "http://yourdomain.com/api/common/init?version=1.0.0&lng=116.40&lat=39.90" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (object) - Response data - **citydata** (object) - City and district information - **versiondata** (object) - Version update information - **url** (string) - Update URL - **description** (string) - Update description - **has_new_version** (boolean) - Indicates if a new version is available - **uploaddata** (object) - Upload configuration - **storage** (string) - Storage type (e.g., "local") - **cdnurl** (string) - CDN URL - **uploadurl** (string) - URL for file uploads - **maxsize** (integer) - Maximum allowed file size in bytes ### Response Example ```json { "code": 1, "msg": "", "data": { "citydata": {"city": "北京市", "district": "东城区"}, "versiondata": {"url": "", "description": "", "has_new_version": false}, "uploaddata": {"storage": "local", "cdnurl": "", "uploadurl": "/api/common/upload", "maxsize": 10485760} } } ``` ``` ```APIDOC ## POST /api/common/upload ### Description Handles file uploads, supporting both regular and chunked uploads. Requires authentication for some operations. ### Method POST ### Endpoint /api/common/upload ### Parameters #### Headers - **__token__** (string) - Optional/Required - Authentication token (required for authenticated uploads) #### Request Body (Regular Upload) - **file** (file) - Required - The file to upload #### Request Body (Chunked Upload - Step 1: Upload Chunk) - **file** (file) - Required - The file chunk to upload - **chunkid** (string) - Required - Unique identifier for the chunked upload session - **chunkindex** (integer) - Required - The index of the current chunk (starts from 0) - **chunkcount** (integer) - Required - The total number of chunks - **filename** (string) - Required - The original filename #### Request Body (Chunked Upload - Step 2: Merge Chunks) - **chunkid** (string) - Required - Unique identifier for the chunked upload session - **action** (string) - Required - Set to "merge" to merge chunks - **chunkcount** (integer) - Required - The total number of chunks - **filename** (string) - Required - The original filename ### Request Example (Regular Upload) ```bash curl -X POST http://yourdomain.com/api/common/upload \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "file=@/path/to/image.jpg" ``` ### Request Example (Chunked Upload - Upload Chunk) ```bash curl -X POST http://yourdomain.com/api/common/upload \ -F "file=@chunk0.bin" \ -F "chunkid=unique-chunk-id-001" \ -F "chunkindex=0" \ -F "chunkcount=3" \ -F "filename=bigfile.zip" ``` ### Request Example (Chunked Upload - Merge Chunks) ```bash curl -X POST http://yourdomain.com/api/common/upload \ -d "chunkid=unique-chunk-id-001&action=merge&chunkcount=3&filename=bigfile.zip" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (object) - Response data - **url** (string) - Relative URL of the uploaded file - **fullurl** (string) - Full URL of the uploaded file (for regular uploads) ### Response Example (Regular Upload) ```json {"code":1,"msg":"Uploaded successful","data":{"url":"/uploads/20240101/abc123.jpg","fullurl":"http://yourdomain.com/uploads/20240101/abc123.jpg"}} ``` ### Response Example (Chunked Upload - Merge) ```json {"code":1,"msg":"Uploaded successful","data":{"url":"/uploads/20240101/bigfile.zip"}} ``` ``` ```APIDOC ## GET /api/common/captcha ### Description Generates and returns a graphical CAPTCHA image. ### Method GET ### Endpoint /api/common/captcha ### Parameters #### Query Parameters - **id** (string) - Required - A unique identifier for the CAPTCHA instance (e.g., "login_captcha_001") ### Request Example ```bash curl "http://yourdomain.com/api/common/captcha?id=login_captcha_001" ``` ### Response #### Success Response (200) - Returns an image/jpeg content representing the CAPTCHA. ``` -------------------------------- ### User Account Password Login API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Authenticate users using their account credentials (username/email and password). Subsequent requests require authentication via `__token__` or `Authorization` Header. ```bash # --- 账号密码登录 --- curl -X POST http://yourdomain.com/api/user/login \ -d "account=testuser&password=Test1234" # 响应: # {"code":1,"msg":"Logged in successful","data":{"userinfo":{"id":1,"username":"testuser","token":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}}} ``` -------------------------------- ### Standard File Upload API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Uploads a single file. Requires authentication via `__token__` or `Authorization` Header. The file is sent as multipart/form-data. ```bash # --- 普通文件上传 --- curl -X POST http://yourdomain.com/api/common/upload \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -F "file=@/path/to/image.jpg" # 响应: # {"code":1,"msg":"Uploaded successful","data":{"url":"/uploads/20240101/abc123.jpg","fullurl":"http://yourdomain.com/uploads/20240101/abc123.jpg"}} ``` -------------------------------- ### File Uploads with Upload Library Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles local and cloud storage uploads, including chunked uploads and merging. Automatically records attachment information. ```php request->file('file'); try { $upload = new Upload($file); $attachment = $upload->upload(); // 返回 Attachment 模型实例 $data = $attachment->getBaseData(); // 输出: // [ // 'id' => 1, // 'url' => '/uploads/20240601/abc123def.jpg', // 'fullurl' => 'http://yourdomain.com/uploads/20240601/abc123def.jpg', // 'filename' => 'avatar.jpg', // 'filesize' => 102400, // 'mimetype' => 'image/jpeg', // 'storage' => 'local', // ] return json(['code' => 1, 'data' => $data]); } catch (UploadException $e) { return json(['code' => 0, 'msg' => $e->getMessage()]); } // 2. 分片上传(手动调用) $file = $this->request->file('file'); $chunkid = $this->request->post('chunkid'); // 唯一分片会话 ID $chunkindex = $this->request->post('chunkindex/d'); // 当前分片索引(0-based) $chunkcount = $this->request->post('chunkcount/d'); // 分片总数 try { $upload = new Upload($file); $upload->chunk($chunkid, $chunkindex, $chunkcount); // 保存单个分片 } catch (UploadException $e) { return json(['code' => 0, 'msg' => $e->getMessage()]); } // 3. 合并分片 $filename = $this->request->post('filename'); // 原始文件名 try { $upload = new Upload(); $attachment = $upload->merge($chunkid, $chunkcount, $filename); return json(['code' => 1, 'data' => $attachment->getBaseData()]); } catch (UploadException $e) { return json(['code' => 0, 'msg' => $e->getMessage()]); } // 4. 清理冗余分片 $upload = new Upload(); $upload->clean($chunkid); ``` -------------------------------- ### Admin Login Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles the administrator login process, including username/password authentication, optional CAPTCHA verification, CSRF token validation, and 'remember me' functionality. ```APIDOC ## POST /admin/index/login ### Description Authenticates an administrator user. Supports username, password, optional remember me flag, CAPTCHA, and CSRF token validation. ### Method POST ### Endpoint `/admin/index/login` ### Parameters #### Request Body - **username** (string) - Required - The administrator's username. - **password** (string) - Required - The administrator's password. - **keeplogin** (integer) - Optional - If set to `1`, enables the 'remember me' feature for 24 hours. - **captcha** (string) - Optional - The CAPTCHA code, required if CAPTCHA verification is enabled. - **__token__** (string) - Required - The CSRF token value, obtained from the page. ### Request Example ```json { "username": "admin", "password": "123456", "keeplogin": 1, "captcha": "1a2b", "__token__": "your-csrf-token-here" } ``` ### Response #### Success Response (200) - **code** (integer) - `1` indicating success. - **msg** (string) - Success message, e.g., "Login successful". - **data** (object) - Contains user information and redirect URL. - **url** (string) - The URL to redirect to after successful login. - **id** (integer) - The administrator's ID. - **username** (string) - The administrator's username. - **avatar** (string) - URL to the administrator's avatar. #### Failure Response (200) - **code** (integer) - `0` indicating failure. - **msg** (string) - Error message, e.g., "Password is incorrect". - **data** (object) - Contains a new CSRF token. - **token** (string) - A new CSRF token to be used for subsequent requests. ``` -------------------------------- ### Synchronize Permission Nodes with ThinkPHP CLI Source: https://context7.com/fastadminnet/fastadmin/llms.txt After generating modules, use this ThinkPHP command to synchronize permission nodes within the admin panel. This ensures new modules are accessible via the menu. ```bash php think menu ``` -------------------------------- ### Auth Library - Direct Login Source: https://context7.com/fastadminnet/fastadmin/llms.txt Allows direct login for a user identified by their user ID. Commonly used after third-party authentication or phone verification. ```APIDOC ## Auth::direct() ### Description Logs in a user directly using their user ID. Useful for scenarios like third-party authentication or post-verification logins. ### Method ```php Auth::direct(int $userId) ``` ### Parameters - **userId** (int) - Required - The ID of the user to log in. ### Usage This method sets the current user session based on the provided user ID. ``` -------------------------------- ### Upload Library - Chunked File Upload (Part 1: Upload Chunk) Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles the upload of individual chunks for a file. This is the first step in a chunked upload process, saving a single part of the file. ```APIDOC ## Upload::chunk() ### Description Saves a single chunk of a file during a chunked upload process. This method is called for each part of the file being uploaded. ### Method ```php Upload::chunk(string $chunkid, int $chunkindex, int $chunkcount) ``` ### Parameters - **chunkid** (string) - Required - A unique identifier for the chunked upload session. - **chunkindex** (int) - Required - The index (0-based) of the current chunk being uploaded. - **chunkcount** (int) - Required - The total number of chunks for the file. ### Error Handling - Throws `UploadException` if there is an issue saving the chunk. ``` -------------------------------- ### Attachment Management API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Provides backend media library functionalities including listing, categorization, and deletion of attachments. Works with the Upload library. ```bash # --- 获取附件列表(AJAX,供 bootstrap-table 使用)--- curl "http://yourdomain.com/admin/general/attachment/index" \ -H "X-Requested-With: XMLHttpRequest" \ -G \ --data-urlencode 'filter={"mimetype":"image/"}' \ --data-urlencode 'op={"mimetype":"LIKE"}' \ -d "offset=0&limit=20&sort=id&order=DESC" # 响应: # { # "total": 150, # "rows": [ # {"id":1,"filename":"avatar.jpg","url":"/uploads/20240601/abc.jpg","filesize":102400,"mimetype":"image/jpeg","storage":"local","category":"","fullurl":"http://yourdomain.com/uploads/20240601/abc.jpg"}, # ... # ] # } # --- 批量删除附件 --- curl -X POST http://yourdomain.com/admin/general/attachment/del \ -d "ids=1,2,3" # 响应:{"code":1,"msg":"","data":null} ``` -------------------------------- ### Upload Library - Normal File Upload Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles the upload of a single file received from a request. Supports local and cloud storage configurations. ```APIDOC ## Upload::upload() ### Description Uploads a file received from the request. It handles saving the file to the configured storage (local or cloud) and records attachment information. ### Method ```php Upload::upload(mixed $file) ``` ### Parameters - **file** - Required - The file object obtained from the request (e.g., `$this->request->file('file')`). ### Return Value - Attachment model instance - Returns an instance of the Attachment model upon successful upload, containing details about the uploaded file. ### Error Handling - Throws `UploadException` on failure. Use a try-catch block to handle potential errors during the upload process. ``` -------------------------------- ### User API Endpoints Source: https://context7.com/fastadminnet/fastadmin/llms.txt Provides standard RESTful interfaces for user management including registration, login, profile updates, password changes, and logout. Authentication is handled via `__token__` or `Authorization` header. ```APIDOC ## POST /api/user/register ### Description Registers a new user. ### Method POST ### Endpoint /api/user/register ### Parameters #### Request Body - **username** (string) - Required - User's username - **password** (string) - Required - User's password - **mobile** (string) - Required - User's mobile number - **code** (string) - Required - Verification code ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/register \ -d "username=testuser&password=Test1234&mobile=13800138000&code=123456" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (object) - Response data - **userinfo** (object) - User information - **id** (integer) - User ID - **username** (string) - Username - **nickname** (string) - User nickname - **token** (string) - Authentication token ### Response Example ```json { "code": 1, "msg": "Sign up successful", "data": { "userinfo": { "id": 1, "username": "testuser", "nickname": "用户8000", "token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } } } ``` ``` ```APIDOC ## POST /api/user/login ### Description Logs in a user using account and password. ### Method POST ### Endpoint /api/user/login ### Parameters #### Request Body - **account** (string) - Required - User's account name or mobile number - **password** (string) - Required - User's password ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/login \ -d "account=testuser&password=Test1234" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (object) - Response data - **userinfo** (object) - User information - **id** (integer) - User ID - **username** (string) - Username - **token** (string) - Authentication token ### Response Example ```json { "code": 1, "msg": "Logged in successful", "data": { "userinfo": { "id": 1, "username": "testuser", "token": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } } } ``` ``` ```APIDOC ## POST /api/sms/send ### Description Sends an SMS verification code. Used for mobile login or other verification purposes. ### Method POST ### Endpoint /api/sms/send ### Parameters #### Request Body - **mobile** (string) - Required - The mobile number to send the code to - **event** (string) - Required - The event for which the code is sent (e.g., "mobilelogin") ### Request Example ```bash curl -X POST http://yourdomain.com/api/sms/send \ -d "mobile=13800138000&event=mobilelogin" ``` ``` ```APIDOC ## POST /api/user/mobilelogin ### Description Logs in a user using their mobile number and a verification code. ### Method POST ### Endpoint /api/user/mobilelogin ### Parameters #### Request Body - **mobile** (string) - Required - User's mobile number - **captcha** (string) - Required - The verification code received via SMS ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/mobilelogin \ -d "mobile=13800138000&captcha=123456" ``` ``` ```APIDOC ## POST /api/user/profile ### Description Updates the current user's profile information. Requires authentication. ### Method POST ### Endpoint /api/user/profile ### Parameters #### Headers - **__token__** (string) - Required - Authentication token #### Request Body - **nickname** (string) - Optional - New nickname for the user - **bio** (string) - Optional - User's biography ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/profile \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -d "nickname=新昵称&bio=个人简介" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (null) - No data returned on success ### Response Example ```json {"code":1,"msg":"","data":null} ``` ``` ```APIDOC ## POST /api/user/changepwd ### Description Changes the current user's password. Requires authentication. ### Method POST ### Endpoint /api/user/changepwd ### Parameters #### Headers - **__token__** (string) - Required - Authentication token #### Request Body - **newpassword** (string) - Required - The new password - **oldpassword** (string) - Required - The current password ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/changepwd \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ -d "newpassword=NewPass123&oldpassword=Test1234" ``` ``` ```APIDOC ## POST /api/user/logout ### Description Logs out the current user. Requires authentication. ### Method POST ### Endpoint /api/user/logout ### Parameters #### Headers - **__token__** (string) - Required - Authentication token ### Request Example ```bash curl -X POST http://yourdomain.com/api/user/logout \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ``` ### Response #### Success Response (200) - **code** (integer) - Return code, 1 for success, 0 for failure - **msg** (string) - Message - **data** (null) - No data returned on success ### Response Example ```json {"code":1,"msg":"Logout successful","data":null} ``` ``` -------------------------------- ### FastAdmin Backend Controller Base Class Source: https://context7.com/fastadminnet/fastadmin/llms.txt Extend this class for backend business controllers to leverage built-in CRUD actions and common methods like buildparams and selectpage. Configure properties like noNeedLogin, dataLimit, and searchFields as needed. ```php model = model('Article'); } // 继承 Backend Trait 后,以下方法均已自动实现: // GET /admin/article/index → 列表(支持分页、搜索、过滤、排序) // POST /admin/article/index → 返回 JSON 数据(供 bootstrap-table 使用) // GET /admin/article/add → 添加页面 // POST /admin/article/add → 执行添加(row 数组参数) // GET /admin/article/edit/1 → 编辑页面 // POST /admin/article/edit/1 → 执行编辑 // POST /admin/article/del → 软删除(ids 参数) // POST /admin/article/multi → 批量修改 status 等字段 // GET /admin/article/recyclebin → 回收站列表 // POST /admin/article/restore → 从回收站还原 // POST /admin/article/destroy → 真实删除 /** * 自定义覆盖:添加时附加额外逻辑示例 */ public function add() { if ($this->request->isPost()) { // buildparams 示例:手动构建查询 [$where, $sort, $order, $offset, $limit] = $this->buildparams('title,content'); $count = $this->model->where($where)->count(); if ($count > 1000) { $this->error('文章数量已达上限'); } } return parent::add(); // 调用 Trait 默认 add 逻辑 } } ``` -------------------------------- ### FastAdmin CRUD Code Generation Command Source: https://context7.com/fastadminnet/fastadmin/llms.txt Use the `php think crud` command to automatically generate controllers, models, views, JS, language files, and menu rules based on database tables. Options include specifying table names, controllers, relations, force overwriting, deletion, soft delete, data scope limits, and automatic menu synchronization. ```bash # 基本用法:根据 fa_blog 表生成 CRUD(--table 指定表名) php think crud --table=blog # 指定控制器名(默认与表名相同) php think crud --table=blog --controller=Blog # 生成关联模型(例如 blog 表通过 category_id 关联 category 表) php think crud --table=blog --relation=category --relationforeignkey=category_id --relationprimarykey=id --relationfields=name # 强制覆盖已有文件 php think crud --table=blog --force=true # 撤销生成(删除已生成的文件) php think crud --table=blog --delete=true # 生成带软删除(回收站)功能 php think crud --table=blog --softdelete=true # 指定数据范围限制(auth=按权限/personal=仅个人) php think crud --table=blog --datalimit=auth # 生成后自动同步菜单规则 php think crud --table=blog --menu=true # 生成结果示例(输出): # Create file: /application/admin/controller/Blog.php # Create file: /application/admin/model/Blog.php # Create file: /application/admin/validate/Blog.php # Create file: /application/admin/view/blog/index.html # Create file: /application/admin/view/blog/add.html # Create file: /application/admin/view/blog/edit.html # Create file: /public/assets/js/backend/blog.js # Create file: /application/admin/lang/zh-cn/blog.php ``` -------------------------------- ### Auth Library - User Login Source: https://context7.com/fastadminnet/fastadmin/llms.txt Authenticates a user using their username, email, or mobile number. Returns true on success, allowing access to user data. ```APIDOC ## Auth::login() ### Description Logs in a user using their account credentials (username, email, or mobile). ### Method ```php Auth::login(string $account, string $password) ``` ### Parameters - **account** (string) - Required - The user's account identifier (username, email, or mobile). - **password** (string) - Required - The user's password. ### Return Value - bool - Returns `true` on successful login, `false` otherwise. ### Usage After successful login, `Auth::getUser()` can be used to retrieve the User model instance. ``` -------------------------------- ### Translate and Display Label Source: https://github.com/fastadminnet/fastadmin/blob/1.x-dev/application/admin/view/user/group/add.html Translates a given string using the '__' function and displays it. This is used for internationalization of labels. ```html {:__('Name')} ``` ```html {:__('Permission')} ``` ```html {:__('Check all')} ``` ```html {:__('Expand all')} ``` ```html {:__('Status')} ``` ```html {:__('OK')} ``` ```html {:__('Reset')} ``` -------------------------------- ### Generate CRUD Module with ThinkPHP CLI Source: https://context7.com/fastadminnet/fastadmin/llms.txt Use the ThinkPHP command-line interface to quickly generate a complete data management module for a given table. This command automates CRUD code generation. ```bash php think crud --table=xxx ``` -------------------------------- ### Upload Library - Chunked File Upload (Part 2: Merge Chunks) Source: https://context7.com/fastadminnet/fastadmin/llms.txt Merges all uploaded file chunks into a single complete file. This is the final step after all chunks have been successfully uploaded. ```APIDOC ## Upload::merge() ### Description Merges all previously uploaded file chunks into a single, complete file. This operation should be called after all chunks have been successfully uploaded using `Upload::chunk()`. ### Method ```php Upload::merge(string $chunkid, int $chunkcount, string $filename) ``` ### Parameters - **chunkid** (string) - Required - The unique identifier for the chunked upload session. - **chunkcount** (int) - Required - The total number of chunks that were uploaded. - **filename** (string) - Required - The original filename of the file. ### Return Value - Attachment model instance - Returns an instance of the Attachment model for the newly created complete file. ### Error Handling - Throws `UploadException` if the merging process fails. ``` -------------------------------- ### Large File Chunked Upload API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Handles uploading large files by breaking them into chunks. This process involves three steps: uploading individual chunks, merging the chunks, and optionally cleaning up. Each chunk upload requires parameters like `chunkid`, `chunkindex`, `chunkcount`, and `filename`. ```bash # --- 大文件分片上传(三步:分片上传 → 合并 → 清理)--- # 第一步:上传各分片(chunkindex 从 0 开始) curl -X POST http://yourdomain.com/api/common/upload \ -F "file=@chunk0.bin" \ -F "chunkid=unique-chunk-id-001" \ -F "chunkindex=0" \ -F "chunkcount=3" \ -F "filename=bigfile.zip" # 第二步:合并分片 curl -X POST http://yourdomain.com/api/common/upload \ -d "chunkid=unique-chunk-id-001&action=merge&chunkcount=3&filename=bigfile.zip" # 响应:{"code":1,"msg":"Uploaded successful","data":{"url":"/uploads/20240101/bigfile.zip"}} ``` -------------------------------- ### Iterate and Display Status List Source: https://github.com/fastadminnet/fastadmin/blob/1.x-dev/application/admin/view/user/group/edit.html Iterates through a status list and outputs each status as an HTML-encoded string. This is useful for displaying dynamic status options. ```php {foreach name="statusList" item="vo"} {$vo|htmlentities} {/foreach} ``` -------------------------------- ### User Mobile Verification Code Login API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Log in users via their mobile number using a verification code. This process involves two steps: first sending the code, then logging in with the mobile number and the received code. Authentication is required for subsequent requests. ```bash # --- 手机验证码登录(先发送验证码再登录)--- curl -X POST http://yourdomain.com/api/sms/send \ -d "mobile=13800138000&event=mobilelogin" curl -X POST http://yourdomain.com/api/user/mobilelogin \ -d "mobile=13800138000&captcha=123456" ``` -------------------------------- ### User Logout API Source: https://context7.com/fastadminnet/fastadmin/llms.txt Logs out the currently authenticated user. Requires authentication via `__token__` or `Authorization` Header. ```bash # --- 退出登录 --- curl -X POST http://yourdomain.com/api/user/logout \ -H "__token__: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # 响应:{"code":1,"msg":"Logout successful","data":null} ```