Skip to content

This was a project for my Software Engineering class. I needed to follow the entire development roadmap for starting, planning, testing, and deploying a piece of software. All of this was done under my project manager and TA, Li Shi. She was extremely helpful at keeping me on track and giving insight into how to deploy my software. A version of …

Notifications You must be signed in to change notification settings

smithcol11/CS300-Chat-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS300 Chat Application

Czat - Software: Messaging App

A version of my software is hosted at Heroku if you want to check it out!

https://cs300-czat.herokuapp.com/ - Hosted at this link.

Introduction

This is my first attempt at any sort of software development. This is for my CS300 course at PSU. Czat is an instant messaging app with many features that mainstream apps contain, such as user authentication, hosting, database access, group messaging, etc.

Code Samples

User.js

const mongoose = require("mongoose");
const passportLocalMongoose = require("passport-local-mongoose");
const userSchema = new mongoose.Schema({
  username: {
    type: String,
    //required: true,
    unique: true,
    trim: true,
    minlength: 1
  },
  password: {
    type: String,
    //required: true,
    minlength: 1,
  },
  
},  {
  timestamps: true,
});

userSchema.plugin(passportLocalMongoose);
const User = mongoose.model('User', userSchema);
module.exports = User;

Index.ejs

<form id="login" action="/login" method="POST" class="container needs-validation w-75" style="max-width: 500px; margin-top: 20%">
    <div class="form-group">
      <label for="username">Username</label>
      <input type="text" class="form-control" require id="username" required name="username">
    </div>
    <p></p>
    <div class="form-group">
      <label for="password">Password</label>
      <input type="password" class="form-control" id="password" required name="password"> 
    </div>
    <p></p>
      <button type="submit" class="btn btn-primary">Login</button> 
      <script>
        var socket = io();

        var username = document.getElementById("username");
        var form = document.getElementById("login");
        form.addEventListener("submit", (e) => {
          document.cookie = username.value;
          socket.emit('user', document.getElementById('username').value);
        })
      </script>
  </form>

index.js

socket.on("joinRoom", ({ username, room}) =>{
    const userF = userExit(socket.id);
    if (userF) {
      console.log("user: " + userF.username + " room: " + userF.room);
      socket.leave(userF.room);
      socket.broadcast.to(userF.room).emit('message',formatMessage(bot, `${userF.username} has left the chat`));
    }
    const user = userJoin(socket.id, username, room);
    console.log("user: " + user.username + " room: " + user.room);
    socket.join(user.room);
    socket.emit("message", formatMessage(bot,"Welcome to Czat"));
    socket.broadcast.to(user.room).emit("message", formatMessage(bot, `${user.username} has joined the chat.`));
    io.to(user.room).emit('roomUsers', {room: user.room, users: getRoomUser(user.room)});
  })

  socket.on('chat message', ( {msg, room} ) => {
    const user = getCurrentUser(socket.id);
    console.log("user: " + user.username + " room: " + user.room);
    io.to(room).emit('message', formatMessage(user.username, msg));
    var message = formatMessage(user.username, msg);
    const newMessage = new Message({
      name: room,
      username: message.username,
      text: message.text,
      time: message.time,
    });
    newMessage.save();
  });

Installation

Download repository to folder. Need to have dependencies, these can be found in the package.json file. If you need to install those, use 'npm install xxxxx'. (Where xxxxx is the name of a dependency, Ex: 'npm install mongoose'.)

The actual software is started by typing 'nodemon index.js'

About

This was a project for my Software Engineering class. I needed to follow the entire development roadmap for starting, planning, testing, and deploying a piece of software. All of this was done under my project manager and TA, Li Shi. She was extremely helpful at keeping me on track and giving insight into how to deploy my software. A version of …

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published