Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend-MECRED
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MECRED
Backend-MECRED
Commits
1558d5d3
Commit
1558d5d3
authored
8 months ago
by
Richard Fernando Heise Ferreira
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue-43/delete-reset-ticket-after-use' into 'develop'
issue
#43
: delete reset ticket after use See merge request
!38
parents
9c8c377b
a2bed0ac
Branches
Branches containing commit
No related tags found
1 merge request
!38
issue #43: delete reset ticket after use
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/db/schema/user-stats.schema.ts
+3
-3
3 additions, 3 deletions
src/db/schema/user-stats.schema.ts
src/routes/password.route.ts
+6
-13
6 additions, 13 deletions
src/routes/password.route.ts
src/services/password.service.ts
+9
-9
9 additions, 9 deletions
src/services/password.service.ts
with
18 additions
and
25 deletions
src/db/schema/user-stats.schema.ts
+
3
−
3
View file @
1558d5d3
import
{
integer
,
pgTable
,
serial
}
from
"
drizzle-orm/pg-core
"
;
import
{
integer
,
numeric
,
pgTable
,
serial
}
from
"
drizzle-orm/pg-core
"
;
import
{
createInsertSchema
,
createSelectSchema
}
from
"
drizzle-zod
"
;
import
{
createInsertSchema
,
createSelectSchema
}
from
"
drizzle-zod
"
;
import
type
{
z
}
from
"
zod
"
;
import
type
{
z
}
from
"
zod
"
;
...
@@ -6,9 +6,9 @@ const userStatsTable = pgTable('user_stats', {
...
@@ -6,9 +6,9 @@ const userStatsTable = pgTable('user_stats', {
id
:
serial
(
'
id
'
).
primaryKey
()
id
:
serial
(
'
id
'
).
primaryKey
()
.
unique
()
.
unique
()
.
notNull
(),
.
notNull
(),
score
:
integer
(
'
score
'
)
score
:
numeric
(
'
score
'
)
.
notNull
()
.
notNull
()
.
default
(
0
),
.
default
(
'
0.0
'
),
likes
:
integer
(
'
likes
'
).
notNull
()
likes
:
integer
(
'
likes
'
).
notNull
()
.
default
(
0
),
.
default
(
0
),
likes_received
:
integer
(
'
likes_received
'
).
notNull
()
likes_received
:
integer
(
'
likes_received
'
).
notNull
()
...
...
This diff is collapsed.
Click to expand it.
src/routes/password.route.ts
+
6
−
13
View file @
1558d5d3
...
@@ -27,14 +27,14 @@ export const passRouter = new Hono()
...
@@ -27,14 +27,14 @@ export const passRouter = new Hono()
if
(
user
==
null
)
if
(
user
==
null
)
throw
new
Error
();
throw
new
Error
();
le
t
resetTickets
=
await
passwordRecoveryService
.
findByUserId
(
user
.
id
)
cons
t
resetTickets
=
await
passwordRecoveryService
.
findByUserId
(
user
.
id
)
if
(
resetTickets
==
null
)
if
(
resetTickets
==
null
)
throw
new
Error
();
throw
new
Error
();
/*
/*
* Find reset ticket in database
* Find reset ticket in database
*/
*/
var
resetTicket
:
PasswordRecoveryModel
|
any
=
null
let
resetTicket
:
PasswordRecoveryModel
|
any
=
null
resetTickets
.
forEach
(
element
=>
{
resetTickets
.
forEach
(
element
=>
{
if
(
element
.
tokenHash
==
token
[
0
])
if
(
element
.
tokenHash
==
token
[
0
])
resetTicket
=
element
resetTicket
=
element
...
@@ -55,13 +55,7 @@ export const passRouter = new Hono()
...
@@ -55,13 +55,7 @@ export const passRouter = new Hono()
await
userService
.
update
(
user
)
await
userService
.
update
(
user
)
)
)
/*
await
passwordRecoveryService
.
delete
(
resetTicket
.
id
)
* Set this ticket as used and not valid
*/
resetTicket
.
validToken
=
false
;
resetTicket
.
tokenUsed
=
true
;
await
passwordRecoveryService
.
update
(
resetTicket
)
return
c
.
json
({
ret
})
return
c
.
json
({
ret
})
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -87,14 +81,13 @@ export const passRouter = new Hono()
...
@@ -87,14 +81,13 @@ export const passRouter = new Hono()
)
)
/*
/*
* When a ticket is generated, the last one is
set as invali
d
* When a ticket is generated, the last one is
delete
d
*/
*/
const
ticketList
=
await
passwordRecoveryService
.
findByUserId
(
user
.
id
)
const
ticketList
=
await
passwordRecoveryService
.
findByUserId
(
user
.
id
)
if
(
ticketList
?.
length
!=
0
){
if
(
ticketList
?.
length
!=
0
){
le
t
lastTicket
=
ticketList
!
[
ticketList
!
.
length
-
1
]
cons
t
lastTicket
=
ticketList
!
[
ticketList
!
.
length
-
1
]
if
(
lastTicket
.
validToken
){
if
(
lastTicket
.
validToken
){
lastTicket
.
validToken
=
false
await
passwordRecoveryService
.
delete
(
lastTicket
.
id
)
await
passwordRecoveryService
.
update
(
lastTicket
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/services/password.service.ts
+
9
−
9
View file @
1558d5d3
...
@@ -14,7 +14,7 @@ export class PasswordRecoveryService {
...
@@ -14,7 +14,7 @@ export class PasswordRecoveryService {
isNotValidTicket
(
resetTicket
:
PasswordRecoveryModel
):
boolean
{
isNotValidTicket
(
resetTicket
:
PasswordRecoveryModel
):
boolean
{
if
(
resetTicket
==
null
)
return
true
if
(
resetTicket
==
null
)
return
true
le
t
is_expired
:
boolean
=
Date
.
parse
(
resetTicket
.
expirationDate
)
<
Date
.
now
()
cons
t
is_expired
:
boolean
=
Date
.
parse
(
resetTicket
.
expirationDate
)
<
Date
.
now
()
if
(
!
resetTicket
.
validToken
||
is_expired
||
resetTicket
.
tokenUsed
)
if
(
!
resetTicket
.
validToken
||
is_expired
||
resetTicket
.
tokenUsed
)
return
true
return
true
return
false
return
false
...
@@ -36,13 +36,13 @@ export class PasswordRecoveryService {
...
@@ -36,13 +36,13 @@ export class PasswordRecoveryService {
emailTemplatePasswordRecovery
(
resetTicket
:
PasswordRecoveryModel
):
string
{
emailTemplatePasswordRecovery
(
resetTicket
:
PasswordRecoveryModel
):
string
{
le
t
recover_link
:
string
=
process
.
env
[
"
URL
"
]
+
'
/reset-password/
'
+
resetTicket
.
tokenHash
cons
t
recover_link
:
string
=
process
.
env
[
"
URL
"
]
+
'
/reset-password/
'
+
resetTicket
.
tokenHash
le
t
token_link
:
string
=
recover_link
+
"
?token=
"
+
resetTicket
.
tokenHash
cons
t
token_link
:
string
=
recover_link
+
"
?token=
"
+
resetTicket
.
tokenHash
le
t
expirationDate
=
new
Date
(
resetTicket
.
expirationDate
)
cons
t
expirationDate
=
new
Date
(
resetTicket
.
expirationDate
)
expirationDate
.
setHours
(
expirationDate
.
getHours
()
-
1
)
expirationDate
.
setHours
(
expirationDate
.
getHours
()
-
1
)
le
t
requestedDate
=
expirationDate
.
toLocaleString
(
'
pt-br
'
,
{
timeZone
:
'
America/Sao_Paulo
'
})
cons
t
requestedDate
=
expirationDate
.
toLocaleString
(
'
pt-br
'
,
{
timeZone
:
'
America/Sao_Paulo
'
})
le
t
text
=
`
cons
t
text
=
`
<head>
<head>
<style>
<style>
...
@@ -109,9 +109,9 @@ export class PasswordRecoveryService {
...
@@ -109,9 +109,9 @@ export class PasswordRecoveryService {
}*/
}*/
async
create
(
user
:
UserDto
,
tx
?:
db
):
Promise
<
PasswordRecoveryModel
>
{
async
create
(
user
:
UserDto
,
tx
?:
db
):
Promise
<
PasswordRecoveryModel
>
{
le
t
tokenExpirationDate
=
this
.
generateExpirationDate
()
cons
t
tokenExpirationDate
=
this
.
generateExpirationDate
()
le
t
newTokenHash
=
this
.
generateToken
(
user
?.
email
,
tokenExpirationDate
)
cons
t
newTokenHash
=
this
.
generateToken
(
user
?.
email
,
tokenExpirationDate
)
le
t
resetTicket
=
{
cons
t
resetTicket
=
{
userId
:
user
!
.
id
,
userId
:
user
!
.
id
,
tokenHash
:
newTokenHash
,
tokenHash
:
newTokenHash
,
expirationDate
:
tokenExpirationDate
,
expirationDate
:
tokenExpirationDate
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment