yzh52521 / think-auth
The Auth Library For ThinkPHP6
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 1
Type:think-extend
Requires
- php: >=8.0.2
- topthink/framework: >=6.0
Requires (Dev)
- yzh52521/think-mailer: ^2.0
- yzh52521/think-notification: ^1.0
Suggests
- yzh52521/think-mailer: Required to send email.
- yzh52521/think-notification: Required to send notification.
README
安装
composer require yzh52521/think-auth
基础user表
CREATE TABLE `user` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '用户名称', `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '邮箱地址', `email_verified_at` timestamp NULL DEFAULT NULL COMMENT '邮箱验证时间', `phone` varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '手机号', `phone_verified_at` timestamp NULL DEFAULT NULL COMMENT '手机验证时间', `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '密码', `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '记住密码token', `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_email_unique` (`email`), UNIQUE KEY `user_phone_unique` (`phone`) USING HASH ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Auth常用方法
//通过账号密码登录 第二个参数 此值指示是否需要验证会话的 「记住我」 功能
Auth::attempt(['username' => 'tp5er@qq.com', 'password' => '123456'], $remember = true);
//通过用户实例登录
Auth::login(User::find(1), $remember = false);
//只验证一次
Auth::once(['username' => 'tp5er@qq.com', 'password' => '123456'])
//通过id登录
Auth::loginUsingId(1,$remember = false)
在没有会话或cookie的情况下,将给定的用户ID登录认证用户
Auth::onceUsingId(1);
// 获取当前的认证用户信息 ...
$user = Auth::user();
// 获取当前的认证用户id ...
$id = Auth::id();
if (Auth::check()) {
// 用户已登录...
}
//使用户退出登录(清除会话)
Auth::logout();
//访问特定的看守器实例
Auth::guard('api')->attempt($credentials,$remember = false);
Auth::guard('api')->login(User::find(1), $remember = false);