정다정 정다정 2024-01-29
240129 정다정 회원가입 join으로 변경
@45911927d969d789e0db7a5fb10bb94b20ca1409
client/views/pages/join/Join.vue
--- client/views/pages/join/Join.vue
+++ client/views/pages/join/Join.vue
@@ -1,35 +1,35 @@
 <template>
-    <div class="join-view container ">
-        <div class="flex align-center flex-column   ">
+    <div class="join-view container">
+        <div class="flex align-center flex-column">
             <div class="view-wrap">
-
                 <h1 class="main-title page-titleZone">회원가입</h1>
-                <ul class="content-wrap ">
+                <ul class="content-wrap">
                     <li class="flex-column">
-                        <a href="#">ID</a>
-                        <input class="flex70" type="text">
+                        <a>ID</a>
+                        <input class="flex70" type="text" v-model="id" />
                     </li>
                     <li class="flex-column">
-                        <a href="#">PW</a>
-                        <input type="password">
+                        <a>PW</a>
+                        <input type="password" v-model="pwd" />
                     </li>
                     <li class="flex-column">
-                        <a href="#">PW CHECK</a>
-                        <input type="password">
+                        <a>PW CHECK</a>
+                        <input type="password" v-model="pwd_check" />
                     </li>
                     <li class="flex-column">
-                        <a href="#">NAME</a>
-
-                        <input type="text">
-
+                        <a>NAME</a>
+                        <input type="text" v-model="name" />
+                    </li>
+                    <li class="flex-column">
+                        <a>E-MAIL</a>
+                        <input type="text" v-model="email" />
                     </li>
                 </ul>
-                <button class="large-btn blue-btn join-button" @click="joinbtn">회원가입</button>
+                <button class="large-btn blue-btn join-button" @click="joinUser">회원가입</button>
             </div>
         </div>
-        <div class="join-modal modal-wrapper  " v-if="joinModal">
+        <div class="join-modal modal-wrapper" v-if="joinModal">
             <div class="modal-fillter flex-column align-center justify-between">
-
                 <h1>회원가입이 완료되었습니다.로그인 페이지로 넘어갑니다.</h1>
                 <button class="blue-btn small-btn" @click="closeModal">확인</button>
             </div>
@@ -38,41 +38,109 @@
 </template>
 
 <script>
-import axios from "axios";
-import vueCookie from "vue-cookies";
-import SvgIcon from '@jamescoyle/vue-icon'
-import { mdiAccountOutline, mdiKey, mdiCardAccountDetails } from '@mdi/js'
+import axios from 'axios';
+import vueCookie from 'vue-cookies';
+import SvgIcon from '@jamescoyle/vue-icon';
+import { mdiAccountOutline, mdiKey, mdiCardAccountDetails } from '@mdi/js';
 export default {
-
-
     data() {
         return {
             mdiAccountOutline: mdiAccountOutline,
             mdiKey: mdiKey,
             mdiCardAccountDetails: mdiCardAccountDetails,
-            joinbtn:true,
-            joinModal:false,
-            closeModal:false
-        }
+            // joinbtn: true,
+            joinModal: false,
+            closeModal: false,
+
+            id: '',
+            pwd: '',
+            pwd_check: '',
+            name: '',
+            email: '',
+        };
     },
     methods: {
-        joinbtn(){
+        joinUser() {
+            const vm = this;
+            if (!vm.id || !vm.pwd || !vm.pwd_check || !vm.name || !vm.email) {
+                this.$showAlert('error', '모든 칸을 입력하세요.');
+                return;
+            }
+
+            //아이디 검사
+            /*if (vm.onlyNumberAndEnglish(vm.id) == false) {
+                this.$showAlert('error', '아이디를 입력하실 때 영어 또는 숫자만 가능합니다.');
+                return;
+            }*/
+
+            //비밀번호 검사
+            /*if (vm.strongPassword(vm.pwd) == false) {
+                this.$showAlert('error','비밀번호 입력시 최소 8글자 이상이면서, 알파벳과 숫자 및 특수문자(@$!%*#?&)를 하나 이상 입력해주시기 바랍니다.');
+                return;
+            }*/
+
+            //비밀번호 일치 확인
+            if (vm.pwd === vm.pwd_check) {
+                const user_info = {
+                    user_id: vm.id,
+                    user_pw: vm.pwd,
+                    user_nm: vm.name,
+                    user_email: vm.email,
+                };
+                axios({
+                    url: '/insertUsers.json',
+                    method: 'post',
+                    headers: {
+                        'Content-Type': 'application/json; charset=UTF-8',
+                    },
+                    data: user_info,
+                })
+                    .then((res) => {
+                        console.log('회원가입 응답 : ', res);
+                        vm.joinbtn();
+                    })
+                    .catch((err) => {
+                        console.log('회원가입 에러 : ', err);
+                        this.$showAlert('error', '회원가입 실패');
+                    });
+            } else {
+                this.$showAlert('error', '비밀번호가 일치하지 않습니다.');
+            }
+            vm.id = '';
+            vm.pwd = '';
+            vm.pwd_check = '';
+            vm.name = '';
+            vm.email = '';
+        },
+        joinbtn() {
             this.joinModal = !this.joinModal;
         },
-        closeModal(){
+        closeModal() {
             this.joinModal = !this.joinModal;
-        }
-    },
-    watch: {
+            this.$router.push({ path: '/', query: {} });
+        },
+        // 특수문자 검증
+        onlyNumberAndEnglish(id) {
+            return /^[A-Za-z0-9][A-Za-z0-9]*$/.test(id);
+        },
 
-
+        // 비밀번호 검증(8글자 이상, 영문, 숫자, 특수문자 사용)
+        strongPassword(password) {
+            return /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/.test(password);
+        },
     },
+    watch: {},
     computed: {},
     components: {
-        SvgIcon
+        SvgIcon,
     },
     mounted() {
-
+        //쿠키 존재 유무 확인
+        if ($cookies.get('JSESSIONID') != null) {
+            this.$router.push('/main.page');
+        } else {
+            this.$router.push('/join.page');
+        }
     },
 };
 </script>
@@ -85,62 +153,60 @@
 }
 
 .view-wrap {
-
     background-color: var(--color-white);
     width: 30%;
     border-radius: 2rem;
     padding: 50px 60px;
     box-shadow: 5px 5px 10px #33333336;
-
 }
 
 .content-wrap .container {
     flex-direction: row;
 }
 
-.content-wrap>li {
+.content-wrap > li {
     padding: 2rem 0;
 }
 
-.content-wrap>li>a {
+.content-wrap > li > a {
     padding: 0 0 1rem 0;
     font-size: 1.5rem;
 }
 
-input[type="password"]{
+input[type='password'] {
     min-width: 100px;
     padding: 5px 10px;
     border: 1px solid #eee;
     border-radius: 5px;
     font-size: 1.3rem;
 }
-input[type="text"]{
+input[type='text'] {
     margin-left: 0px;
 }
 
-.join-button{
+.join-button {
     padding: 1rem 0;
     margin-left: 0px;
 }
-.join-button.active{
+.join-button.active {
     display: block;
 }
-.join-modal{
+.join-modal {
     position: fixed;
     top: 50%;
     left: 50%;
-    transform: translate(-50%,-50%);
+    transform: translate(-50%, -50%);
     width: 100%;
     height: 100%;
     padding: 0px !important;
-background-color: rgba(0, 0, 0, 0.256); 
+    background-color: rgba(0, 0, 0, 0.256);
 }
 
-.modal-fillter{
+.modal-fillter {
     position: absolute;
     top: 50%;
     left: 50%;
-    transform: translate(-50%,-50%);
+    transform: translate(-50%, -50%);
     width: 30%;
     height: 30%;
     background-color: var(--color-white);
@@ -148,9 +214,5 @@
     text-align: center;
     padding: 4rem;
     border-radius: 2rem;
-
-
 }
-
-
 </style>
client/views/pages/login/Login.vue
--- client/views/pages/login/Login.vue
+++ client/views/pages/login/Login.vue
@@ -8,13 +8,24 @@
                 <div class="login-zone">
                     <div class="input-wrap">
                         <div class="inputContainer">
-                            <input required="" class="customInput" type="text" v-model="userLogin.user_id"
-                            @keyup.enter="handleEnterKey">
+                            <input
+                                required=""
+                                class="customInput"
+                                type="text"
+                                v-model="userLogin.user_id"
+                                @keyup.enter="handleEnterKey"
+                            />
                             <label class="inputLabel">ID</label>
                             <div class="inputUnderline"></div>
                         </div>
                         <div class="inputContainer">
-                            <input required="" class="customInput" type="password" v-model="userLogin.user_password" @keyup.enter="handleEnterKey">
+                            <input
+                                required=""
+                                class="customInput"
+                                type="password"
+                                v-model="userLogin.user_password"
+                                @keyup.enter="handleEnterKey"
+                            />
                             <label class="inputLabel">PASSWORD</label>
                             <div class="inputUnderline"></div>
                         </div>
@@ -22,7 +33,7 @@
                     <div class="found-zone flex justify-center">
                         <router-link to="">아이디찾기</router-link>
                         <router-link to="">비밀번호 찾기</router-link>
-                        <router-link to="/register.page">회원가입</router-link>
+                        <router-link to="/join.page">회원가입</router-link>
                     </div>
                 </div>
                 <button class="blue-btn large-btn" @click="login()">로그인</button>
@@ -32,8 +43,8 @@
 </template>
 
 <script>
-import axios from "axios";
-import vueCookie from "vue-cookies";
+import axios from 'axios';
+import vueCookie from 'vue-cookies';
 
 export default {
     data() {
@@ -55,54 +66,54 @@
             // 아이디를 입력하지 않았을 경우
             // 공백만 입력하였을 경우
             // 특수문자가 입력되었을 경우
-            if (vm.userLogin.user_id == null || vm.userLogin.user_id.replace(/\s/gi, '') == '' || special_pattern.test(vm.userLogin.user_id) == true) {
-                alert("아이디를 입력해주시기 바랍니다.");
+            if (
+                vm.userLogin.user_id == null ||
+                vm.userLogin.user_id.replace(/\s/gi, '') == '' ||
+                special_pattern.test(vm.userLogin.user_id) == true
+            ) {
+                alert('아이디를 입력해주시기 바랍니다.');
                 return;
             }
 
             // 비밀번호를 입력하지 않았을 경우
             // 공백만 입력하였을 경우
             if (vm.userLogin.user_password == null || vm.userLogin.user_password.replace(/\s/gi, '') == '') {
-                alert("비밀번호를 입력해주시기 바랍니다.");
+                alert('비밀번호를 입력해주시기 바랍니다.');
                 return;
             }
 
             axios({
                 url: '/login.json',
                 method: 'post',
-                headers: { "Content-Type": "application/json; charset=UTF-8" },
+                headers: { 'Content-Type': 'application/json; charset=UTF-8' },
                 data: vm.userLogin,
             })
                 .then(function (response) {
-                    console.log("login - response", response.data);
+                    console.log('login - response', response.data);
                     if (response.data > 0) {
                         vm.$router.go();
                         vm.$router.push({ path: '/main.page', query: {} });
                     } else {
-                        alert("로그인 실패하였습니다.\n\n아이디와 비밀번호를 다시 입력해주시기 바랍니다.");
+                        alert('로그인 실패하였습니다.\n\n아이디와 비밀번호를 다시 입력해주시기 바랍니다.');
                         return;
-
                     }
                 })
                 .catch(function (error) {
-                    console.log("login - error", error);
-                    alert("로그인에 오류가 발생하였습니다.");
+                    console.log('login - error', error);
+                    alert('로그인에 오류가 발생하였습니다.');
                 });
         },
         handleEnterKey: function () {
             this.login();
-        }
+        },
     },
-    watch: {
-
-
-    },
+    watch: {},
     computed: {},
     components: {},
     mounted() {
         console.log('main mounted');
         // 쿠키에 JSESSIONID 키 값이 존재한다면 메인페이지로 이동
-        if (vueCookie.get("JSESSIONID") != null) {
+        if (vueCookie.get('JSESSIONID') != null) {
             this.$router.push({ path: '/main.page', query: {} });
         }
     },
@@ -128,56 +139,54 @@
     margin-bottom: 50px;
 }
 
-.logo>img {
+.logo > img {
     display: block;
     margin: 0 auto;
 }
 .inputContainer {
-  position: relative;
-  margin-bottom: 40px;  
+    position: relative;
+    margin-bottom: 40px;
 }
 
-.inputContainer:last-child{
+.inputContainer:last-child {
     margin-bottom: 0;
 }
 
 .customInput {
-  width: 100%;
-  padding: 10px;
-  font-size: 13px;
-  background-color: transparent;
-  border: none;
-  outline: none;
-  transition: border-color 0.3s ease;
+    width: 100%;
+    padding: 10px;
+    font-size: 13px;
+    background-color: transparent;
+    border: none;
+    outline: none;
+    transition: border-color 0.3s ease;
 }
-
 
 .inputLabel {
-  position: absolute;
-  top: 0;
-  left: 0;
-  pointer-events: none;
-  padding: 5px;
-  font-size: 13px;
-  color: #eee;
-  transform: translateY(-80%);
+    position: absolute;
+    top: 0;
+    left: 0;
+    pointer-events: none;
+    padding: 5px;
+    font-size: 13px;
+    color: #eee;
+    transform: translateY(-80%);
 }
 
-
 .inputUnderline {
-  position: absolute;
-  bottom: 0;
-  left: 0;
-  width: 100%;
-  height: 2px;
-  background-color: #eee;
+    position: absolute;
+    bottom: 0;
+    left: 0;
+    width: 100%;
+    height: 2px;
+    background-color: #eee;
 }
 
 .found-zone {
     padding: 20px 0;
 }
 
-.found-zone>a {
+.found-zone > a {
     font-size: 1.4rem;
     padding: 0 10px;
 }
@@ -185,4 +194,5 @@
 .login-page .blue-btn {
     margin-left: 0;
     padding: 10px 0;
-}</style>
+}
+</style>
Add a comment
List