feat: WWJCloud 企业级全栈框架 v0.3.5 完整更新
🚀 核心更新: - ✅ 完善 NestJS 企业级架构设计 - ✅ 优化配置中心和基础设施层 - ✅ 增强第三方服务集成能力 - ✅ 完善多租户架构支持 - 🎯 对标 Java Spring Boot 和 PHP ThinkPHP 📦 新增文件: - wwjcloud-nest 完整框架结构 - Docker 容器化配置 - 管理后台界面 - 数据库迁移脚本 🔑 Key: ebb38b43ec39f355f071294fd1cf9c42
This commit is contained in:
221
src/core/auth/services/admin/auth-site.service.ts
Normal file
221
src/core/auth/services/admin/auth-site.service.ts
Normal file
@@ -0,0 +1,221 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseService } from '@wwjCommon/base/base.service';
|
||||
import { CacheService } from '@wwjCommon/cache/cache.service';
|
||||
import { LoggingService } from '@wwjCommon/logging/logging.service';
|
||||
import { UploadService } from '@wwjVendor/upload/upload.service';
|
||||
import { PayService } from '@wwjVendor/pay/pay.service';
|
||||
import { SmsService } from '@wwjVendor/sms/sms.service';
|
||||
import { NoticeService } from '@wwjVendor/notice/notice.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthSiteService extends BaseService<any> {
|
||||
private readonly logger = new Logger(AuthSiteService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Object)
|
||||
protected readonly repository: Repository<any>,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly loggingService: LoggingService,
|
||||
private readonly uploadService: UploadService,
|
||||
private readonly payService: PayService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly noticeService: NoticeService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSiteInfo
|
||||
* 对应 PHP: AuthSiteService_admin::getSiteInfo()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getSiteInfo() {
|
||||
// 基于PHP真实逻辑: getSiteInfo
|
||||
// PHP原文: //通过用户id获取 return ( new SiteService() )->getSiteCache($this->site_id); } /** * 通过站点id获取菜单列表 * @param int $is_tree * @...
|
||||
//通过用户id获取
|
||||
return ( this.siteService ).getSiteCache(this.site_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过站点id获取菜单列表
|
||||
* @param int is_tree
|
||||
* @param int|string status
|
||||
* @param string addon
|
||||
* @param int is_button
|
||||
* @return mixed
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getMenuList(int is_tree, status, addon = 'all', int is_button = 1)
|
||||
{
|
||||
return ( this.siteService ).getMenuList(this.site_id, is_tree, status, addon, is_button);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过站点id获取菜单列表
|
||||
* @param int|string status
|
||||
* @return mixed
|
||||
*/
|
||||
async getApiList(status)
|
||||
{
|
||||
return ( this.siteService ).getApiList(this.site_id, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前站点可以单独显示的菜单(仅支持站点端调用)
|
||||
* @return array|SysMenu[]
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getShowMenuList()
|
||||
{
|
||||
const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
|
||||
return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站点支持
|
||||
* @return array|mixed|string|null
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getAuthAddonList()
|
||||
{
|
||||
return ( this.addonService ).getAddonListBySiteId(this.site_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getMenuList
|
||||
* 对应 PHP: AuthSiteService_admin::getMenuList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getMenuList(is_tree: number, status: number, addon: number, is_button: number) {
|
||||
// 基于PHP真实逻辑: getMenuList
|
||||
// PHP原文: return ( new SiteService() )->getMenuList($this->site_id, $is_tree, $status, $addon, $is_button); } /** * 通过站点id获取菜单列表 * @param int...
|
||||
return ( this.siteService ).getMenuList(this.site_id, is_tree, status, addon, is_button);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过站点id获取菜单列表
|
||||
* @param int|string status
|
||||
* @return mixed
|
||||
*/
|
||||
async getApiList(status)
|
||||
{
|
||||
return ( this.siteService ).getApiList(this.site_id, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前站点可以单独显示的菜单(仅支持站点端调用)
|
||||
* @return array|SysMenu[]
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getShowMenuList()
|
||||
{
|
||||
const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
|
||||
return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站点支持
|
||||
* @return array|mixed|string|null
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getAuthAddonList()
|
||||
{
|
||||
return ( this.addonService ).getAddonListBySiteId(this.site_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getApiList
|
||||
* 对应 PHP: AuthSiteService_admin::getApiList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getApiList(status: any) {
|
||||
// 基于PHP真实逻辑: getApiList
|
||||
// PHP原文: return ( new SiteService() )->getApiList($this->site_id, $status); } /** * 查询当前站点可以单独显示的菜单(仅支持站点端调用) * @return array|SysMenu[] ...
|
||||
return ( this.siteService ).getApiList(this.site_id, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前站点可以单独显示的菜单(仅支持站点端调用)
|
||||
* @return array|SysMenu[]
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getShowMenuList()
|
||||
{
|
||||
const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
|
||||
return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站点支持
|
||||
* @return array|mixed|string|null
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getAuthAddonList()
|
||||
{
|
||||
return ( this.addonService ).getAddonListBySiteId(this.site_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getShowMenuList
|
||||
* 对应 PHP: AuthSiteService_admin::getShowMenuList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getShowMenuList() {
|
||||
// 基于PHP真实逻辑: getShowMenuList
|
||||
// PHP原文: $menu_keys = ( new SiteService() )->getMenuIdsBySiteId($this->site_id, 1); return ( new SysMenu() )->where([ [ 'menu_key', 'in', $menu_keys ],...
|
||||
const menu_keys = ( this.siteService ).getMenuIdsBySiteId(this.site_id, 1);
|
||||
return ( this.sysMenuService ).where([ [ 'menu_key', 'in', menu_keys ], [ 'menu_type', '=', MenuTypeDict.MENU ], [ 'app_type', '=', AppTypeDict.SITE ], [ 'is_show', '=', 1 ) )).select().toArray(];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取站点支持
|
||||
* @return array|mixed|string|null
|
||||
* @throws DataNotFoundBusinessException
|
||||
* @throws DbBusinessException
|
||||
* @throws ModelNotFoundBusinessException
|
||||
*/
|
||||
async getAuthAddonList()
|
||||
{
|
||||
return ( this.addonService ).getAddonListBySiteId(this.site_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthAddonList
|
||||
* 对应 PHP: AuthSiteService_admin::getAuthAddonList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getAuthAddonList() {
|
||||
// 基于PHP真实逻辑: getAuthAddonList
|
||||
// PHP原文: return ( new AddonService() )->getAddonListBySiteId($this->site_id); } }...
|
||||
return ( this.addonService ).getAddonListBySiteId(this.site_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
203
src/core/auth/services/admin/auth.service.ts
Normal file
203
src/core/auth/services/admin/auth.service.ts
Normal file
@@ -0,0 +1,203 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseService } from '@wwjCommon/base/base.service';
|
||||
import { CacheService } from '@wwjCommon/cache/cache.service';
|
||||
import { LoggingService } from '@wwjCommon/logging/logging.service';
|
||||
import { UploadService } from '@wwjVendor/upload/upload.service';
|
||||
import { PayService } from '@wwjVendor/pay/pay.service';
|
||||
import { SmsService } from '@wwjVendor/sms/sms.service';
|
||||
import { NoticeService } from '@wwjVendor/notice/notice.service';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService extends BaseService<any> {
|
||||
private readonly logger = new Logger(AuthService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Object)
|
||||
protected readonly repository: Repository<any>,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly loggingService: LoggingService,
|
||||
private readonly uploadService: UploadService,
|
||||
private readonly payService: PayService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly noticeService: NoticeService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* checkSiteAuth
|
||||
* 对应 PHP: AuthService_admin::checkSiteAuth()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async checkSiteAuth(request: any) {
|
||||
// 基于PHP真实逻辑: checkSiteAuth
|
||||
// PHP原文: $site_id = $request->adminSiteId(); //todo 将站点编号转化为站点id $site_info = ( new CoreSiteService() )->getSiteCache($site_id); //站点不...
|
||||
const site_id = request.adminSiteId(];
|
||||
//todo 将站点编号转化为站点id
|
||||
const site_info = ( this.coreSiteService ).getSiteCache(site_id);
|
||||
//站点不存在
|
||||
if (!site_info)) throw new AuthBusinessException('SITE_NOT_EXIST');
|
||||
//没有当前站点的信息
|
||||
if (!AuthService.isSuperAdmin()) {
|
||||
if (!this.getAuthRole(site_id)) throw new AuthBusinessException('NO_SITE_PERMISSION');
|
||||
}
|
||||
|
||||
/**
|
||||
* checkRole
|
||||
* 对应 PHP: AuthService_admin::checkRole()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async checkRole(request: any) {
|
||||
// 基于PHP真实逻辑: checkRole
|
||||
// PHP原文: $rule = strtolower(trim($request->rule()->getRule())); $method = strtolower(trim($request->method())); $site_info = ( new AuthSiteServ...
|
||||
const rule = strtolower(trim(request.rule().getRule())];
|
||||
const method = strtolower(trim(request.method())];
|
||||
const site_info = ( this.authSiteService ).getSiteInfo(];
|
||||
if (method != 'get') {
|
||||
if (site_info[ 'status' ) == SiteDict.EXPIRE) throw new AuthBusinessException('SITE_EXPIRE_NOT_ALLOW');
|
||||
if (site_info[ 'status' ) == SiteDict.CLOSE) throw new AuthBusinessException('SITE_CLOSE_NOT_ALLOW');
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthRole
|
||||
* 对应 PHP: AuthService_admin::getAuthRole()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getAuthRole(site_id: number) {
|
||||
// 基于PHP真实逻辑: getAuthRole
|
||||
// PHP原文: $user_role_service = new UserRoleService(); return $user_role_service->getUserRole($site_id, $this->uid); } /** * 当前授权用户接口权限 ...
|
||||
const user_role_service = this.userRoleService;
|
||||
return user_role_service.getUserRole(site_id, this.uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前授权用户接口权限
|
||||
* @return */
|
||||
async getAuthApiList()
|
||||
{
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const is_admin = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthApiList
|
||||
* 对应 PHP: AuthService_admin::getAuthApiList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getAuthApiList() {
|
||||
// 基于PHP真实逻辑: getAuthApiList
|
||||
// PHP原文: if (AuthService::isSuperAdmin()) { $is_admin = 1;...
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const is_admin = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthMenuList
|
||||
* 对应 PHP: AuthService_admin::getAuthMenuList()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getAuthMenuList(is_tree: number, addon: number) {
|
||||
// 基于PHP真实逻辑: getAuthMenuList
|
||||
// PHP原文: if (AuthService::isSuperAdmin()) { $is_admin = 1;...
|
||||
if (AuthService.isSuperAdmin()) {
|
||||
const is_admin = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* getAuthInfo
|
||||
* 对应 PHP: AuthService_admin::getAuthInfo()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getAuthInfo() {
|
||||
// 基于PHP真实逻辑: getAuthInfo
|
||||
// PHP原文: return ( new SiteUserService() )->getInfo($this->uid); } /** * 修改用户权限 * @param string $field * @param $data * @return boo...
|
||||
return ( this.siteUserService ).getInfo(this.uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户权限
|
||||
* @param string field
|
||||
* @param data
|
||||
* @return bool
|
||||
*/
|
||||
async modifyAuth(string field, data)
|
||||
{
|
||||
return ( this.siteUserService ).modify(this.uid, field, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param data
|
||||
* @return true
|
||||
*/
|
||||
async editAuth(data)
|
||||
{
|
||||
if (!!data[ 'password' ))) {
|
||||
//检测原始密码是否正确
|
||||
const user = ( this.userService ).find(this.uid);
|
||||
if (!check_password(data[ 'original_password' ), user.password))
|
||||
throw new AuthBusinessException('OLD_PASSWORD_ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* modifyAuth
|
||||
* 对应 PHP: AuthService_admin::modifyAuth()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async modifyAuth(field: string, data: string) {
|
||||
// 基于PHP真实逻辑: modifyAuth
|
||||
// PHP原文: return ( new SiteUserService() )->modify($this->uid, $field, $data); } /** * 修改用户 * @param array $data * @return true */ ...
|
||||
return ( this.siteUserService ).modify(this.uid, field, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param data
|
||||
* @return true
|
||||
*/
|
||||
async editAuth(data)
|
||||
{
|
||||
if (!!data[ 'password' ))) {
|
||||
//检测原始密码是否正确
|
||||
const user = ( this.userService ).find(this.uid);
|
||||
if (!check_password(data[ 'original_password' ), user.password))
|
||||
throw new AuthBusinessException('OLD_PASSWORD_ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* editAuth
|
||||
* 对应 PHP: AuthService_admin::editAuth()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async editAuth(data: any[]) {
|
||||
// 基于PHP真实逻辑: editAuth
|
||||
// PHP原文: if (!empty($data[ 'password' ])) { //检测原始密码是否正确 $user = ( new UserService() )->find($this->uid); if (!check_passwo...
|
||||
if (!!data[ 'password' ))) {
|
||||
//检测原始密码是否正确
|
||||
const user = ( this.userService ).find(this.uid);
|
||||
if (!check_password(data[ 'original_password' ), user.password))
|
||||
throw new AuthBusinessException('OLD_PASSWORD_ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* isSuperAdmin
|
||||
* 对应 PHP: AuthService_admin::isSuperAdmin()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async isSuperAdmin() {
|
||||
// 基于PHP真实逻辑: isSuperAdmin
|
||||
// PHP原文: $super_admin_uid = Cache::get('super_admin_uid'); if (!$super_admin_uid) { $super_admin_uid = ( new SysUserRole() )->where([ ...
|
||||
const super_admin_uid = Cache.get('super_admin_uid');
|
||||
|
||||
if (!super_admin_uid) {
|
||||
const super_admin_uid = ( this.sysUserRoleService ).where([
|
||||
[ 'site_id', '=', request().defaultSiteId() ],
|
||||
[ 'is_admin', '=', 1 ]
|
||||
]).value('uid'];
|
||||
Cache.set('super_admin_uid', super_admin_uid);
|
||||
}
|
||||
}
|
||||
88
src/core/auth/services/admin/config.service.ts
Normal file
88
src/core/auth/services/admin/config.service.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseService } from '@wwjCommon/base/base.service';
|
||||
import { CacheService } from '@wwjCommon/cache/cache.service';
|
||||
import { LoggingService } from '@wwjCommon/logging/logging.service';
|
||||
import { UploadService } from '@wwjVendor/upload/upload.service';
|
||||
import { PayService } from '@wwjVendor/pay/pay.service';
|
||||
import { SmsService } from '@wwjVendor/sms/sms.service';
|
||||
import { NoticeService } from '@wwjVendor/notice/notice.service';
|
||||
|
||||
@Injectable()
|
||||
export class ConfigService extends BaseService<any> {
|
||||
private readonly logger = new Logger(ConfigService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Object)
|
||||
protected readonly repository: Repository<any>,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly loggingService: LoggingService,
|
||||
private readonly uploadService: UploadService,
|
||||
private readonly payService: PayService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly noticeService: NoticeService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* getConfig
|
||||
* 对应 PHP: ConfigService_admin::getConfig()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async getConfig() {
|
||||
// 基于PHP真实逻辑: getConfig
|
||||
// PHP原文: $info = (new CoreConfigService())->getConfig($this->request->defaultSiteId(), ConfigKeyDict::ADMIN_LOGIN)['value'] ?? []; return [ ...
|
||||
const info = this.coreConfigService.getConfig(this.request.defaultSiteId(), ConfigKeyDict.ADMIN_LOGIN).value || [];
|
||||
return [
|
||||
is_captcha: info.is_captcha || 0,//是否启用验证码
|
||||
is_site_captcha: info.is_site_captcha || 0,//是否启用站点验证码
|
||||
bg: info.bg || '',//平台登录端 背景
|
||||
site_bg: info.site_bg || '',//站点登录端 背景
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册与登录设置
|
||||
* @param data
|
||||
* @return true
|
||||
*/
|
||||
async setConfig(data)
|
||||
{
|
||||
const config = [
|
||||
is_captcha: data.is_captcha || 0,//是否启用验证码
|
||||
is_site_captcha: data.is_site_captcha || 0,//是否启用站点验证码
|
||||
bg: data.bg || '',//平台登录端 背景
|
||||
site_bg: data.site_bg || '',//站点登录端 背景
|
||||
];
|
||||
this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.ADMIN_LOGIN, config);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* setConfig
|
||||
* 对应 PHP: ConfigService_admin::setConfig()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async setConfig(data: any[]) {
|
||||
// 基于PHP真实逻辑: setConfig
|
||||
// PHP原文: $config = [ 'is_captcha' => $data['is_captcha'] ?? 0,//是否启用验证码 'is_site_captcha' => $data['is_site_captcha'] ?? 0,//是否启用站点验证码 ...
|
||||
const config = [
|
||||
is_captcha: data.is_captcha || 0,//是否启用验证码
|
||||
is_site_captcha: data.is_site_captcha || 0,//是否启用站点验证码
|
||||
bg: data.bg || '',//平台登录端 背景
|
||||
site_bg: data.site_bg || '',//站点登录端 背景
|
||||
];
|
||||
this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.ADMIN_LOGIN, config);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
161
src/core/auth/services/admin/login.service.ts
Normal file
161
src/core/auth/services/admin/login.service.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { BaseService } from '@wwjCommon/base/base.service';
|
||||
import { CacheService } from '@wwjCommon/cache/cache.service';
|
||||
import { LoggingService } from '@wwjCommon/logging/logging.service';
|
||||
import { UploadService } from '@wwjVendor/upload/upload.service';
|
||||
import { PayService } from '@wwjVendor/pay/pay.service';
|
||||
import { SmsService } from '@wwjVendor/sms/sms.service';
|
||||
import { NoticeService } from '@wwjVendor/notice/notice.service';
|
||||
|
||||
@Injectable()
|
||||
export class LoginService extends BaseService<any> {
|
||||
private readonly logger = new Logger(LoginService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Object)
|
||||
protected readonly repository: Repository<any>,
|
||||
private readonly cacheService: CacheService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly loggingService: LoggingService,
|
||||
private readonly uploadService: UploadService,
|
||||
private readonly payService: PayService,
|
||||
private readonly smsService: SmsService,
|
||||
private readonly noticeService: NoticeService,
|
||||
) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* login
|
||||
* 对应 PHP: LoginService_admin::login()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async login(username: string, password: string, app_type: string) {
|
||||
// 基于PHP真实逻辑: login
|
||||
// PHP原文: if(!array_key_exists($app_type, AppTypeDict::getAppType())) throw new AuthException('APP_TYPE_NOT_EXIST'); $this->site_id = $this->request->a...
|
||||
if(!array_key_exists(app_type, AppTypeDict.getAppType())) throw new AuthBusinessException('APP_TYPE_NOT_EXIST'];
|
||||
|
||||
this.site_id = this.request.adminSiteId(];
|
||||
|
||||
const config = this.configService.getConfig();
|
||||
switch(app_type){
|
||||
case AppTypeDict.SITE:
|
||||
const is_captcha = config.is_site_captcha;
|
||||
break;
|
||||
case AppTypeDict.ADMIN:
|
||||
const is_captcha = config.is_captcha;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* logout
|
||||
* 对应 PHP: LoginService_admin::logout()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async logout() {
|
||||
// 基于PHP真实逻辑: logout
|
||||
// PHP原文: self::clearToken($this->uid, $this->app_type, $this->request->adminToken()); return true; } /** * 创建token * @param SysUser ...
|
||||
self.clearToken(this.uid, this.app_type, this.request.adminToken()];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建token
|
||||
* @param SysUser userinfo
|
||||
* @param string app_type
|
||||
* @return */
|
||||
async createToken(SysUser userinfo, string app_type)
|
||||
{
|
||||
const expire_time = env('system.admin_token_expire_time') || 3600;
|
||||
return TokenAuth.createToken(userinfo.uid, AppTypeDict.ADMIN, [uid: userinfo.uid, username: userinfo.username), expire_time];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理token
|
||||
* @param int uid
|
||||
* @param string|null type
|
||||
* @param string|null token
|
||||
*/
|
||||
public static function clearToken(int uid, ?string type = '', ?string token = '')
|
||||
{
|
||||
if (!type)) {
|
||||
TokenAuth.clearToken(uid, AppTypeDict.ADMIN, token];//清除平台管理端的token
|
||||
// TokenAuth.clearToken(uid, AppTypeDict.SITE, token);//清除站点管理端的token
|
||||
}
|
||||
|
||||
/**
|
||||
* createToken
|
||||
* 对应 PHP: LoginService_admin::createToken()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async createToken(userinfo: string, app_type: string) {
|
||||
// 基于PHP真实逻辑: createToken
|
||||
// PHP原文: $expire_time = env('system.admin_token_expire_time') ?? 3600; return TokenAuth::createToken($userinfo->uid, AppTypeDict::ADMIN, ['uid' => $use...
|
||||
const expire_time = env('system.admin_token_expire_time') || 3600;
|
||||
return TokenAuth.createToken(userinfo.uid, AppTypeDict.ADMIN, [uid: userinfo.uid, username: userinfo.username), expire_time];
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理token
|
||||
* @param int uid
|
||||
* @param string|null type
|
||||
* @param string|null token
|
||||
*/
|
||||
public static function clearToken(int uid, ?string type = '', ?string token = '')
|
||||
{
|
||||
if (!type)) {
|
||||
TokenAuth.clearToken(uid, AppTypeDict.ADMIN, token];//清除平台管理端的token
|
||||
// TokenAuth.clearToken(uid, AppTypeDict.SITE, token);//清除站点管理端的token
|
||||
}
|
||||
|
||||
/**
|
||||
* clearToken
|
||||
* 对应 PHP: LoginService_admin::clearToken()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async clearToken(uid: number, type: number, token: number) {
|
||||
// 基于PHP真实逻辑: clearToken
|
||||
// PHP原文: if (empty($type)) { TokenAuth::clearToken($uid, AppTypeDict::ADMIN, $token);//清除平台管理端的token // TokenAuth::clearToken($uid, AppT...
|
||||
if (!type)) {
|
||||
TokenAuth.clearToken(uid, AppTypeDict.ADMIN, token];//清除平台管理端的token
|
||||
// TokenAuth.clearToken(uid, AppTypeDict.SITE, token);//清除站点管理端的token
|
||||
}
|
||||
|
||||
/**
|
||||
* parseToken
|
||||
* 对应 PHP: LoginService_admin::parseToken()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async parseToken(token: string) {
|
||||
// 基于PHP真实逻辑: parseToken
|
||||
// PHP原文: if (empty($token)) { //定义专属于授权认证机制的错误响应, 定义专属语言包 throw new AuthException('MUST_LOGIN', 401);...
|
||||
if (!token)) {
|
||||
//定义专属于授权认证机制的错误响应, 定义专属语言包
|
||||
throw new AuthBusinessException('MUST_LOGIN', 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* resetAdministratorPassword
|
||||
* 对应 PHP: LoginService_admin::resetAdministratorPassword()
|
||||
* 逻辑类型: undefined - undefined
|
||||
*/
|
||||
async resetAdministratorPassword() {
|
||||
// 基于PHP真实逻辑: resetAdministratorPassword
|
||||
// PHP原文: $super_admin_uid = ( new SysUserRole() )->where([ [ 'site_id', '=', request()->defaultSiteId() ], [ 'is_admin', '=', 1 ] ...
|
||||
const super_admin_uid = ( this.sysUserRoleService ).where([
|
||||
[ 'site_id', '=', request().defaultSiteId() ],
|
||||
[ 'is_admin', '=', 1 ]
|
||||
]).value('uid'];
|
||||
|
||||
const user = this.userService.find(super_admin_uid];
|
||||
user.password = create_password('123456'];
|
||||
user.save(];
|
||||
|
||||
self.clearToken(super_admin_uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user