File tree Expand file tree Collapse file tree 4 files changed +111
-20
lines changed
Expand file tree Collapse file tree 4 files changed +111
-20
lines changed Original file line number Diff line number Diff line change @@ -76,15 +76,15 @@ git clone https://github.com/SystangoTechnologies/Koach.git
7676├── src # Source code
7777│ ├── modules # Module-specific controllers
7878│ │ ├── common # Contains common modules
79- │ │ │ ├─── home
79+ │ │ │ ├─── home
8080│ │ │ └─ index.js
8181│ │ ├── v1 # Version 1 of APIs
8282│ │ │ ├─ Auth
83- │ │ │ ├─ User
84- │ │ │ └─ index.js
83+ │ │ │ ├─ User
84+ │ │ │ └─ index.js
8585│ │ └─── v2 # Version 2 of APIs
8686│ │ ├─ Auth
87- │ │ ├─ User
87+ │ │ ├─ User
8888│ │ └─ index.js
8989│ ├── models # Mongoose models
9090│ └── middleware # Custom middleware
@@ -109,7 +109,7 @@ Prerequisite For Docker Configuration : Docker and docker compose must be instal
109109Steps to run app in docker container :
110110 1 . CD to project dir
111111 2 . Create build using cmd: $ docker-compose build
112- 3 . Start the server in daemon thread using cmd: $ docker-compose up -d
112+ 3 . Start the server in daemon thread using cmd: $ docker-compose up -d
113113 4 . Stop the server using cmd : $ docker-compose down
114114
115115## Documentation
@@ -135,6 +135,7 @@ The environment for the test cases are following-
135135[ Arpit Khandelwal] ( https://github.com/arpit-systango )
136136[ Anurag Vikram Singh] ( https://www.linkedin.com/in/anuragvikramsingh/ )
137137[ Vikas Patidar] ( https://www.linkedin.com/in/vikas-patidar-0106/ )
138+ [ Sparsh Pipley] ( https://www.linkedin.com/in/sparsh-pipley-6ab0b1a4/ )
138139
139140## License
140141MIT.
Original file line number Diff line number Diff line change @@ -237,3 +237,61 @@ export async function deleteUser(ctx) {
237237 ctx . status = constants . STATUS_CODE . INTERNAL_SERVER_ERROR_STATUS
238238 }
239239}
240+
241+ /**
242+ * @api {patch } /v1/users/_change-password Upadete password of a user
243+ * @apiPermission
244+ * @apiVersion 1.0.0
245+ * @apiName changePassword
246+ * @apiGroup Users
247+ *
248+ * @apiExample Example usage:
249+ * curl -H "Content-Type: application/json" -X PATCH -d '{ "oldPassword":"oldPassword", "newPassword": "newPassword" }' localhost:3000/v1/users/_changePassword
250+ *
251+ * @apiSuccess {StatusCode} 200
252+ *
253+ * @apiSuccessExample {json} Success-Response:
254+ * HTTP/1.1 200 OK
255+ * {
256+ * "success": true
257+ * }
258+ *
259+ * @apiUse TokenError
260+ */
261+
262+ export async function changePassword ( ctx ) {
263+ try {
264+ let oldPassword = ctx . request . body . oldPassword
265+ let newPassword = ctx . request . body . newPassword
266+
267+ if ( ! newPassword || ! oldPassword ) {
268+ ctx . status = constants . STATUS_CODE . BAD_REQUEST_ERROR_STATUS
269+ return
270+ }
271+
272+ let user = await User . findOne ( {
273+ _id : mongoose . Types . ObjectId ( ctx . state . user . id )
274+ } )
275+
276+ let isMatch = await user . validatePassword ( oldPassword )
277+
278+ if ( isMatch ) {
279+ user . password = newPassword
280+ user . save ( ) ;
281+ ctx . status = constants . STATUS_CODE . SUCCESS_STATUS ;
282+ ctx . body = {
283+ success : true
284+ }
285+ return
286+ } else {
287+ ctx . body = {
288+ success : false
289+ }
290+ ctx . status = constants . STATUS_CODE . UNAUTHORIZED_ERROR_STATUS
291+ return
292+ }
293+ } catch ( error ) {
294+ ctx . body = error ;
295+ ctx . status = constants . STATUS_CODE . INTERNAL_SERVER_ERROR_STATUS
296+ }
297+ }
Original file line number Diff line number Diff line change @@ -42,5 +42,13 @@ export default [
4242 ensureUser ,
4343 user . deleteUser
4444 ]
45+ } ,
46+ {
47+ method : 'PATCH' ,
48+ route : '/_change-password' ,
49+ handlers : [
50+ ensureUser ,
51+ user . changePassword
52+ ]
4553 }
4654]
You can’t perform that action at this time.
0 commit comments