Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2930f2

Browse files
committed
Implemented delete user functionaility. TODO testing
1 parent5fa1862 commitb2930f2

File tree

4 files changed

+89
-18
lines changed

4 files changed

+89
-18
lines changed

‎frontend/client/views/settings/index.vue‎

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</td>
2323
<td>
2424
<av-on:click="editUserModal(props.row)"><iclass="fa fa-edit"style="color:whitesmoke;"></i></a>
25-
<av-on:click="deleteUser(props.row)"><iclass="fa fa-trash"style="color:whitesmoke;"></i></a>
25+
<av-on:click="deleteUserModal(props.row)"><iclass="fa fa-trash"style="color:whitesmoke;"></i></a>
2626
</td>
2727
</template>
2828
<divslot="emptystate"class="empty-table-text">
@@ -38,26 +38,26 @@
3838

3939
<!-- edit user modal-->
4040
<modal:visible="showEditUserModal"class="modal-z-index"@close="close">
41-
<divclass="boxedit-user-modal">
41+
<divclass="box user-modal">
4242
<divclass="block edit-user-modal-content">
4343
<collapseaccordionis-fullwidth>
4444
<collapse-itemtitle="Change Password"selected>
4545
<divclass="edit-user-modal-content">
46-
<labelclass="label"style="text-align:left;">Change password for user {{editUser.display_name }}:</label>
46+
<labelclass="label"style="text-align:left;">Change password for user {{selectUser.display_name }}:</label>
4747
<pclass="control has-icons-left"style="padding-bottom:5px;">
48-
<inputclass="input is-medium input-bar"v-focustype="password"v-model="editUser.oldpassword"placeholder="Old Password">
48+
<inputclass="input is-medium input-bar"v-focustype="password"v-model="selectUser.oldpassword"placeholder="Old Password">
4949
<spanclass="icon is-small is-left">
5050
<iclass="fa fa-lock"></i>
5151
</span>
5252
</p>
5353
<pclass="control has-icons-left">
54-
<inputclass="input is-medium input-bar"type="password"v-model="editUser.newpassword"placeholder="New Password">
54+
<inputclass="input is-medium input-bar"type="password"v-model="selectUser.newpassword"placeholder="New Password">
5555
<spanclass="icon is-small is-left">
5656
<iclass="fa fa-lock"></i>
5757
</span>
5858
</p>
5959
<pclass="control has-icons-left">
60-
<inputclass="input is-medium input-bar"type="password"v-model="editUser.newpasswordconf"placeholder="New Password confirmation">
60+
<inputclass="input is-medium input-bar"type="password"v-model="selectUser.newpasswordconf"placeholder="New Password confirmation">
6161
<spanclass="icon is-small is-left">
6262
<iclass="fa fa-lock"></i>
6363
</span>
@@ -76,6 +76,29 @@
7676
</div>
7777
</div>
7878
</modal>
79+
80+
<!-- delete user modal-->
81+
<modal:visible="showDeleteUserModal"class="modal-z-index"@close="close">
82+
<divclass="box user-modal">
83+
<articleclass="media">
84+
<divclass="media-content">
85+
<divclass="content">
86+
<p>
87+
<spanstyle="color:whitesmoke;">Do you really want to delete the user {{ selectUser.display_name }}?</span>
88+
</p>
89+
</div>
90+
<divclass="modal-footer">
91+
<divstyle="float:left;">
92+
<buttonclass="button is-primary"v-on:click="deleteUser"style="width:150px;">Yes</button>
93+
</div>
94+
<divstyle="float:right;">
95+
<buttonclass="button is-danger"v-on:click="cancel"style="width:130px;">No</button>
96+
</div>
97+
</div>
98+
</div>
99+
</article>
100+
</div>
101+
</modal>
79102
</div>
80103
</template>
81104

@@ -132,8 +155,9 @@ export default {
132155
}
133156
],
134157
userRows: [],
135-
editUser: [],
136-
showEditUserModal:false
158+
selectUser: [],
159+
showEditUserModal:false,
160+
showDeleteUserModal:false
137161
}
138162
},
139163
@@ -164,31 +188,33 @@ export default {
164188
},
165189
166190
editUserModal (user) {
167-
this.editUser= user
191+
this.selectUser= user
168192
this.showEditUserModal=true
169193
},
170194
171-
deleteUser (user) {
172-
console.log('TODO')
195+
deleteUserModal (user) {
196+
this.selectUser= user
197+
this.showDeleteUserModal=true
173198
},
174199
175200
close () {
176201
this.showEditUserModal=false
202+
this.showDeleteUserModal=false
177203
this.$emit('close')
178204
},
179205
180206
cancel () {
181207
// cancel means reset all stuff
182-
this.editUser.oldpassword=''
183-
this.editUser.newpassword=''
184-
this.editUser.newpasswordconf=''
208+
this.selectUser.oldpassword=''
209+
this.selectUser.newpassword=''
210+
this.selectUser.newpasswordconf=''
185211
186212
this.close()
187213
},
188214
189215
changePassword () {
190216
// pre-validate
191-
if (this.editUser.newpassword===''||this.editUser.newpasswordconf==='') {
217+
if (this.selectUser.newpassword===''||this.selectUser.newpasswordconf==='') {
192218
openNotification({
193219
title:'Empty password',
194220
message:'Empty password is not allowed.',
@@ -199,7 +225,7 @@ export default {
199225
}
200226
201227
this.$http
202-
.post('/api/v1/user/password',this.editUser)
228+
.post('/api/v1/user/password',this.selectUser)
203229
.then(response=> {
204230
openNotification({
205231
title:'Password changed!',
@@ -212,6 +238,22 @@ export default {
212238
})
213239
this.close()
214240
}
241+
},
242+
243+
deleteUser () {
244+
this.$http
245+
.delete('/api/v1/user',this.selectUser)
246+
.then(response=> {
247+
openNotification({
248+
title:'User deleted!',
249+
message:'User'+this.selectUser.display_name+' has been successfully deleted.',
250+
type:'success'
251+
})
252+
})
253+
.catch((error)=> {
254+
this.$onError(error)
255+
})
256+
this.close()
215257
}
216258
}
217259
</script>
@@ -232,7 +274,7 @@ export default {
232274
border-bottom-color:#4da2fc!important;
233275
}
234276
235-
.edit-user-modal {
277+
.user-modal {
236278
text-align:center;
237279
background-color:#2a2735;
238280
}
@@ -243,7 +285,7 @@ export default {
243285
}
244286
245287
.modal-footer {
246-
height:35px;
288+
height:45px;
247289
padding-top:15px;
248290
}
249291

‎handlers/User.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,20 @@ func UserChangePassword(c echo.Context) error {
118118

119119
returnc.String(http.StatusOK,"Password has been changed")
120120
}
121+
122+
// UserDelete deletes the given user
123+
funcUserDelete(c echo.Context)error {
124+
// Get user which we should delete
125+
u:=&gaia.User{}
126+
iferr:=c.Bind(u);err!=nil {
127+
returnc.String(http.StatusBadRequest,"Invalid parameters given for delete user request")
128+
}
129+
130+
// Delete user
131+
err:=storeService.UserDelete(u)
132+
iferr!=nil {
133+
c.String(http.StatusNotFound,"Cannot delete user with the given username")
134+
}
135+
136+
returnc.String(http.StatusOK,"user has been deleted")
137+
}

‎handlers/handler.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func InitHandlers(e *echo.Echo, store *store.Store, scheduler *scheduler.Schedul
7070
e.POST(p+"login",UserLogin)
7171
e.GET(p+"users",UserGetAll)
7272
e.POST(p+"user/password",UserChangePassword)
73+
e.DELETE(p+"user",UserDelete)
7374

7475
// Pipelines
7576
e.POST(p+"pipeline",CreatePipeline)

‎store/user.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,14 @@ func (s *Store) UserGetAll() ([]gaia.User, error) {
128128
})
129129
})
130130
}
131+
132+
// UserDelete deletes the given user.
133+
func (s*Store)UserDelete(u*gaia.User)error {
134+
returns.db.Update(func(tx*bolt.Tx)error {
135+
// Get bucket
136+
b:=tx.Bucket(userBucket)
137+
138+
// Delete user
139+
returnb.Delete([]byte(u.Username))
140+
})
141+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp