This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c0b1b90
Showing
13 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*] | ||
indent_style=space | ||
indent_size=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
leprechaun-prototype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
type jsonErr struct { | ||
Code int `json:"code"` | ||
Text string `json:"text"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
// "strconv" | ||
// "github.com/gorilla/mux" | ||
// "encoding/json" | ||
) | ||
|
||
func Index(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "text/html; charset=utf-8") | ||
b, err := ioutil.ReadFile("index.html") | ||
if err != nil { | ||
fmt.Fprintf(w, "Could not read HTML file from disk. Error: %v", err) | ||
} else { | ||
fmt.Fprintf(w, "%s", b) | ||
} | ||
} | ||
|
||
func BeginAuth(w http.ResponseWriter, r *http.Request) { | ||
r.ParseForm() | ||
roll := r.PostForm.Get("roll") | ||
email := r.PostForm.Get("email") | ||
|
||
if !validRoll(roll) { | ||
fmt.Fprintf(w, "Roll number not valid. Please try again") | ||
return | ||
} | ||
|
||
if !validEmail(email) { | ||
fmt.Fprintf(w, "Email not valid. Please try again") | ||
return | ||
} | ||
|
||
fmt.Fprint(w, "You have submitted valid roll and email") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
// TODO | ||
func validRoll(roll string) bool { | ||
return true | ||
} | ||
|
||
// TODO | ||
func validEmail(email string) bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Leprechaun - KGP ERP Authentication Service</title> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
|
||
<!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> | ||
</head> | ||
<body style="margin:40px;"> | ||
|
||
<div class="container"> | ||
<header class="header clearfix"> | ||
<nav> | ||
<ul class="nav nav-pills float-right"> | ||
<li class="nav-item"> | ||
<a class="nav-link active" href="/">Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" | ||
href="https://github.com/metakgp" | ||
target="_blank">Github</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="https://metakgp.github.io" target="_blank">About</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
<h3>Leprechaun</h3> | ||
</header> | ||
|
||
<main role="main"> | ||
|
||
<div class="jumbotron"> | ||
<h1 class="display-3"> | ||
Leprechaun - KGP ERP Authentication service | ||
</h1> | ||
<h3> | ||
Authenticate yourself now! Connect your email ID to your | ||
roll number, and enjoy the myriad services provided | ||
throughout the campus! | ||
</h3> | ||
</div> | ||
|
||
<form method="POST" action="/auth"> | ||
<input type="text" name="roll" placeholder="Enter your roll number" | ||
autofocus /> | ||
<br> | ||
<input type="text" name="email" placeholder="Enter your email address" | ||
/> | ||
<br> | ||
<input type="submit" value="Begin authentication process now!"> | ||
</form> | ||
|
||
</main> | ||
|
||
<footer class="footer"> | ||
<hr> | ||
<p>Leprechaun - Metakgp 2017</p> | ||
</footer> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
func Logger(inner http.Handler, name string) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
|
||
inner.ServeHTTP(w, r) | ||
|
||
log.Printf( | ||
"%s\t%s\t%s\t%s", | ||
r.Method, | ||
r.RequestURI, | ||
name, | ||
time.Since(start), | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"github.com/joho/godotenv" | ||
"os" | ||
) | ||
|
||
func main() { | ||
|
||
err := godotenv.Load() | ||
if err != nil { | ||
log.Print("Error loading .env file") | ||
} | ||
|
||
router := NewRouter() | ||
|
||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./public")))) | ||
|
||
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
var currentId int | ||
|
||
var todos Todos | ||
|
||
// Give us some seed data | ||
func init() { | ||
RepoCreateTodo(Todo{Name: "Write presentation"}) | ||
RepoCreateTodo(Todo{Name: "Host meetup"}) | ||
} | ||
|
||
func RepoFindTodo(id int) Todo { | ||
for _, t := range todos { | ||
if t.Id == id { | ||
return t | ||
} | ||
} | ||
// return empty Todo if not found | ||
return Todo{} | ||
} | ||
|
||
//this is bad, I don't think it passes race condtions | ||
func RepoCreateTodo(t Todo) Todo { | ||
currentId += 1 | ||
t.Id = currentId | ||
todos = append(todos, t) | ||
return t | ||
} | ||
|
||
func RepoDestroyTodo(id int) error { | ||
for i, t := range todos { | ||
if t.Id == id { | ||
todos = append(todos[:i], todos[i+1:]...) | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("Could not find Todo with id of %d to delete", id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
func NewRouter() *mux.Router { | ||
|
||
router := mux.NewRouter().StrictSlash(true) | ||
for _, route := range routes { | ||
var handler http.Handler | ||
|
||
handler = route.HandlerFunc | ||
handler = Logger(handler, route.Name) | ||
|
||
router. | ||
Methods(route.Method). | ||
Path(route.Pattern). | ||
Name(route.Name). | ||
Handler(handler) | ||
|
||
} | ||
|
||
return router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import "net/http" | ||
|
||
type Route struct { | ||
Name string | ||
Method string | ||
Pattern string | ||
HandlerFunc http.HandlerFunc | ||
} | ||
|
||
type Routes []Route | ||
|
||
var routes = Routes{ | ||
Route{ | ||
"Index", | ||
"GET", | ||
"/", | ||
Index, | ||
}, | ||
Route{ | ||
"BeginAuth", | ||
"POST", | ||
"/auth", | ||
BeginAuth, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import "time" | ||
|
||
type Todo struct { | ||
Id int `json:"id"` | ||
Name string `json:"name"` | ||
Completed bool `json:"completed"` | ||
Due time.Time `json:"due"` | ||
} | ||
|
||
type Todos []Todo |