Skip to content

Commit

Permalink
feat: 密码修改样式优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Nov 15, 2022
1 parent 3eb4862 commit 21938a9
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 193 deletions.
6 changes: 3 additions & 3 deletions internal/api/v1/user/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import v1User "github.com/KubeOperator/kubepi/internal/model/v1/user"

type User struct {
v1User.User
Roles []string `json:"roles"`
Password string `json:"password"`
Roles []string `json:"roles"`
OldPassword string `json:"oldPassword"`
Password string `json:"password"`
}

4 changes: 2 additions & 2 deletions internal/api/v1/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ func (h *Handler) UpdateUser() iris.Handler {
return
}
if req.Password != "" {
if err := h.userService.ResetPassword(userName, req.Password, common.DBOptions{}); err != nil {
if err := h.userService.UpdatePassword(userName, req.OldPassword, req.Password, common.DBOptions{}); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Values().Set("message", err.Error())
ctx.Values().Set("message", "can not match original password")
return
}
ctx.Values().Set("data", "ok")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<el-dropdown-item style="text-align: center" command="profile">
{{ $t("commons.personal.profile") }}
</el-dropdown-item>
<el-dropdown-item style="text-align: center" command="password">
{{ $t("business.user.change_password") }}
</el-dropdown-item>


<el-dropdown-item style="text-align: center" divided command="exit">
Expand All @@ -27,7 +30,8 @@ export default {
name: "UserSetting",
computed: {
...mapGetters([
"nickName"
"nickName",
"name"
])
},
methods: {
Expand All @@ -39,6 +43,9 @@ export default {
case "profile":
this.$router.push("/profile")
break
case "password":
this.$router.push({name: "UserPassword", params: {name: this.name}})
break
default:
this.aboutDialogVisible = true
break
Expand Down
101 changes: 1 addition & 100 deletions web/kubepi/src/business/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
<span v-if="editModeOpened"><el-input v-model="profileForm.email"></el-input></span>
</el-form-item>

<el-form-item :label="$t('business.user.password')">
<el-link @click="openPasswordChange">{{ $t('business.user.change_password') }}</el-link>
</el-form-item>

<el-form-item>
<div style="float: right">
<el-button v-if="!editModeOpened" @click="onEditProfile">{{ $t("commons.button.edit") }}</el-button>
Expand All @@ -36,75 +32,27 @@
</div>
</el-form-item>
</el-form>

</div>
</el-col>
<el-col :span="4"><br/></el-col>
</el-row>

<el-dialog
:title="$t('business.user.change_password')"
:visible.sync="changePasswordOpened"
:close-on-click-modal="false"
width="30%">
<div>
<el-form :rules="passwordChangeRules" ref="passwordChangeFrom" :model="passwordChangeFrom" label-width="150px"
label-position="left">
<el-form-item :label="$t('business.user.old_password')" prop="oldPassword">
<el-input type="password" v-model="passwordChangeFrom.oldPassword"></el-input>
</el-form-item>
<el-form-item :label="$t('business.user.new_password')" prop="newPassword">
<el-input type="password" v-model="passwordChangeFrom.newPassword"></el-input>
</el-form-item>
<el-form-item :label="$t('business.user.confirm_password')" prop="confirmPassword">
<el-input type="password" v-model="passwordChangeFrom.confirmPassword"></el-input>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="changePasswordOpened = false">{{ $t("commons.button.cancel") }}</el-button>
<el-button type="primary" @click="onChangePasswordConfirm">{{ $t("commons.button.confirm") }}</el-button>
</span>
</el-dialog>


</layout-content>
</template>

<script>
import LayoutContent from "@/components/layout/LayoutContent"
import {getCurrentUser, updateProfile, updatePassword,} from "@/api/auth"
import {getCurrentUser, updateProfile} from "@/api/auth"
import Rules from "@/utils/rules"
export default {
name: "UserProfile",
components: {LayoutContent},
data() {
var validatePass = (rule, value, callback) => {
if (value === '') {
callback(new Error(this.$t('business.user.please_input_password')));
} else {
if (this.passwordChangeFrom.newPassword !== '') {
this.$refs.passwordChangeFrom.validateField('checkPass');
}
callback();
}
};
var validatePass2 = (rule, value, callback) => {
if (value === '') {
callback(new Error(this.$t('business.user.please_input_password')));
} else if (value !== this.passwordChangeFrom.newPassword) {
callback(new Error(this.$t('business.user.password_not_equal')));
} else {
callback();
}
};
return {
loading: false,
isSubmitGoing: false,
roleOptions: [],
editModeOpened: false,
changePasswordOpened: false,
profileForm: {
name: "",
nickname: "",
Expand All @@ -119,30 +67,9 @@ export default {
Rules.EmailRule
],
},
passwordChangeFrom: {
oldPassword: "",
newPassword: "",
confirmPassword: ""
},
passwordChangeRules: {
oldPassword: [
Rules.RequiredRule
],
newPassword: [
Rules.RequiredRule,
Rules.PasswordRule,
{validator: validatePass, trigger: 'blur'},
],
confirmPassword: [
Rules.RequiredRule,
Rules.PasswordRule,
{validator: validatePass2, trigger: 'blur'}
]
}
}
},
methods: {
onConfirm() {
if (this.isSubmitGoing) {
return
Expand All @@ -163,7 +90,6 @@ export default {
this.loading = false
this.editModeOpened = false
this.$message.success(this.$t('commons.msg.update_success'))
// 修改vuex
window.location.reload()
})
Expand All @@ -175,30 +101,6 @@ export default {
this.editModeOpened = false
this.onVueCreated()
},
openPasswordChange() {
this.passwordChangeFrom.newPassword = ""
this.passwordChangeFrom.oldPassword = ""
this.changePasswordOpened = true
},
onChangePasswordConfirm() {
let isFormReady = false
this.$refs["passwordChangeFrom"].validate((valid) => {
if (valid) {
isFormReady = true
}
})
if (!isFormReady) {
return
}
updatePassword({
"oldPassword": this.passwordChangeFrom.oldPassword,
"newPassword": this.passwordChangeFrom.newPassword
}).then(() => {
this.$message.success(this.$t('commons.msg.update_success'))
this.changePasswordOpened = false
})
},
onVueCreated() {
getCurrentUser().then(data => {
this.profileForm.name = data.data.name
Expand All @@ -208,7 +110,6 @@ export default {
}
},
created() {
this.onVueCreated()
}
Expand Down
84 changes: 0 additions & 84 deletions web/kubepi/src/business/user-management/user/edit/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('business.user.password')" v-if="form.type !=='LDAP'">
<el-link @click="openedChangePassword">{{ $t("business.user.change_password") }}</el-link>
</el-form-item>
<el-form-item :label="$t('commons.table.mfa_enable')" prop="mfa.enable">
<el-checkbox v-model="form.mfa.enable">{{ $t("commons.enable.true") }}</el-checkbox>
</el-form-item>
Expand All @@ -46,31 +43,6 @@
</el-col>
<el-col :span="4"><br/></el-col>
</el-row>


<el-dialog
:title="$t('business.user.change_password')"
:visible.sync="changePasswordOpened"
:close-on-click-modal="false"
width="30%">
<div>
<el-form :rules="passwordChangeRules" ref="passwordChangeFrom" :model="passwordChangeFrom" label-width="150px"
label-position="left">
<el-form-item :label="$t('business.user.new_password')" prop="newPassword">
<el-input type="password" v-model="passwordChangeFrom.newPassword"></el-input>
</el-form-item>
<el-form-item :label="$t('business.user.confirm_password')" prop="confirmPassword">
<el-input type="password" v-model="passwordChangeFrom.confirmPassword"></el-input>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="changePasswordOpened = false">{{ $t("commons.button.cancel") }}</el-button>
<el-button type="primary" @click="onChangePasswordConfirm">{{ $t("commons.button.confirm") }}</el-button>
</span>
</el-dialog>


</layout-content>
</template>

Expand All @@ -86,25 +58,6 @@ export default {
props: ["name"],
components: { LayoutContent },
data () {
var validatePass = (rule, value, callback) => {
if (value === "") {
callback(new Error(this.$t("business.user.please_input_password")))
} else {
if (this.passwordChangeFrom.newPassword !== "") {
this.$refs.form.validateField("checkPass")
}
callback()
}
}
var validatePass2 = (rule, value, callback) => {
if (value === "") {
callback(new Error(this.$t("business.user.please_input_password")))
} else if (value !== this.passwordChangeFrom.newPassword) {
callback(new Error(this.$t("business.user.password_not_equal")))
} else {
callback()
}
}
return {
loading: false,
isSubmitGoing: false,
Expand All @@ -128,23 +81,6 @@ export default {
// enable:Rules.RequiredRule,
}
},
changePasswordOpened: false,
passwordChangeRules: {
newPassword: [
Rules.RequiredRule,
Rules.PasswordRule,
{ validator: validatePass, trigger: "blur" },
],
confirmPassword: [
Rules.RequiredRule,
Rules.PasswordRule,
{ validator: validatePass2, trigger: "blur" }
],
},
passwordChangeFrom: {
newPassword: "",
confirmPassword: ""
},
form: {
name: "",
nickname: "",
Expand All @@ -156,26 +92,6 @@ export default {
}
},
methods: {
onChangePasswordConfirm () {
let isFormReady = false
this.$refs["passwordChangeFrom"].validate((valid) => {
if (valid) {
isFormReady = true
}
})
if (!isFormReady) {
return
}
updateUser(this.name, {
"password": this.passwordChangeFrom.newPassword
}).then(() => {
this.$message.success(this.$t("commons.msg.update_success"))
this.changePasswordOpened = false
})
},
openedChangePassword () {
this.changePasswordOpened = true
},
onConfirm () {
if (this.isSubmitGoing) {
return
Expand Down
15 changes: 14 additions & 1 deletion web/kubepi/src/business/user-management/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import {checkPermissions} from "@/utils/permission"
export default {
name: "ClusterList",
name: "Users",
components: {ComplexTable, LayoutContent},
data() {
return {
Expand All @@ -80,6 +80,16 @@ export default {
return !checkPermissions({resource: "users", verb: "update"})
}
},
{
label: this.$t("commons.button.change_password"),
icon: "el-icon-edit-outline",
click: (row) => {
this.onChangePassword(row.name)
},
disabled: () => {
return !checkPermissions({resource: "users", verb: "update"})
}
},
{
label: this.$t("commons.button.delete"),
icon: "el-icon-delete",
Expand Down Expand Up @@ -132,6 +142,9 @@ export default {
onEdit(name) {
this.$router.push({name: "UserEdit", params: {name: name}})
},
onChangePassword(name) {
this.$router.push({name: "UserPassword", params: {name: name}})
},
onDelete(name) {
this.$confirm(this.$t("commons.confirm_message.delete"), this.$t("commons.message_box.alert"), {
confirmButtonText: this.$t("commons.button.confirm"),
Expand Down
Loading

0 comments on commit 21938a9

Please sign in to comment.