Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseto committed Jun 28, 2016
2 parents 6113399 + 21a1f7c commit 5ddd39e
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
*.a
*.so

# fakeCAS binary
fakecas

# Folders
_obj
_test
vendor

# Architecture specific extensions/prefixes
*.[568vq]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fake CAS

Download the binary from [here](https://github.com/CenterForOpenScience/fakecas/releases/download/0.2.0/fakecas)
Download the binary from [here](https://github.com/CenterForOpenScience/fakecas/releases/latest)

```bash
cd ~/Downloads # cd to where you downloaded the file to
Expand All @@ -12,4 +12,5 @@ chmod +x fakecas # Make the server executable
# -dbaddress="localhost:27017": The address of your mongodb. ie: localhost:27017
# -dbname="osf20130903": The name of your OSF database
# -host="localhost:8080": The host to bind to
# -osfhost="localhost:5000": The osf host to bind to
```
16 changes: 13 additions & 3 deletions fakecas.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
mw "github.com/labstack/echo/middleware"
"github.com/rs/cors"
"gopkg.in/mgo.v2"
"html/template"
"os"
)

var (
Host = flag.String("host", "localhost:8080", "The host to bind to")
OSFHost = flag.String("osfhost", "localhost:5000", "The osf host to bind to")
DatabaseName = flag.String("dbname", "osf20130903", "The name of your OSF database")
DatabaseAddress = flag.String("dbaddress", "localhost:27017", "The address of your mongodb. ie: localhost:27017")
DatabaseSession mgo.Session
Expand All @@ -21,9 +23,10 @@ var (
)

func main() {
fmt.Println("Starting FakeCAS 0.8.0")
flag.Parse()
e := echo.New()
e.Use(mw.LoggerFromConfig(mw.LoggerConfig{
e.Use(mw.LoggerWithConfig(mw.LoggerConfig{
Format: "${time_rfc3339} ${method} ${uri} ${status} ${response_time} ${response_size}\n",
Output: os.Stdout,
}))
Expand All @@ -37,8 +40,15 @@ func main() {
ExposedHeaders: []string{"Range", "Content-Type", "Authorization", "X-Requested-With"},
}).Handler))

e.Get("/login", Login)
e.Post("/login", Login)
t, err := template.New("login").Parse(LOGINPAGE)
if err != nil {
panic(err)
}
temp := &Template{templates: t}
e.SetRenderer(temp)

e.Get("/login", LoginGET)
e.Post("/login", LoginPOST)
e.Get("/logout", Logout)
e.Get("/oauth2/profile", OAuth)
e.Get("/p3/serviceValidate", ServiceValidate)
Expand Down
43 changes: 43 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package: github.com/CenterForOpenScience/fakecas
import:
- package: github.com/labstack/echo
subpackages:
- engine/standard
- middleware
- package: github.com/rs/cors
- package: gopkg.in/mgo.v2
subpackages:
- bson
94 changes: 55 additions & 39 deletions static.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,65 @@
package main

var UNREGISTERED = `<html lang="en" class=" js no-mobile desktop no-ie chrome chrome49 root-section gradient rgba opacity textshadow multiplebgs boxshadow borderimage borderradius cssreflections csstransforms csstransitions no-touch no-retina fontface domloaded w-2307 gt-240 gt-320 gt-480 gt-640 gt-768 gt-800 gt-1024 gt-1280 gt-1440 gt-1680 gt-1920 no-portrait landscape" id="login-page"><head>
<meta charset="UTF-8">
var LOGINPAGE = `{{define "login"}}
<title>Open Science Framework | Sign In</title>
<!DOCTYPE html>
<html>
<head>
<title>Open Science Framework | Sign In</title>
</head>
<link rel="stylesheet" href="//staging-accounts.osf.io/css/cas.css">
<link rel="icon" href="//staging-accounts.osf.io/favicon.ico" type="image/x-icon">
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]--><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script><style type="text/css">@media print{.lpiframeoverlay{display:none}}</style></head>
<body id="cas"><div id="lptopspacer80974089" style="height: 40px;"></div>
<div id="container">
<header>
<a id="logo" href="" title="Open Science Framework Sign In">Open Science Framework | Sign In</a>
</header>
<div id="content">
<div id="msg" class="errors">
<body>
<div id="header">
<span><h3>Open Science Framework | fakeCAS</h3></span>
<br>
</div>
<h2>Account has not been confirmed.</h2>
<p>This login email has been registered but not confirmed. Please check your email (and spam folder). <a href="https://staging.osf.io/resend/">Click here</a> to resend your confirmation email.</p>
</div>
{{if .NotRegistered}}
<div id="message">
<p>This login email has been registered but not confirmed. Please check your email (and spam folder). <a href={{.OSFResendConfirmation}}>Click here</a> to resend your confirmation email.</p>
</div>
{{end}}
<div class="row" style="text-align: center;">
<hr>
<a href="https://staging.osf.io/">Back to OSF</a>
{{if .NotAuthorized}}
<div id="message">
<p>The service you attempted to authenticate to is not authorized to use CAS.</p>
</div>
</div> <!-- END #content -->
{{end}}
<footer>
<div class="copyright">
<div class="row">
<p>Copyright © 2011-2015 <a href="http://centerforopenscience.org">Center for Open Science</a> |
<a href="https://github.com/CenterForOpenScience/centerforopenscience.org/blob/master/TERMS_OF_USE.md">Terms of Use</a> |
<a href="https://github.com/CenterForOpenScience/centerforopenscience.org/blob/master/PRIVACY_POLICY.md">Privacy Policy</a>
</p>
</div>
{{if .NotValid}}
<p>Invalid request. User does not exist or invalid/expired validation key.</p>
{{end}}
{{if .LoginForm}}
<div id="forms">
<form id="login" action="{{.CASLogin}}" method="post">
<section>
<span>Email:</span>&nbsp;&nbsp;
<input id="username" name="username" type="text" value="" size="" />&nbsp;&nbsp;
<input id="submit" type="submit" value="Sign In" />
{{if .NotExist}}
&nbsp;&nbsp;<span>User does not exist.</span>
{{end}}
</section>
<section hidden>
<br>
<span>Password:</span>&nbsp;&nbsp;
<input id="password", name="password", type="password", value="" />&nbsp;&nbsp;
<input id="persistence" name="persistence", type="checkbox" value="true" checked />
<label id="for-persistence">Stay Signed In</label>
</section>
</form>
</div>
{{end}}
<br>
<div id="links">
<section>
<a id="forgot-password" href={{.OSFForgotPassword}}>Forgot Your Password?</a><br>
<a id="institution-login" href={{.OSFInstitutionLogin}}>Login Through Your Institution</a><br>
<a id="back-to-osf" href={{.OSFDomain}}>Back to OSF</a><br>
<a id="create-account" href={{.OSFCreateAccount}}>Create Account</a>
</section>
</div>
</footer>
</body>
</html>
</div> <!-- END #container -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/headjs/1.0.3/head.min.js"></script>
<script type="text/javascript" src="//staging-accounts.osf.io/js/cas.js"></script>`
{{end}}`
63 changes: 63 additions & 0 deletions static/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{define "login"}}

<!DOCTYPE html>
<html>
<head>
<title>Open Science Framework | Sign In</title>
</head>

<body>
<div id="header">
<span><h3>Open Science Framework | fakeCAS</h3></span>
<br>
</div>

{{if .NotRegistered}}
<div id="message">
<p>This login email has been registered but not confirmed. Please check your email (and spam folder). <a href={{.OSFResendConfirmation}}>Click here</a> to resend your confirmation email.</p>
</div>
{{end}}

{{if .NotAuthorized}}
<div id="message">
<p>The service you attempted to authenticate to is not authorized to use CAS.</p>
</div>
{{end}}

{{if .NotValid}}
<p>Invalid request. User does not exist or invalid/expired validation key.</p>
{{end}}
{{if .LoginForm}}
<div id="forms">
<form id="login" action="{{.CASLogin}}" method="post">
<section>
<span>Email:</span>&nbsp;&nbsp;
<input id="username" name="username" type="text" value="" size="" />&nbsp;&nbsp;
<input id="submit" type="submit" value="Sign In" />
{{if .NotExist}}
&nbsp;&nbsp;<span>User does not exist.</span>
{{end}}
</section>
<section hidden>
<br>
<span>Password:</span>&nbsp;&nbsp;
<input id="password", name="password", type="password", value="" />&nbsp;&nbsp;
<input id="persistence" name="persistence", type="checkbox" value="true" checked />
<label id="for-persistence">Stay Signed In</label>
</section>
</form>
</div>
{{end}}
<br>
<div id="links">
<section>
<a id="forgot-password" href={{.OSFForgotPassword}}>Forgot Your Password?</a><br>
<a id="institution-login" href={{.OSFInstitutionLogin}}>Login Through Your Institution</a><br>
<a id="back-to-osf" href={{.OSFDomain}}>Back to OSF</a><br>
<a id="create-account" href={{.OSFCreateAccount}}>Create Account</a>
</section>
</div>
</body>
</html>

{{end}}
41 changes: 33 additions & 8 deletions types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "encoding/xml"
import (
"encoding/xml"
"html/template"
)

type OAuthAttributes struct {
LastName string `json:"lastName"`
Expand All @@ -14,13 +17,14 @@ type OAuthResponse struct {
}

type User struct {
Id string `bson:"_id"`
Username string `bson:"username"`
Emails []string `bson:"emails"`
Fullname string `bson:"fullname"`
GivenName string `bson:"given_name"`
FamilyName string `bson:"family_name"`
IsRegistered bool `bson:"is_registered"`
Id string `bson:"_id"`
Username string `bson:"username"`
Emails []string `bson:"emails"`
Fullname string `bson:"fullname"`
GivenName string `bson:"given_name"`
FamilyName string `bson:"family_name"`
IsRegistered bool `bson:"is_registered"`
VerificationKey string `bson:"verification_key"`
}

type ServiceResponse struct {
Expand All @@ -43,3 +47,24 @@ type AccessToken struct {
TokenId string `bson:"token_id"`
Scopes string `bson:"scopes"`
}

type Template struct {
templates *template.Template
}

type TemplateGlobal struct {
// login flow
LoginForm bool
NotExist bool
NotValid bool
NotAuthorized bool
NotRegistered bool
// cas url
CASLogin string
// osf url
OSFCreateAccount string
OSFDomain string
OSFForgotPassword string
OSFInstitutionLogin string
OSFResendConfirmation string
}
Loading

0 comments on commit 5ddd39e

Please sign in to comment.