diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..11c5874 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..8dac0f0 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +
+ +#### Dweb ❌ Incheon National University (INU) + +## 🌟 Base code for the term project in Web class + +⚠️ Copyright © 2024. _Dweb_ All Rights Reserved. + + diff --git a/app.js b/app.js new file mode 100644 index 0000000..f65f3ee --- /dev/null +++ b/app.js @@ -0,0 +1,103 @@ +'use strict'; + +/** + * Module dependencies. + */ + +var express = require('express'); +var http = require('http'); + +var socket = require('./routes/socket.js'); + +var app = express(); +var server = http.createServer(app); + +/* Configuration */ +app.set('views', __dirname + '/views'); +app.use(express.static(__dirname + '/public')); +app.set('port', 3000); + +if (process.env.NODE_ENV === 'development') { + app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); +} + +/* Socket.io Communication */ +var io = require('socket.io').listen(server); +io.sockets.on('connection', socket); + +/* Start server */ +server.listen(app.get('port'), function (){ + //console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env')); +}); + + + + +const bodyParser = require('body-parser'); +app.use(bodyParser.json()); +let users = []; //유저 목록을 관리하는 배열 + +// Register endpoint +app.post('/api/register', (req, res) => { + const { username, password } = req.body; + + // 동일한 이름의 사용자가 존재하는지 체크 + if (users.find(user => user.username === username)) { + return res.json({ success: false, message: '이미 사용 중인 아이디입니다.' }); + } + + // 유저 리스트에 추가 + users.push({ username, password }); + let ids = users.map(user => user.username); + res.json({ success: true, userlist: ids }); +}); + +// Login endpoint +app.post('/api/login', (req, res) => { + const { username, password } = req.body; + + // 아이디와 비밀번호가 일치하는지 검사 + const user = users.find(user => + user.username === username && user.password === password); + if (user) { + res.json({ success: true }); + } else { + res.json({ success: false, + message: '아이디 또는 비밀번호가 올바르지 않습니다.' }); + } +}); + +// Update user endpoint +app.post('/api/update', (req, res) => { + const { currentname, newName } = req.body; + //console.log(currentname, newName); + + // 동일한 이름의 사용자가 존재하는지 체크 + if (users.find(user => user.username === newName)) { + return res.json({ success: false, message: '이미 사용 중인 아이디입니다.' }); + } + + // 현재 이름을 찾아서 + const userIndex = users.findIndex(user => user.username === currentname); + + if (userIndex !== -1) { + // 새 이름으로 update + users[userIndex].username = newName; + res.json({ success: true, message: '아이디가 성공적으로 변경되었습니다.' }); + //console.log(users, '성공'); + } else { + res.json({ success: false, message: '해당하는 아이디를 찾을 수 없습니다.' }); + //console.log('실패'); + + } +}); + +// Get endpoint +app.post('/api/get', (req, res) => { + let ids = users.map(user => user.username); + res.json({userlist : ids}); +}); + + + +module.exports = app; \ No newline at end of file diff --git a/client/app.jsx b/client/app.jsx new file mode 100644 index 0000000..9056ee2 --- /dev/null +++ b/client/app.jsx @@ -0,0 +1,814 @@ +'use strict'; + +var React = require('react'); + +var socket = io.connect(); + + +var RoomTitle = React.createClass({ + render() { + return ( +아이디 변경
+현재 아이디 : {this.props.currentname}
+ +가입된 유저 목록
+ this.handleRoomClick(room.id)}>
+
+
+
+ {room.name}
+
+
+
+ 최근 메시지:
+ {room.messages.length > 0 && (
+ {room.messages[room.messages.length - 1].text}
+ )}
+ {room.messages.length == 0 && (
+ 없음
+ )}
+
+
+
채팅방이 없습니다.
채팅방을 개설하시겠습니까?
+
현재 선택된 방: {this.state.rooms.find(room => room.id === selectedRoom).name}
+ )} +아이디 : {this.state.user}
+Open your dev tools ;)
+ + diff --git a/node_modules/browserify/example/source_maps/js/build/.npmignore b/node_modules/browserify/example/source_maps/js/build/.npmignore new file mode 100644 index 0000000..f935021 --- /dev/null +++ b/node_modules/browserify/example/source_maps/js/build/.npmignore @@ -0,0 +1 @@ +!.gitignore diff --git a/node_modules/browserify/example/source_maps/js/build/bundle.js b/node_modules/browserify/example/source_maps/js/build/bundle.js new file mode 100644 index 0000000..a807c46 --- /dev/null +++ b/node_modules/browserify/example/source_maps/js/build/bundle.js @@ -0,0 +1,28 @@ +;(function(e,t,n,r){function i(r){if(!n[r]){if(!t[r]){if(e)return e(r);throw new Error("Cannot find module '"+r+"'")}var s=n[r]={exports:{}};t[r][0](function(e){var n=t[r][1][e];return i(n?n:e)},s,s.exports)}return n[r].exports}for(var s=0;s