-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is why you don't let friends push code for you.
- Loading branch information
Showing
14 changed files
with
560 additions
and
31 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,13 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/robfig/revel" | ||
) | ||
|
||
type API struct { | ||
App | ||
} | ||
|
||
func (c API) Documentation() revel.Result { | ||
return c.Render() | ||
} |
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
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,92 @@ | ||
package controllers | ||
|
||
import ( | ||
"code.google.com/p/go.crypto/bcrypt" | ||
"encoding/hex" | ||
"github.com/huntaub/list/app/routes" | ||
"github.com/robfig/revel" | ||
"labix.org/v2/mgo" | ||
"strings" | ||
) | ||
|
||
type User struct { | ||
Email string | ||
HashedPassword string | ||
FullName string | ||
ClassBucket []string | ||
} | ||
|
||
var users *mgo.Collection | ||
|
||
func init() { | ||
session, _ := mgo.Dial("mongodb://leath:hunter0813@oceanic.mongohq.com:10000/list") | ||
users = session.DB("list").C("users") | ||
} | ||
|
||
type Users struct { | ||
*revel.Controller | ||
} | ||
|
||
func (u *Users) Login(email string, password string) revel.Result { | ||
var user *User | ||
err := users.Find(map[string]string{"email": email}).One(&user) | ||
if err != nil { | ||
u.Flash.Error("Incorrect username or password.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
bytes, _ := hex.DecodeString(user.HashedPassword) | ||
if bcrypt.CompareHashAndPassword(bytes, []byte(password)) != nil { | ||
u.Flash.Error("Incorrect username or password.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
u.Session["user"] = email | ||
|
||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
func (u *Users) Register(name string, email string, password string, cpassword string) revel.Result { | ||
if name == "" { | ||
u.Flash.Error("Name is required.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
if email == "" { | ||
u.Flash.Error("Email is required.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
if !strings.HasSuffix(email, "@virginia.edu") { | ||
u.Flash.Error("Only @virginia.edu emails allowed.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
if password == "" { | ||
u.Flash.Error("Password is required.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
if password != cpassword { | ||
u.Flash.Error("Passwords do not match.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
var existing *User | ||
if users.Find(map[string]string{"email": email}).One(&existing) == nil { | ||
u.Flash.Error("Someone with that email has already registered.") | ||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
pass, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) | ||
users.Insert(&User{ | ||
Email: email, | ||
FullName: name, | ||
HashedPassword: hex.EncodeToString(pass), | ||
}) | ||
|
||
u.Session["user"] = email | ||
|
||
return u.Redirect(routes.App.Index()) | ||
} | ||
|
||
func (u *Users) Logout() revel.Result { | ||
delete(u.Session, "user") | ||
return u.Redirect(routes.App.Index()) | ||
} |
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,73 @@ | ||
{{set . "title" "API Documentation" }} | ||
{{ append . "moreScripts" "js/prism.js" }} | ||
{{ append . "moreStyles" "css/prism.css" }} | ||
{{template "header.html" .}} | ||
|
||
<div class="container" id="main"> | ||
<div class="row"> | ||
<div class="col-md-4" style="position: fixed; top: 70px;"> | ||
<ul class="list-unstyled nav-list"> | ||
<li><a href="#overview" class="visit">Overview</a></li> | ||
<li><a href="#class">Class Information</a></li> | ||
<li><a href="#">Department Information</a></li> | ||
<li><a href="#">Schedule Building</a></li> | ||
</ul> | ||
</div> | ||
<div class="col-md-8 col-md-offset-4"> | ||
<h1 id="overview">Leath's List API Documentation</h1> | ||
<p>The Leath's List API was created in order to free class data fully from SIS. It allows students and faculty to create applications that rely on the Data scraped from Lou's List and more without having to go through that work themselves.</p> | ||
<p>In order to use the documentation, you must be registered through Leath's List and have a working "API Key" which you can find by clicking "API" and "Account Settings" on the navbar above.</p> | ||
<h3 id="class">Class Information</h3> | ||
<p><code>GET /api/YOUR_API_KEY/class</code></p> | ||
<p>The Class API will return information about a class (enrollment, name, sections) by sending information about the class.</p> | ||
<h4>Input</h4> | ||
<pre style="padding-top: 0; padding-bottom: 0;"> | ||
<code class="language-javascript"> | ||
{ | ||
"department": "CS", | ||
"number": 2110 | ||
} | ||
</code> | ||
</pre> | ||
<h4>Output</h4> | ||
<pre style="padding-top: 0; padding-bottom: 0;"> | ||
<code class="language-javascript"> | ||
{ | ||
name: "Software Development Methods", | ||
department: "CS", | ||
number: 2110, | ||
sections: [ | ||
{ | ||
number: 1, | ||
type: "Lecture", // or "Discussion", "Laboratory", "Seminar", etc.. | ||
sisnumber: 17567, | ||
meetings: [ | ||
{ | ||
location: "Rice Hall 130", | ||
instructor: "Thomas Horton", | ||
starttime: ISODate("0-01-01T10:00:00Z"), // EST | ||
endtime: ISODate("0-01-01T10:50:00Z"), | ||
days: [1, 3, 5], // Days of the Week where 0 = Sunday | ||
tba: false | ||
} | ||
], | ||
capacity: 110, | ||
enrollment: 106, | ||
topic: "", | ||
credits: 3 | ||
}, | ||
] | ||
} | ||
</code> | ||
</pre> | ||
<h3 id="class">Department Information</h3> | ||
<p><code>GET /api/YOUR_API_KEY/department</code></p> | ||
<p>The Class API will return a list of classes by department mnemonic.</p> | ||
<h3 id="class">Schedule Building</h3> | ||
<p><code>GET /api/YOUR_API_KEY/schedule</code></p> | ||
<p>The Schedule API will return a list of schedules from a list of classes.</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{{template "footer.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
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
Oops, something went wrong.