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

update documentation #14

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</a>
</div>

_Heimdall checks the client's IP to know whether the request has originated from inside the IIT Kharagpur network. This helps to ascertain if the client is a current member of the institute and should have access to certain information._
_Heimdall checks the client's IP to know whether the request has originated from inside the IIT Kharagpur network and verifies their institute email ID. This helps to ascertain if the client is a current member of the institute and should have access to certain information._

<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down Expand Up @@ -89,6 +89,12 @@ The following dependencies are required to be installed for the project to funct
<!-- UPDATE -->

- [go](https://go.dev/)
- [nodejs](https://nodejs.org/en/download/package-manager)

To create credentials.json file, create the [OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent#configure_oauth_consent) and then create [OAuth client ID credentials](https://developers.google.com/workspace/guides/create-credentials#oauth-client-id) by following the steps provided there. While creating OAuth client ID credentials, set redirect URL to any port of the localhost. Then save downloaded json file as credentials.json in the project's root folder.

Then enable [Gmail API](https://console.cloud.google.com/apis/library/gmail.googleapis.com) to enable receiving OTP.


<p align="right">(<a href="#top">back to top</a>)</p>

Expand All @@ -102,15 +108,52 @@ _Now that the environment has been set up and configured to properly compile and
```sh
git clone https://github.com/metakgp/heimdall.git
```
2. Install dependencies
2. Configure environment variables
```sh
cd ./heimdall
cp .env.template .env
```
Choose a strong JWT_SECRET_KEY and edit the .env file accordingly.

3. Install go dependencies
```sh
go mod download
```
3. Execute the script
4. Compile the code
```sh
go build
```
5. Install node modules
```sh
cd frontend
npm install
```
It is suggested to use pnpm as package manager due to its efficiency. To use pnpm, run following commands instead of above:
```sh
npm install -g pnpm
cd frontend
pnpm install
```

6. Start development server
```sh
go run main.go
npm run dev
cd ..
```
7. Execute the script
```sh
./heimdall
```

When prompted to enter authorization code, visit the link provided in terminal which will redirect to localhost. Then inspect the url after redirection and copy the string after `code=` and paste it in the terminal. This will create `token.json` file. You need to create this token only once and it will be valid for 6 months.

<p align="right">(<a href="#top">back to top</a>)</p>

### How to use?

Enter your institute mail id in the box provided on screen. You will receive an OTP if the provided mail id is a valid institute mail id. In that case, enter the OTP received at the provided email address and verify. These verifies that you are a current member of the institute.

Next, you will have access to services like [Naarad](https://github.com/metakgp/naarad) and [Chillzone](https://github.com/metakgp/chillzone) which are available only for KGPians. These can be accessed via the campus network.

<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down
43 changes: 20 additions & 23 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
# React + TypeScript + Vite
# Frontend

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
## Heimdall

Currently, two official plugins are available:
Heimdall checks the client's IP to know whether the request has originated from inside the IIT Kharagpur network and verifies their institute email ID. This helps to ascertain if the client is a current member of the institute and should have access to certain information.

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
### Running locally

## Expanding the ESLint configuration
First install [nodejs](https://nodejs.org/en/download/package-manager). Then install `pnpm` by running `npm install -g pnpm`.

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
Then follow the given steps to start the development server:

- Configure the top-level `parserOptions` property like this:
1. Clone the repository
```sh
git clone https://github.com/metakgp/heimdall.git
```
2. Install dependencies
```sh
cd heimdall/frontend
pnpm install
```
3. Start the server
```sh
npm run dev
```

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
This setup will launch the frontend. To start backend server also, please follow the instructions [here](https://github.com/metakgp/heimdall/blob/master/README.md#getting-started)
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Heimdall : Metakgp</title>
<title>Heimdall : MetaKGP</title>
</head>
<body>
<div id="root"></div>
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ const Form = () => {
});
setOtpRequested(true);
} else {
toast.error("Failed to send OTP. Please try again", {
id: loadingToast,
response.text().then((msg) => {
toast.error(msg, {
id: loadingToast,
});
});
}
})
Expand Down Expand Up @@ -90,7 +92,7 @@ const Form = () => {
<div className="form-container">
<div className="info">
<div className="title">Heimdall</div>
<p>The gatekeeper to Metakgp services</p>
<p>The gatekeeper to MetaKGP services</p>
<p>Please verify using your kgpian email to continue</p>
</div>
<div className="form">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { servicesList } from "./constants";
const Services = () => {
return (
<div className="services-container">
<div className="title">Metakgp Services</div>
<div className="title">MetaKGP Services</div>
<div className="subtitle">
Click on any of the links below to visit
</div>
Expand Down
4 changes: 2 additions & 2 deletions mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ func sendMail(receiverEmail string, subject string, body string) (bool, error) {
}

func sendOTP(receiverEmail string, otp string) (bool, error) {
subject := "Metakgp verification OTP"
body := "OTP for Sign In into Heimdall Portal of Metakgp, IIT Kharagpur is " + otp
subject := "MetaKGP verification OTP"
body := "OTP for Sign In into Heimdall Portal of MetaKGP, IIT Kharagpur is " + otp

return sendMail(receiverEmail, subject, body)
}