fluidphp / user-auth-api-helper
FluidPhp 框架用户身份验证 API
Requires
- php: 5.4.0 - 7.4
- fluidphp/emailmanager-helper: ^1.0.0
- fluidphp/fluidphp: ^2.0.0
- fluidphp/logger-helper: ^1.0.0
- fluidphp/translator-helper: ^1.0.0
- fluidphp/validator-helper: ^1.0.0
- mnsami/composer-custom-directory-installer: 2.0.*
- phpmailer/phpmailer: ^6.7
- rmccue/requests: ^2.0
This package is auto-updated.
Last update: 2024-09-13 00:02:04 UTC
README
这是 fluidphp 框架的一个辅助工具,用于在您的网站或后端面板上验证用户
安装
1 - 将包添加到您的 composer.json 以安装辅助工具
"require":
{
"mnsami/composer-custom-directory-installer": "2.0.*" ,
"fluidphp/user-auth-api-helper": "^1.0.0"
} ,
"extra":
{
"installer-paths":
{
"./vendor/fluidphp/helpers/Translator": ["fluidphp/translator-helper"] ,
"./vendor/fluidphp/helpers/Validator": ["fluidphp/validator-helper"],
"./vendor/fluidphp/helpers/Logger": ["fluidphp/logger-helper"],
"./vendor/fluidphp/helpers/EmailManager": ["fluidphp/emailmanager-helper"],
"./vendor/fluidphp/helpers/UserAuthApi": ["fluidphp/user-auth-api-helper"]
}
}
2 - 在 app/config 文件夹中创建 "user-auth-api.php" 配置文件,并从 "user-auth-api.config.sample.php" 复制代码
3 - 在 app/config 文件夹中创建 "logger.php" 文件,如果尚未存在,请添加您的配置
return
[
'develop' =>
[
'connection' => 'default' ,
'table' => 'log'
] ,
'prod' =>
[
'connection' => 'default' ,
'table' => 'log'
]
];
4 - 在 app/config 中配置 "auth.php" 以添加 API 用户模型
'model' => '\helpers\UserAuthApi\models\Users',
5- 将 email-templates 文件夹移动到 app/views
用法
使用受保护页面过滤器
将过滤器 "_user-auth-api.check_login" 添加到所有需要访问已认证用户的路由
使用 API 包装器
API 包装器是一种方便的方式,可以直接从 js 中调用,因为它可以直接设置会话变量。
要调用 API 包装器,您可以使用任何请求库
$app = \App::option('app');
try
{
$request = Requests::post($app['url'] . $app['env'] . '/wrapper/reset-password/', [], ['username' => 'some_user_name']);
return $request->body;
}
catch (\Throwable $e)
{
return '{"error": 1, "message": "' . $e->getMessage() . '", "code": ' . $e->getCode(). '}';
}
请注意,直接调用 API 不会设置会话变量。
直接调用身份验证 API
API 应仅在本地主机环境中直接调用。
要调用身份验证 API,您可以使用任何请求库
$app = \App::option('app');
try
{
$request = Requests::put($app['url'] . $app['env'] . '/account/asutologin/'. $code . '/');
return $request->body;
}
catch (\Throwable $e)
{
return '{"error": 1, "message": "' . $e->getMessage() . '", "code": ' . $e->getCode(). '}';
}
端点
包装器
注册
-
{(http|https)}://{main_doman}/{app_path}/wrapper/register/
- 方法: post
- 描述: 将新用户注册到数据库
- 参数: see config/validator.php
登录
-
{(http|https)}://{main_doman}/{app_path}/wrapper/login/
- 方法: post
- 描述: 尝试登录用户
- 参数: 用户名,密码
- 返回数据: 用户数据
登出
-
{(http|https)}://{main_doman}/{app_path}/wrapper/logout/
- 方法: put
- 描述: 删除用户会话数据和自动登录 cookie
忘记密码
-
{(http|https)}://{main_doman}/{app_path}/wrapper/forgot-pass/
- 方法: post
- 描述: 发送包含重置密码链接的电子邮件
- 参数: 用户名
自动登录
-
{(http|https)}://{main_doman}/{app_path}/wrapper/auto-login/{code}/
- 方法: put
- 描述: 尝试使用现有的 login_token 登录
- 参数: see config/validator.php
- 返回数据: 返回用户数据
验证账户
-
{(http|https)}://{main_doman}/{app_path}/wrapper/verify/{verificationCode}/
- 方法: put
- 描述: 尝试验证用户账户
更改密码
-
{(http|https)}://{main_doman}/{app_path}/wrapper/change-password/{resetLink}/
- 方法: post
- 描述: 更改用户密码
- 参数: see config/validator.php
API
API 应仅在本地主机环境中直接调用,因此它无法设置会话变量。
注册
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/register/
- 方法: post
- 描述: 将新用户注册到数据库
- 参数: see config/validator.php
登录
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/login/
- 方法: post
- 描述: 尝试登录用户
- 参数: 用户名,密码
- 返回数据: 用户数据
登出
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/logout/{code}/
- 方法: put
- 描述: 删除用户会话数据和自动登录 cookie
忘记密码
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/forgot-password/
- 描述: 发送包含重置密码链接的电子邮件
- 参数: 用户名
自动登录
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/auto-login/{code}/
- 方法: put
- 描述: 尝试使用现有的 login_token 登录
- 参数: see config/validator.php
- 返回数据: 返回用户数据
验证账户
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/verify/{verificationCode}/
- 方法: put
- 描述: 尝试验证用户账户
更改密码
-
{(http|https)}://{USER_AUTH_APP_URL}/{app_path}/account/change-password/{resetLink}/
- 方法: post
- 描述: 更改用户密码
- 参数: see config/validator.php