Giter Site home page Giter Site logo

jxnuchat-backend's Introduction

JxnuChat is a messaging platform just like WeChat, WhatsApp or Telegram but made by Jiangxi Normal University Student as part of java class projects. And it took around 6 months of active development and careful design.

๐Ÿ› ๏ธ App components

Just like all traditional REST apps structures, JxnuChat consists of the following parts

  • ๐Ÿ’ป Front end โ†’ App's UI and direct interactive part with the user, Written in React Framework with JavaScript.
  • โš™๏ธ Back end โ†’ App's Behind the scene and where all magic happens, Crafted in Java's web Framework Spring.
  • ๐Ÿ’พ Database โ†’ all data accessed and stored on MySQL database (can be changed).

๐ŸŽฏ Features

For now the application is still under development, but some main objectives are archived as following.

  • Supports Direct Messaging using Websockets.
  • Secure Login using JWT (JSON Web Token) tokens.
  • Users can add friends by username search and send message.
  • Sending Images.
  • User's profile.
  • Cross platform support (maybe in future ? ๐Ÿคซ )

๐Ÿ“ Get started

  1. Setting-Up Database Connectivity with Spring Back-end.

    • Clone the project to your local machine (make sure you have git installed).
        git clone https://github.com/0xNullHex/JxnuChat-Backend.git    
    • Open cloned project in a code editor or ide and follow the path written below. src/main/resources/application.properties

    • Edit the "application.properties" file to your following preferences (Make sure you already setup a MySQL/MariaDB server).

    spring.datasource.url=jdbc:mariadb://{Your_DB_IP}:{DB_Port}/{DB_Name}?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 
    spring.datasource.username={DB_Username}
    spring.datasource.password={DB_Password}
    
    #MariaDb driver can work properly with MySQL server so no worries
    spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
    
    #For the first time start leave the option on create and after change it to update
    spring.jpa.hibernate.ddl-auto=create
    
  2. Adding Custom Secure Key for JWT feature.

    • Access the class in the following path src/main/java/com/myapp/chatbackend/Jwt/JwTokenVerifier.java

    • Add your Secure Key in the key variable (Make sure it's a strong and long Key).

        try {
                String token = authorizationHeader.replace("Bearer ","");
    
    //          Enter Secure Key Here
                String key = "";
    
                Jws<Claims> claimsJws = Jwts.parserBuilder()
                        .setSigningKey(Keys.hmacShaKeyFor(key.getBytes()))
                        .build()
                        .parseClaimsJws(token);
    
                Claims body = claimsJws.getBody();
                String username = body.getSubject();
                Authentication authentication = new UsernamePasswordAuthenticationToken(username,null,null);
                SecurityContextHolder.getContext().setAuthentication(authentication);
            }
    • Access the class in the following path src/main/java/com/myapp/chatbackend/Jwt/JwtUsernamePasswordAuthenticationFilter.java

    • Add Same Key here

        @Override
        protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException {
    
    //      Enter Same Key here
            String key = " ";
            
            String token= Jwts.builder()
                    .setSubject(authResult.getName())
                            .setIssuedAt(new Date())
                                    .setExpiration(java.sql.Date.valueOf(LocalDate.now().plusWeeks(2)))
                                            .signWith(Keys.hmacShaKeyFor(key.getBytes()))
                                                    .compact();
            response.addHeader("Authorization","Bearer "+token);
            response.setContentType("application/json");
            response.setCharacterEncoding("UTF-8");
            response.getWriter().write("{\"accessToken\":"+"\""+token+"\",");
            response.getWriter().write("\"username\":"+"\""+authResult.getName()+"\"}");
        }

jxnuchat-backend's People

Contributors

0xnullhex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.