Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login page fixed and responsive #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 75 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
# CP-GRIND

## Table of Contents
- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
## Introduction
This project is a RESTful API built using the Golang web framework Fiber and PostgreSQL as the database. It provides a foundation for building and deploying RESTful web services. You can use this project as a starting point for creating your own APIs or as a learning resource for Golang and PostgreSQL integration.

### Features
- Integration with Codeforces and AtCoder APIs: This project leverages the [Codeforces](https://codeforces.com/apiHelp) and [AtCoder](https://github.com/kenkoooo/AtCoderProblems/blob/master/doc/api.md) APIs to retrieve contest data, user information, and other related data. It fetches data from these platforms, processes it, and exposes it through RESTful APIs.
- Data Modification and Presentation: The project not only fetches data from Codeforces and AtCoder but also allows you to modify and present the data in a customized way through its RESTful endpoints.
- Flexible and Extendable: You can easily extend the functionality of this project to integrate with other APIs or add additional features to suit your specific needs.

You can use this project to build applications that interact with competitive programming platforms, analyze contest statistics, or create personalized dashboards for users participating in coding competitions.

## Prerequisites
Before you begin, ensure you have met the following requirements:

- [Golang](https://golang.org/dl/): Install Golang on your system.
- [PostgreSQL](https://www.postgresql.org/download/): Install PostgreSQL and create a database for this project.
- [Git](https://git-scm.com/downloads): Install Git for version control.

## Installation
Follow these steps to set up and run the project:

1. Clone the repository:
```bash
git clone https://github.com/ContriHUB/CP-Grind.git
```

2. Change to the project directory:
```bash
cd CP-Grind
```

3. Install project dependencies using Go Modules:
```bash
go mod tidy
```

4. Set up your environment variables. Create a `.env` file in the project root and add the following configuration, replacing the values with your own:

```ini
# Database Configuration
DATABASE_URL = "host=localhost user=<Database Username> password=<Database Password> dbname=<Database Name> port=<Database Port>"
# Fiber Configuration
PORT=3000
```

5. Migrate the database to create the necessary tables:
```bash
go run migrate.go
```

6. Start the application:
```bash
go run main.go
```

## Configuration
You can configure the application by modifying the `.env` file with your own settings. Additionally, you can customize other aspects of the application by editing the relevant code files.

## Usage
After successfully setting up the project, you can start using the RESTful API. You can use tools like [Postman](https://www.postman.com/downloads/) or `curl` to interact with the API.

## Contributing
We welcome contributions to this project. If you have any bug fixes, enhancements, or new features to propose, please open a pull request. For major changes, please open an issue first to discuss the changes you want to make.

## License
This project is licensed under the [MIT License](LICENSE).
# CP-GRIND
## Table of Contents
- [Introduction](#introduction)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
## Introduction
This project is a RESTful API built using the Golang web framework Fiber and PostgreSQL as the database. It provides a foundation for building and deploying RESTful web services. You can use this project as a starting point for creating your own APIs or as a learning resource for Golang and PostgreSQL integration.
### Features
- Integration with Codeforces and AtCoder APIs: This project leverages the [Codeforces](https://codeforces.com/apiHelp) and [AtCoder](https://github.com/kenkoooo/AtCoderProblems/blob/master/doc/api.md) APIs to retrieve contest data, user information, and other related data. It fetches data from these platforms, processes it, and exposes it through RESTful APIs.
- Data Modification and Presentation: The project not only fetches data from Codeforces and AtCoder but also allows you to modify and present the data in a customized way through its RESTful endpoints.
- Flexible and Extendable: You can easily extend the functionality of this project to integrate with other APIs or add additional features to suit your specific needs.
You can use this project to build applications that interact with competitive programming platforms, analyze contest statistics, or create personalized dashboards for users participating in coding competitions.
## Prerequisites
Before you begin, ensure you have met the following requirements:
- [Golang](https://golang.org/dl/): Install Golang on your system.
- [PostgreSQL](https://www.postgresql.org/download/): Install PostgreSQL and create a database for this project.
- [Git](https://git-scm.com/downloads): Install Git for version control.
## Installation
Follow these steps to set up and run the project:
1. Clone the repository:
```bash
git clone https://github.com/ContriHUB/CP-Grind.git
```
2. Change to the project directory:
```bash
cd CP-Grind
```
3. Install project dependencies using Go Modules:
```bash
go mod tidy
```
4. Set up your environment variables. Create a `.env` file in the project root and add the following configuration, replacing the values with your own:
```ini
# Database Configuration
DATABASE_URL = "host=localhost user=<Database Username> password=<Database Password> dbname=<Database Name> port=<Database Port>"
# Fiber Configuration
PORT=3000
```
5. Migrate the database to create the necessary tables:
```bash
go run migrate.go
```
6. Start the application:
```bash
go run main.go
```
## Configuration
You can configure the application by modifying the `.env` file with your own settings. Additionally, you can customize other aspects of the application by editing the relevant code files.
## Usage
After successfully setting up the project, you can start using the RESTful API. You can use tools like [Postman](https://www.postman.com/downloads/) or `curl` to interact with the API.
## Contributing
We welcome contributions to this project. If you have any bug fixes, enhancements, or new features to propose, please open a pull request. For major changes, please open an issue first to discuss the changes you want to make.
## License
This project is licensed under the [MIT License](LICENSE).
Binary file added background image 4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions controllers/grindController.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package controllers

import "github.com/gofiber/fiber/v2"

func GrindPage(c *fiber.Ctx) error {
return c.Render("home/grind", fiber.Map{})
}

package controllers
import "github.com/gofiber/fiber/v2"
func GrindPage(c *fiber.Ctx) error {
return c.Render("home/grind", fiber.Map{})
}
192 changes: 96 additions & 96 deletions controllers/homeController.go
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
package controllers

import (
"html/template"
"time"
"github.com/dhanrajchaurasia/CP-GRIND/initializers"
"github.com/dhanrajchaurasia/CP-GRIND/models"
"github.com/gofiber/fiber/v2"
)

func HomePage(c *fiber.Ctx) error {
msg := c.Cookies("message")
cfProfile := template.HTML(c.Cookies("cfProfile"))
c.ClearCookie("message")
c.ClearCookie("cfProfile")
data := fiber.Map{
"User": c.Cookies("username"),
"CF_Profile": cfProfile,
"Message": msg,
}
return c.Render("home/index", data)
}
func LoginPage(c *fiber.Ctx) error {
auth := c.Cookies("authorization_token")
if initializers.IsValidToken(auth) {
return c.Redirect("/")
}
return c.Render("home/login", fiber.Map{
"Message": "Welcome to CP Grind!",
})
}

func Signup(c *fiber.Ctx) error {
fname := c.FormValue("fname")
lname := c.FormValue("lname")
username := c.FormValue("username")
email := c.FormValue("email")
pass := c.FormValue("password")
cpass := c.FormValue("cpassword")
// Check if password and confirm password match
if pass != cpass {
return c.Render("home/login", fiber.Map{
"Message": "Password didn't match!",
})
}

user := models.User{
FirstName: fname,
SecondName: lname,
Username: username,
Email: email,
Password: pass,
}
err := initializers.CreateNewUser(user)
if err != nil {
return c.Render("home/login", fiber.Map{
"Message": err.Error(),
})
}
return c.Render("home/login", fiber.Map{
"Message": "Your account has been created successfully, Login to Continue!",
})
}

func Login(c *fiber.Ctx) error {
username := c.FormValue("username")
password := c.FormValue("password")
token, err := initializers.IsUserPresent(username, password)
if err != nil {
return c.Render("home/login", fiber.Map{
"Message": err.Error(),
})
}
c.Cookie(&fiber.Cookie{
Name: "authorization_token",
Value: token,
})
c.Cookie(&fiber.Cookie{
Name: "username",
Value: username,
})
return c.Redirect("/")
}

func Logout(c *fiber.Ctx) error {
c.Cookie(&fiber.Cookie{
Name: "authorization_token",
Value: "",
Expires: time.Now(),
})
return c.Redirect("/login")
}

func NotFound(c *fiber.Ctx) error {
return c.Render("home/404", fiber.Map{})
}
package controllers
import (
"html/template"
"time"
"github.com/dhanrajchaurasia/CP-GRIND/initializers"
"github.com/dhanrajchaurasia/CP-GRIND/models"
"github.com/gofiber/fiber/v2"
)
func HomePage(c *fiber.Ctx) error {
msg := c.Cookies("message")
cfProfile := template.HTML(c.Cookies("cfProfile"))
c.ClearCookie("message")
c.ClearCookie("cfProfile")
data := fiber.Map{
"User": c.Cookies("username"),
"CF_Profile": cfProfile,
"Message": msg,
}
return c.Render("home/index", data)
}
func LoginPage(c *fiber.Ctx) error {
auth := c.Cookies("authorization_token")
if initializers.IsValidToken(auth) {
return c.Redirect("/")
}
return c.Render("home/login", fiber.Map{
"Message": "Welcome to CP Grind!",
})
}
func Signup(c *fiber.Ctx) error {
fname := c.FormValue("fname")
lname := c.FormValue("lname")
username := c.FormValue("username")
email := c.FormValue("email")
pass := c.FormValue("password")
cpass := c.FormValue("cpassword")
// Check if password and confirm password match
if pass != cpass {
return c.Render("home/login", fiber.Map{
"Message": "Password didn't match!",
})
}
user := models.User{
FirstName: fname,
SecondName: lname,
Username: username,
Email: email,
Password: pass,
}
err := initializers.CreateNewUser(user)
if err != nil {
return c.Render("home/login", fiber.Map{
"Message": err.Error(),
})
}
return c.Render("home/login", fiber.Map{
"Message": "Your account has been created successfully, Login to Continue!",
})
}
func Login(c *fiber.Ctx) error {
username := c.FormValue("username")
password := c.FormValue("password")
token, err := initializers.IsUserPresent(username, password)
if err != nil {
return c.Render("home/login", fiber.Map{
"Message": err.Error(),
})
}
c.Cookie(&fiber.Cookie{
Name: "authorization_token",
Value: token,
})
c.Cookie(&fiber.Cookie{
Name: "username",
Value: username,
})
return c.Redirect("/")
}
func Logout(c *fiber.Ctx) error {
c.Cookie(&fiber.Cookie{
Name: "authorization_token",
Value: "",
Expires: time.Now(),
})
return c.Redirect("/login")
}
func NotFound(c *fiber.Ctx) error {
return c.Render("home/404", fiber.Map{})
}
Loading