PasswordModal.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="admin--modal-overlay" @click.self="close">
  3. <div class="admin--modal">
  4. <div class="admin--modal-header">
  5. <h4>비밀번호 변경</h4>
  6. <button @click="close" class="admin--modal-close">&times;</button>
  7. </div>
  8. <form @submit.prevent="save" class="admin--modal-form">
  9. <div class="admin--modal-body">
  10. <div class="admin--info-box">
  11. <p><strong>관리자:</strong> {{ admin.name }} ({{ admin.username }})</p>
  12. </div>
  13. <div class="admin--form-group" v-if="isCurrentUser">
  14. <label class="admin--form-label">현재 비밀번호</label>
  15. <input
  16. v-model="formData.current_password"
  17. type="password"
  18. class="admin--form-input"
  19. placeholder="현재 비밀번호 입력"
  20. />
  21. <small class="admin--help-text">본인 계정의 경우 현재 비밀번호를 입력해주세요.</small>
  22. </div>
  23. <div class="admin--form-group">
  24. <label class="admin--form-label">새 비밀번호 *</label>
  25. <input
  26. v-model="formData.new_password"
  27. type="password"
  28. class="admin--form-input"
  29. required
  30. placeholder="최소 8자 이상"
  31. minlength="8"
  32. />
  33. </div>
  34. <div class="admin--form-group">
  35. <label class="admin--form-label">새 비밀번호 확인 *</label>
  36. <input
  37. v-model="formData.new_password_confirm"
  38. type="password"
  39. class="admin--form-input"
  40. required
  41. placeholder="새 비밀번호 재입력"
  42. minlength="8"
  43. />
  44. </div>
  45. </div>
  46. <div class="admin--modal-footer">
  47. <button type="button" @click="close" class="admin--btn-small admin--btn-small-secondary">
  48. 취소
  49. </button>
  50. <button type="submit" class="admin--btn-small admin--btn-small-primary" :disabled="saving">
  51. {{ saving ? '변경 중...' : '변경' }}
  52. </button>
  53. </div>
  54. </form>
  55. </div>
  56. </div>
  57. </template>
  58. <script setup>
  59. import { ref, computed } from 'vue'
  60. const props = defineProps({
  61. admin: {
  62. type: Object,
  63. required: true
  64. }
  65. })
  66. const emit = defineEmits(['close', 'saved'])
  67. const { post } = useApi()
  68. const saving = ref(false)
  69. // 현재 로그인한 관리자 ID
  70. const currentAdminId = computed(() => {
  71. if (typeof window === 'undefined') return null
  72. const user = localStorage.getItem('admin_user')
  73. if (!user) return null
  74. try {
  75. return JSON.parse(user).id
  76. } catch {
  77. return null
  78. }
  79. })
  80. const isCurrentUser = computed(() => {
  81. return currentAdminId.value === props.admin.id
  82. })
  83. const formData = ref({
  84. current_password: '',
  85. new_password: '',
  86. new_password_confirm: ''
  87. })
  88. const close = () => {
  89. emit('close')
  90. }
  91. const save = async () => {
  92. // 비밀번호 확인
  93. if (formData.value.new_password !== formData.value.new_password_confirm) {
  94. emit('saved', '새 비밀번호가 일치하지 않습니다.')
  95. return
  96. }
  97. if (formData.value.new_password.length < 8) {
  98. emit('saved', '비밀번호는 최소 8자 이상이어야 합니다.')
  99. return
  100. }
  101. saving.value = true
  102. try {
  103. const requestData = {
  104. new_password: formData.value.new_password
  105. }
  106. // 본인 계정인 경우 현재 비밀번호 포함
  107. if (isCurrentUser.value && formData.value.current_password) {
  108. requestData.current_password = formData.value.current_password
  109. }
  110. const { data, error } = await post(`/admin/${props.admin.id}/password`, requestData)
  111. if (error) {
  112. console.error('[PasswordModal] 변경 실패:', error)
  113. const errorMessage = error.response?.data?.message || '비밀번호 변경에 실패했습니다.'
  114. emit('saved', errorMessage)
  115. return
  116. }
  117. if (data?.success) {
  118. emit('saved', '비밀번호가 변경되었습니다.')
  119. }
  120. } finally {
  121. saving.value = false
  122. }
  123. }
  124. </script>
  125. <style scoped>
  126. .admin--modal-overlay {
  127. position: fixed;
  128. top: 0;
  129. left: 0;
  130. right: 0;
  131. bottom: 0;
  132. background: rgba(0, 0, 0, 0.7);
  133. z-index: 9999;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. }
  138. .admin--modal {
  139. background: #2d2d2d;
  140. padding: 0;
  141. border-radius: 8px;
  142. min-width: 500px;
  143. max-width: 600px;
  144. width: 90%;
  145. box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  146. max-height: 90vh;
  147. display: flex;
  148. flex-direction: column;
  149. }
  150. .admin--modal-form {
  151. display: flex;
  152. flex-direction: column;
  153. flex: 1;
  154. min-height: 0;
  155. }
  156. .admin--modal-header {
  157. padding: 20px;
  158. border-bottom: 1px solid #404040;
  159. display: flex;
  160. justify-content: space-between;
  161. align-items: center;
  162. flex-shrink: 0;
  163. }
  164. .admin--modal-header h4 {
  165. margin: 0;
  166. font-size: 18px;
  167. font-weight: 600;
  168. color: #ffffff;
  169. }
  170. .admin--modal-close {
  171. background: none;
  172. border: none;
  173. font-size: 28px;
  174. cursor: pointer;
  175. color: #999;
  176. line-height: 1;
  177. transition: color 0.2s;
  178. padding: 0;
  179. width: 30px;
  180. height: 30px;
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. }
  185. .admin--modal-close:hover {
  186. color: #fff;
  187. }
  188. .admin--modal-body {
  189. padding: 24px;
  190. overflow-y: auto;
  191. flex: 1;
  192. min-height: 0;
  193. }
  194. .admin--info-box {
  195. background: #1a1a1a;
  196. border: 1px solid #404040;
  197. border-radius: 4px;
  198. padding: 12px 16px;
  199. margin-bottom: 20px;
  200. }
  201. .admin--info-box p {
  202. margin: 0;
  203. color: #e0e0e0;
  204. font-size: 14px;
  205. }
  206. .admin--info-box strong {
  207. color: #ffffff;
  208. font-weight: 600;
  209. }
  210. .admin--form-group {
  211. display: flex;
  212. flex-direction: column;
  213. margin-bottom: 20px;
  214. }
  215. .admin--form-group:last-child {
  216. margin-bottom: 0;
  217. }
  218. .admin--form-label {
  219. display: block;
  220. margin-bottom: 8px;
  221. font-size: 14px;
  222. font-weight: 500;
  223. color: #e0e0e0;
  224. }
  225. .admin--form-input {
  226. width: 100%;
  227. padding: 10px 14px;
  228. border: 1px solid #404040;
  229. border-radius: 4px;
  230. background: #1a1a1a;
  231. color: #ffffff;
  232. font-size: 14px;
  233. transition: border-color 0.2s;
  234. }
  235. .admin--form-input:focus {
  236. outline: none;
  237. border-color: var(--admin-accent-primary, #217346);
  238. }
  239. .admin--form-input::placeholder {
  240. color: #666;
  241. }
  242. .admin--help-text {
  243. display: block;
  244. margin-top: 6px;
  245. font-size: 12px;
  246. color: #999;
  247. line-height: 1.4;
  248. }
  249. .admin--modal-footer {
  250. padding: 20px 24px;
  251. border-top: 1px solid #404040;
  252. display: flex;
  253. gap: 10px;
  254. justify-content: flex-end;
  255. flex-shrink: 0;
  256. }
  257. .admin--btn-small {
  258. padding: 6px 14px;
  259. border: none;
  260. border-radius: 4px;
  261. font-size: 13px;
  262. font-weight: 500;
  263. cursor: pointer;
  264. transition: all 0.3s ease;
  265. font-family: 'AudiType', sans-serif;
  266. white-space: nowrap;
  267. }
  268. .admin--btn-small:disabled {
  269. opacity: 0.5;
  270. cursor: not-allowed;
  271. }
  272. .admin--btn-small-secondary {
  273. background: var(--admin-bg-tertiary, #252525);
  274. color: var(--admin-text-secondary, #e0e0e0);
  275. border: 1px solid var(--admin-border-color, #404040);
  276. }
  277. .admin--btn-small-secondary:hover:not(:disabled) {
  278. background: var(--admin-bg-primary, #2d2d2d);
  279. border-color: var(--admin-accent-primary, #217346);
  280. color: var(--admin-text-primary, #ffffff);
  281. }
  282. .admin--btn-small-primary {
  283. background: var(--admin-accent-primary, #217346);
  284. color: var(--admin-text-primary, #ffffff);
  285. }
  286. .admin--btn-small-primary:hover:not(:disabled) {
  287. background: var(--admin-accent-hover, #1a5c37);
  288. }
  289. </style>