mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
* fix(api-gateway): reduce exports * wip controllers * fix: imports of controllers * fix(api-gateway): rename http service interface to proxy interface * wip: self-registering services and controllers * wip: add registering controller method bindings and services in container * feat: merge two services together * wip: resolving endpoints to direct code calls * wip: bind controller container to a singleton * fix: controller binding to instantiate and self-register on controller container * fix: move signout endpoint to auth controller * wip: define inversify controllers in the controller container * fix(auth): bind inversify controllers to controller container * fix(auth): linter issues * fix(auth): specs * fix(auth): inversify controllers bindings * wip: endpoint resolving * wip: add endpoint for more auth controllers * wip: add sessions controller endpoint resolvings * wip: add subscription invites endpoint resolvings * wip: add subscription tokens endpoint resolvings * wip: add all binding for auth server controllers * wip: fix migrations path * fix: configure default env vars and ci setup
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { inject, injectable } from 'inversify'
|
|
|
|
import TYPES from '../../../Bootstrap/Types'
|
|
import { OfflineSubscriptionTokenRepositoryInterface } from '../../Auth/OfflineSubscriptionTokenRepositoryInterface'
|
|
import { OfflineSettingName } from '../../Setting/OfflineSettingName'
|
|
import { OfflineSettingRepositoryInterface } from '../../Setting/OfflineSettingRepositoryInterface'
|
|
import { OfflineUserSubscriptionRepositoryInterface } from '../../Subscription/OfflineUserSubscriptionRepositoryInterface'
|
|
import { UseCaseInterface } from '../UseCaseInterface'
|
|
import { AuthenticateOfflineSubscriptionTokenDTO } from './AuthenticateOfflineSubscriptionTokenDTO'
|
|
import { AuthenticateOfflineSubscriptionTokenResponse } from './AuthenticateOfflineSubscriptionTokenResponse'
|
|
|
|
@injectable()
|
|
export class AuthenticateOfflineSubscriptionToken implements UseCaseInterface {
|
|
constructor(
|
|
@inject(TYPES.Auth_OfflineSubscriptionTokenRepository)
|
|
private offlineSubscriptionTokenRepository: OfflineSubscriptionTokenRepositoryInterface,
|
|
@inject(TYPES.Auth_OfflineUserSubscriptionRepository)
|
|
private offlineUserSubscriptionRepository: OfflineUserSubscriptionRepositoryInterface,
|
|
@inject(TYPES.Auth_OfflineSettingRepository) private offlineSettingRepository: OfflineSettingRepositoryInterface,
|
|
) {}
|
|
|
|
async execute(dto: AuthenticateOfflineSubscriptionTokenDTO): Promise<AuthenticateOfflineSubscriptionTokenResponse> {
|
|
const userEmail = await this.offlineSubscriptionTokenRepository.getUserEmailByToken(dto.token)
|
|
if (userEmail === undefined || userEmail !== dto.userEmail) {
|
|
return {
|
|
success: false,
|
|
}
|
|
}
|
|
|
|
const subscriptions = await this.offlineUserSubscriptionRepository.findByEmail(userEmail, 0)
|
|
if (subscriptions.length === 0) {
|
|
return {
|
|
success: false,
|
|
}
|
|
}
|
|
|
|
const offlineFeaturesTokenSetting = await this.offlineSettingRepository.findOneByNameAndEmail(
|
|
OfflineSettingName.FeaturesToken,
|
|
userEmail,
|
|
)
|
|
if (offlineFeaturesTokenSetting === null) {
|
|
return {
|
|
success: false,
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
email: userEmail,
|
|
featuresToken: offlineFeaturesTokenSetting.value as string,
|
|
}
|
|
}
|
|
}
|