Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Евгений Положенцев
planner-team-one
Commits
33a7f579
Commit
33a7f579
authored
Dec 02, 2022
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#84
added change password end points
parent
1721c38d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
38 deletions
+70
-38
.env
.env
+0
-1
helpers.ts
planner-api/src/helpers.ts
+9
-5
PasswordRecovery.ts
planner-api/src/models/PasswordRecovery.ts
+6
-4
Task.ts
planner-api/src/models/Task.ts
+1
-1
User.ts
planner-api/src/models/User.ts
+2
-4
passwordRecovery.ts
planner-api/src/routers/passwordRecovery.ts
+51
-22
server.ts
planner-api/src/server.ts
+1
-1
No files found.
.env
deleted
100644 → 0
View file @
1721c38d
export const FRONTEND_URL = 'localhost:3000'
\ No newline at end of file
planner-api/src/helpers.ts
View file @
33a7f579
...
...
@@ -82,12 +82,16 @@ export const taskFinderById = async (taskId:string):Promise<null | Task>=>{
export
let
transporter
=
nodemailer
.
createTransport
({
host
:
"smtp.yandex.ru"
,
port
:
465
,
secure
:
true
,
// true for 465, false for other ports
service
:
'Yandex'
,
// host: "smtp.yandex.ru",
// port: 465,
// secure: true, // true for 465, false for other ports
auth
:
{
user
:
"planner45"
,
// generated ethereal user
user
:
"planner45
@yandex.ru
"
,
// generated ethereal user
pass
:
"newPlannerProject123"
// generated ethereal password
}
})
export
const
FRONTEND_URL
=
'localhost:3000'
\ No newline at end of file
planner-api/src/models/PasswordRecovery.ts
View file @
33a7f579
...
...
@@ -5,6 +5,7 @@ import {
BaseEntity
,
OneToOne
,
CreateDateColumn
,
JoinColumn
,
}
from
'typeorm'
;
import
{
User
}
from
'./User'
;
...
...
@@ -23,13 +24,14 @@ import { User } from './User';
@
CreateDateColumn
({
name
:
'created_at'
,
type
:
Date
,
default
:
new
Date
()
})
createdAt
!
:
Date
;
@
Column
({
name
:
'token'
,
type
:
String
,
nullable
:
false
})
@
Column
({
name
:
'token'
,
type
:
'varchar'
,
length
:
100
,
unique
:
true
,
nullable
:
true
})
token
!
:
string
;
@
OneToOne
(()
=>
User
,
(
user
:{
passwordRecovery
:
PasswordRecovery
})
=>
user
.
passwordRecovery
)
@
OneToOne
(()
=>
User
,{
nullable
:
false
,
eager
:
true
})
@
JoinColumn
()
user
!
:
User
;
@
Column
({
name
:
'enabled'
,
type
:
'boolean'
,
default
:
fals
e
})
@
Column
({
name
:
'enabled'
,
type
:
'boolean'
,
default
:
tru
e
})
enabled
!
:
boolean
;
}
\ No newline at end of file
planner-api/src/models/Task.ts
View file @
33a7f579
...
...
@@ -50,7 +50,7 @@ import { DateTimeTask } from './DateTimeTask';
dateTimeDeadLine
!
:
Date
;
@
Column
({
name
:
'dateTimeFactDeadLine'
,
type
:
Date
,
nullable
:
true
})
dateTimeFactDeadLine
!
:
Date
;
@
Column
({
name
:
'archive'
,
type
:
'
varchar'
,
length
:
50
,
nullable
:
false
,
default
:
false
})
@
Column
({
name
:
'archive'
,
type
:
'
boolean'
,
nullable
:
false
,
default
:
false
})
archive
!
:
boolean
@
Column
({
...
...
planner-api/src/models/User.ts
View file @
33a7f579
...
...
@@ -17,7 +17,7 @@ import {Task} from './Task';
import
{
Member
}
from
'./Member'
;
import
{
PasswordRecovery
}
from
'./PasswordRecovery'
;
const
SALT_WORK_FACTOR
=
10
;
export
const
SALT_WORK_FACTOR
=
10
;
export
enum
UserRole
{
USER
=
"user"
,
DIRECTOR
=
"director"
,
SUPERUSER
=
"superuser"
}
...
...
@@ -34,7 +34,6 @@ interface IUser {
createdAt
:
Date
;
createdTasks
:
Task
[];
members
:
Member
[];
passwordRecovery
:
PasswordRecovery
;
}
...
...
@@ -84,8 +83,7 @@ export class User extends BaseEntity implements IUser {
@
OneToMany
(()
=>
Member
,
(
member
:
{
user
:
User
})
=>
member
.
user
)
members
!
:
Member
[];
@
OneToOne
(()
=>
PasswordRecovery
,
(
passwordRecovery
:{
user
:
User
})
=>
passwordRecovery
.
user
)
passwordRecovery
!
:
PasswordRecovery
;
@
BeforeInsert
()
protected
async
beforeInserthashPassword
():
Promise
<
void
>
{
...
...
planner-api/src/routers/passwordRecovery.ts
View file @
33a7f579
...
...
@@ -4,7 +4,9 @@ import {myDataSource} from '../app-data-source';
import
{
nanoid
}
from
'nanoid'
;
import
{
PasswordRecovery
}
from
'../models/PasswordRecovery'
;
import
{
transporter
}
from
'../helpers'
;
import
{
FRONTEND_URL
}
from
"../helpers"
;
import
{
SALT_WORK_FACTOR
}
from
"../models/User"
;
import
bcrypt
from
'bcrypt'
;
const
router
:
Router
=
express
.
Router
();
const
dataSource
=
myDataSource
;
...
...
@@ -21,12 +23,12 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
const
token
=
nanoid
();
const
url
=
`
${
process
.
env
.
FRONTEND_URL
}
/reset-password/
${
token
}
`
;
try
{
const
passwordRecovery
=
await
new
PasswordRecovery
()
passwordRecovery
.
user
=
user
passwordRecovery
.
token
=
token
passwordRecovery
.
save
()
const
passwordRecovery
=
new
PasswordRecovery
()
passwordRecovery
.
user
=
user
;
passwordRecovery
.
token
=
token
;
await
passwordRecovery
.
save
()
const
url
=
`
${
FRONTEND_URL
}
/reset-password/
${
token
}
`
;
await
transporter
.
sendMail
({
from
:
"planner45@yandex.com"
,
to
:
`
${
email
}
`
,
...
...
@@ -34,27 +36,54 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
text
:
`Вы отправили запрос на восстановление пароля,
перейдите по ссылке плз:{url}`
,
html
:
`Вы отправили запрос на восстановление пароля,
перейдите по ссылке плз: <br><a> href="
${
url
}
">
${
url
}
</a>`
});
return
res
.
send
({
message
:
'Email succeffuly send'
})
перейдите по ссылке плз: <br><a> href="
${
url
}
">
${
url
}
</a>`
});
return
res
.
send
({
message
:
'Email succe
ss
ffuly send'
})
}
catch
(
e
){
console
.
log
(
e
)
res
.
status
(
502
).
send
({
message
:
'mail got stuck
'
})
res
.
status
(
502
).
send
({
message
:
'mail got stuck
in '
,
e
})
}
})
/**validate token t*/
router
.
get
(
"/validate"
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
>=>
{
/**reset token in password recovery */
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
const
token
=
req
.
query
.
token
;
// if (!token) return res.send({message:'token is not valid'})
// const passwordRecovery = await dataSource
// .getRepository(PasswordRecovery)
// .findOne({
// where:{
// token: token
// }
// })
// if (!passwordRecovery) return res.send({message:'link is not valid'})
return
res
.
send
(
token
);
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
const
passwordRecovery
=
await
dataSource
.
createQueryBuilder
()
.
from
(
PasswordRecovery
,
'passwordRecovery'
)
.
select
(
'passwordRecovery'
)
.
innerJoinAndSelect
(
'passwordRecovery.user'
,
'user'
)
.
where
(
' passwordRecovery.token=:token'
,{
token
})
.
getOne
()
if
(
!
passwordRecovery
||
!
passwordRecovery
.
enabled
)
return
res
.
status
(
404
).
send
({
message
:
"Token is not valid"
})
res
.
send
(
passwordRecovery
)
passwordRecovery
.
enabled
=
false
;
try
{
await
passwordRecovery
.
save
();
}
catch
(
e
){
console
.
log
(
e
)
}
})
/**change password */
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
const
user
=
await
dataSource
.
getRepository
(
User
)
.
findOneBy
({
id
:
req
.
params
.
id
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
Message
:
'user not found'
})
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
let
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
user
.
password
=
newPassword
try
{
await
user
.
save
()
res
.
send
({
message
:
"Password saved"
})
}
catch
(
e
){
res
.
status
(
502
).
send
({
message
:
"error in saving new psasword"
})
}
})
export
default
router
;
\ No newline at end of file
export
default
router
;
\ No newline at end of file
planner-api/src/server.ts
View file @
33a7f579
...
...
@@ -5,7 +5,7 @@ import tasks from './routers/tasks';
import
projects
from
'./routers/projects'
;
import
{
myDataSource
}
from
'./app-data-source'
;
import
copyTasks
from
'./routers/copyTasks'
;
import
passwordRe
v
import
passwordRe
covery
from
'./routers/passwordRecovery'
;
myDataSource
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment