Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
repp_backend
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Julieta Dubra Raimunde
repp_backend
Commits
7e605dcb
Commit
7e605dcb
authored
3 years ago
by
Ignacio Bengoa Nion
Browse files
Options
Downloads
Patches
Plain Diff
Mailing (fully?) implemented
parent
4cc4b74f
Branches
feature/Mailing
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Controllers/UserController.ts
+60
-11
60 additions, 11 deletions
src/Controllers/UserController.ts
src/Services/UserAPI.ts
+36
-6
36 additions, 6 deletions
src/Services/UserAPI.ts
with
96 additions
and
17 deletions
src/Controllers/UserController.ts
+
60
−
11
View file @
7e605dcb
...
...
@@ -53,16 +53,17 @@ const update: Handler = async (req: Request, res: Response) => {
}
};
const
password
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
token
:
any
=
req
.
headers
.
authorization
;
const
user
:
any
=
await
UserAPI
.
password
(
req
.
body
,
req
.
params
.
id
,
token
);
return
logAndRespond
(
res
,
200
,
'
send
'
,
user
,
'
info
'
,
null
,
null
);
}
catch
(
error
)
{
const
e
=
error
as
AxiosError
;
return
logAndRespond
(
res
,
e
.
response
?
e
.
response
.
status
:
400
,
'
json
'
,
e
.
response
?
e
.
response
.
data
:
{
error
:
e
.
message
},
'
info
'
,
null
,
null
);
}
};
// const password: Handler = async (req: Request, res: Response) => {
// try {
// const token: any = req.headers.authorization;
// const user: any = await UserAPI.password(req.body, req.params.id, token);
// return logAndRespond(res, 200, 'send', user, 'info', null, null);
// } catch (error) {
// const e = error as AxiosError;
// return logAndRespond(res, e.response ? e.response.status : 400, 'json',
// e.response ? e.response.data : { error: e.message }, 'info', null, null);
// }
// };
const
approve
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
...
...
@@ -130,16 +131,64 @@ const getUser: Handler = async (req: Request, res: Response) => {
}
};
const
verifyEmail
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
token
=
String
(
req
.
query
.
token
);
const
response
:
any
=
await
UserAPI
.
verifyEmail
(
token
);
return
logAndRespond
(
res
,
200
,
'
send
'
,
response
,
'
info
'
,
null
,
null
);
}
catch
(
error
)
{
const
e
=
error
as
AxiosError
;
return
logAndRespond
(
res
,
e
.
response
?
e
.
response
.
status
:
400
,
'
json
'
,
e
.
response
?
e
.
response
.
data
:
{
error
:
e
.
message
},
'
info
'
,
null
,
null
);
}
};
const
recoveryPasswordChange
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
{
token
,
password
,
repeat
}
=
req
.
body
;
const
response
:
any
=
await
UserAPI
.
recoveryPasswordChange
(
token
,
password
,
repeat
);
return
logAndRespond
(
res
,
200
,
'
send
'
,
response
,
'
info
'
,
null
,
null
);
}
catch
(
error
)
{
const
e
=
error
as
AxiosError
;
return
logAndRespond
(
res
,
e
.
response
?
e
.
response
.
status
:
400
,
'
json
'
,
e
.
response
?
e
.
response
.
data
:
{
error
:
e
.
message
},
'
info
'
,
null
,
null
);
}
};
const
resendVerification
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
{
email
}
=
req
.
body
;
const
response
:
any
=
await
UserAPI
.
resendVerification
(
email
);
return
logAndRespond
(
res
,
200
,
'
send
'
,
response
,
'
info
'
,
null
,
null
);
}
catch
(
error
)
{
const
e
=
error
as
AxiosError
;
return
logAndRespond
(
res
,
e
.
response
?
e
.
response
.
status
:
400
,
'
json
'
,
e
.
response
?
e
.
response
.
data
:
{
error
:
e
.
message
},
'
info
'
,
null
,
null
);
}
};
const
recoverPassword
:
Handler
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
{
email
}
=
req
.
body
;
const
response
:
any
=
await
UserAPI
.
recoverPassword
(
email
);
return
logAndRespond
(
res
,
200
,
'
send
'
,
response
,
'
info
'
,
null
,
null
);
}
catch
(
error
)
{
const
e
=
error
as
AxiosError
;
return
logAndRespond
(
res
,
e
.
response
?
e
.
response
.
status
:
400
,
'
json
'
,
e
.
response
?
e
.
response
.
data
:
{
error
:
e
.
message
},
'
info
'
,
null
,
null
);
}
};
router
.
post
(
'
/
'
,
create
);
router
.
get
(
'
/
'
,
listUsers
);
router
.
post
(
'
/login
'
,
login
);
router
.
put
(
'
/verify-email
'
,
verifyEmail
);
router
.
put
(
'
/password
'
,
recoveryPasswordChange
);
router
.
put
(
'
/:id
'
,
update
);
router
.
put
(
'
/:id/password
'
,
password
);
//
router.put('/:id/password', password);
router
.
put
(
'
/:id/approve
'
,
approve
);
router
.
put
(
'
/:id/cancel
'
,
cancel
);
router
.
put
(
'
/:id/admin
'
,
giveAdminPermission
);
router
.
put
(
'
/:id/client
'
,
removeAdminPermission
);
router
.
post
(
'
/check-user
'
,
checkUser
);
router
.
get
(
'
/:id
'
,
getUser
);
router
.
post
(
'
/resend-verification
'
,
resendVerification
);
router
.
post
(
'
/recover-password
'
,
recoverPassword
);
export
default
router
;
This diff is collapsed.
Click to expand it.
src/Services/UserAPI.ts
+
36
−
6
View file @
7e605dcb
...
...
@@ -46,11 +46,11 @@ const update = async (user: any, idUser: string, token: string) => {
return
res
.
data
;
};
const
password
=
async
(
user
:
any
,
idUser
:
string
,
token
:
string
)
=>
{
const
url
=
`/
${
idUser
}
/password`
;
const
res
=
await
instance
.
put
(
url
,
user
,
{
headers
:
{
authorization
:
token
}
});
return
res
.
data
;
};
//
const password = async (user: any, idUser: string, token: string) => {
//
const url = `/${idUser}/password`;
//
const res = await instance.put(url, user, { headers: { authorization: token } });
//
return res.data;
//
};
const
approve
=
async
(
idUser
:
string
,
token
:
string
)
=>
{
const
url
=
`/
${
idUser
}
/approve`
;
...
...
@@ -94,16 +94,46 @@ const getUser = async (userId: number, token: string) => {
return
res
.
data
;
};
const
verifyEmail
=
async
(
userToken
:
string
)
=>
{
const
url
=
'
/verify-email
'
;
const
res
=
await
instance
.
put
(
url
,
{},
{
params
:
{
token
:
userToken
}
});
return
res
.
data
;
};
const
resendVerification
=
async
(
userEmail
:
string
)
=>
{
const
url
=
'
/resend-verification
'
;
const
res
=
await
instance
.
post
(
url
,
{
email
:
userEmail
});
return
res
.
data
;
};
const
recoverPassword
=
async
(
userEmail
:
string
)
=>
{
const
url
=
'
/recover-password
'
;
const
res
=
await
instance
.
post
(
url
,
{
email
:
userEmail
});
return
res
.
data
;
};
const
recoveryPasswordChange
=
async
(
userToken
:
string
,
userPassword
:
string
,
userRepeat
:
string
)
=>
{
const
url
=
'
/password
'
;
const
res
=
await
instance
.
put
(
url
,
{
token
:
userToken
,
password
:
userPassword
,
repeat
:
userRepeat
});
return
res
.
data
;
};
export
default
{
create
,
login
,
listUsers
,
update
,
password
,
//
password,
approve
,
cancel
,
giveAdminPermission
,
removeAdminPermission
,
listUsersById
,
getUser
,
verifyEmail
,
resendVerification
,
recoverPassword
,
recoveryPasswordChange
,
};
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