Git Product home page Git Product logo

samuelsihotang1 / task-5-pbi-rakamin-academy Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 23.97 MB

This web application serves as a platform for user and photo management, allowing users to register, login, upload, and edit their photos, as well as manage user profiles. It utilizes JWT for authentication and provides endpoints for various CRUD operations related to users and photos.

License: GNU General Public License v3.0

Go 68.27% HTML 31.73%
gin go golang gorm govalidator jwt mysql btpn rakamin rakamin-academy

task-5-pbi-rakamin-academy's Introduction

Profile Web Application

Overview

This repository contains the source code for a web application developed for Task 5 PBI project. The application serves as a platform where users can register, login, upload photos, edit their profiles, and perform other related tasks. Below is a breakdown of the main components and functionalities of the application:

File Structure

  • Connect.go: Establishes a connection to the MySQL database.
  • Migrate.go: Handles the database migrations, ensuring the necessary tables are created.
  • Model.go: Defines a generic model struct with common fields like ID, CreatedAt, and UpdatedAt.
  • User.go: Contains the model definition for the User entity, including fields such as Username, Email, Password, and a reference to Photos.
  • Photo.go: Defines the model for Photo entities, including Title, Caption, PhotoUrl, and a reference to the User who uploaded it.
  • RequireAuth.go: Middleware function to ensure authentication for protected routes.
  • LoadEnvVariable.go: Helper function to load environment variables from a .env file.
  • ValidateStruct.go: Helper function for validating request body structures.
  • controllers/: Contains handlers for various HTTP requests.
    • UserController.go: Handles user-related operations such as registration, login, editing, and deletion.
    • PhotoController.go: Manages photo-related operations like uploading, retrieving, editing, and deletion.
  • router/: Defines HTTP routes and connects them to the corresponding controllers.
    • routers.go: Specifies the routes for user authentication, profile management, and photo-related actions.

Routing

  • /users/register (POST): Allows users to register by providing a username, email, and password. Upon successful registration, a JWT token is generated, and the user is automatically logged in.
  • /register (GET): Renders the registration page.
  • /users/login (POST): Handles user login. Users provide their email and password, and upon successful authentication, a JWT token is generated and stored as a cookie for subsequent requests.
  • /login (GET): Renders the login page.
  • / (GET): Serves the homepage after successful authentication.
  • /users/info (GET): Retrieves user information including username and email.
  • /users (GET): Renders a page for user profile management.
  • /users/:userId (PUT): Allows users to edit their profile information such as username, email, and password.
  • /users/logout (POST): Logs the user out by deleting the JWT token cookie.
  • /users/:userId (DELETE): Allows users to delete their account.
  • /photos (POST): Enables users to upload photos along with a title and caption.
  • /photos (GET): Retrieves the first photo uploaded by the current user.
  • /infophoto (GET): Retrieves information about the first photo uploaded by the current user.
  • /photos/:photoId (PUT): Allows users to edit the title and caption of a specific photo.
  • /photos/:photoId (DELETE): Enables users to delete a specific photo they uploaded.

Functionality

  • User Management: Users can register, login, edit their profile information, and delete their accounts.
  • Authentication: JWT-based authentication ensures secure access to protected routes.
  • Photo Management: Users can upload photos, view their uploaded photos, edit photo details, and delete photos they uploaded.
  • Middleware: Middleware functions ensure authentication for protected routes, preventing unauthorized access.

How It Works

  1. Users can register for an account by providing a username, email, and password.
  2. Upon successful registration, users are automatically logged in, and a JWT token is stored as a cookie.
  3. Users can log in using their email and password, which validates their credentials against the database.
  4. After logging in, users can access protected routes such as their profile page and photo management.
  5. Users can upload photos with titles and captions, view their uploaded photos, edit photo details, and delete photos.
  6. User profile information can be edited, including username, email, and password.
  7. Users can log out, which deletes the JWT token cookie, terminating their session.

Setup Instructions

  1. Clone the repository to your local machine.
  2. Create a .env file and define the necessary environment variables like DB, SECRET, and PORT.
  3. Run go run main.go to start the application.
  4. Access the application via the specified routes, e.g., http://localhost:3000/login for the login page.

Contributors

  • Samuel Christy Angie Sihotang

task-5-pbi-rakamin-academy's People

Contributors

samuelsihotang1 avatar

Stargazers

 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.