@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
2
2
import { node , relation } from 'cypher-query-builder' ;
3
3
import { DateTime } from 'luxon' ;
4
4
import { type ID , type Role , ServerException } from '~/common' ;
5
+ import { type UserStatus } from '../../components/user/dto' ;
5
6
import { DatabaseService , DbTraceLayer , OnIndex } from '../database' ;
6
7
import {
7
8
ACTIVE ,
@@ -97,27 +98,34 @@ export class AuthenticationRepository {
97
98
. run ( ) ;
98
99
}
99
100
100
- async getPasswordHash ( input : LoginInput ) {
101
+ async getInfoForLogin ( input : LoginInput ) {
101
102
const result = await this . db
102
103
. query ( )
103
- . raw (
104
- `
105
- MATCH
106
- (:EmailAddress {value: $email})
107
- <-[:email {active: true}]-
108
- (user:User)
109
- -[:password {active: true}]->
110
- (password:Property)
111
- RETURN
112
- password.value as pash
113
- ` ,
114
- {
115
- email : input . email ,
116
- } ,
117
- )
118
- . asResult < { pash : string } > ( )
104
+ . match ( [
105
+ [
106
+ node ( 'email' , 'EmailAddress' , {
107
+ value : input . email ,
108
+ } ) ,
109
+ relation ( 'in' , '' , 'email' , ACTIVE ) ,
110
+ node ( 'user' , 'User' ) ,
111
+ ] ,
112
+ [
113
+ node ( 'user' ) ,
114
+ relation ( 'out' , '' , 'password' , ACTIVE ) ,
115
+ node ( 'password' , 'Property' ) ,
116
+ ] ,
117
+ [
118
+ node ( 'user' ) ,
119
+ relation ( 'out' , '' , 'status' , ACTIVE ) ,
120
+ node ( 'status' , 'Property' ) ,
121
+ ] ,
122
+ ] )
123
+ . return < { passwordHash : string ; status : UserStatus } > ( [
124
+ 'password.value as passwordHash' ,
125
+ 'status.value as status' ,
126
+ ] )
119
127
. first ( ) ;
120
- return result ?. pash ?? null ;
128
+ return result ?? null ;
121
129
}
122
130
123
131
async connectSessionToUser ( input : LoginInput , session : Session ) {
@@ -352,6 +360,18 @@ export class AuthenticationRepository {
352
360
. run ( ) ;
353
361
}
354
362
363
+ async deactivateAllSessions ( user : ID < 'User' > ) {
364
+ await this . db
365
+ . query ( )
366
+ . match ( [
367
+ node ( 'user' , 'User' , { id : user } ) ,
368
+ relation ( 'out' , 'oldRel' , 'token' , ACTIVE ) ,
369
+ node ( 'token' , 'Token' ) ,
370
+ ] )
371
+ . setValues ( { 'oldRel.active' : false } )
372
+ . run ( ) ;
373
+ }
374
+
355
375
@OnIndex ( )
356
376
private createIndexes ( ) {
357
377
return [
0 commit comments