1
0
forked from sm/vain

Fix error reporting on registration.

- fleshed out documentation (fixing #30)
- added forgot page
This commit is contained in:
Stephen McQuay 2016-05-22 11:41:51 -07:00
parent c99f57527f
commit 48d723a582
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D
7 changed files with 202 additions and 100 deletions

View File

@ -26,7 +26,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<a href="/about/">About</a> <a href="/_static/register/">register</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -34,15 +34,27 @@
</nav> </nav>
<div class="container"> <div class="container">
<div class="row"> <h1>Forgot token</h1>
<div class="col-lg-12 text-center"> <p>If you've forgotten your token please provide an email and instructions will be sent you you.</p>
<h1>Vain</h1>
<p class="lead">vaind is a vanity url server for use by the go tool.</p> <div id="alert" class="alert alert-danger" style="display: none;">placeholder</div>
<h2>Installation</h2> <div id="success" class="alert alert-success" style="display: none;" role="alert">...</div>
<p>running $ go get mcquay.me/vain/cmd/vaind</p>
<h2>Running Server</h2>
<p>$ vaind database</p> <div id="input" class="row">
<div class="col-md-2"></div>
<div class="input-group col-md-6">
<span class="input-group-addon">
<span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="text" class="form-control" id="name" placeholder="Email address" autofocus>
<span class="input-group-btn">
<button id="send" class="btn btn-block" type="button">
<span class="glyphicon glyphicon-send"></span> &nbsp; Submit
</button>
</span>
</div> </div>
<div class="col-md-4"></div>
</div> </div>
</div> </div>

View File

@ -26,7 +26,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li> <li>
<a href="/_static/about/">About</a> <a href="/_static/register/">register</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -34,21 +34,29 @@
</nav> </nav>
<div class="container"> <div class="container">
<div class="row"> <h1>Vain</h1>
<div class="col-lg-12 text-center"> <p class="lead"> This server implements <a href="https://golang.org/cmd/go/#hdr-Remote_import_paths">remote import paths</a> for use by the <a href="https://golang.org/cmd/go/">go tool</a>. </p>
<h1>Register Email</h1>
<div class="input-group input-group-lg"> <h2>Adding a repository</h2>
<span class="input-group-addon"> <p>
<span class="glyphicon glyphicon-envelope"></span> The first step is to obtain an api key. Visit the <a href="/_static/register/">registration page</a>
</span> and follow the instructions to obtain a key.
<input type="text" class="form-control input-sm" id="name" placeholder="Email address" autofocus> </p>
</div> <p> Let's say you've got some code hosted at <code>https://git.example.com/user/foo</code> that you'd like to publish with <code>/me/foo</code>. Armed with the token you previously obtained (e.g. <code>c033-b79f-7fa1</code>) </p>
<p>
<pre>
$ export TOKEN=c033-b79f-7fa1
$ curl -i -H "Authorization: Bearer $TOKEN" -d '{"repo": "https://git.example.com/user/foo"}' https://vain/me/foo </pre>
</p>
<h2>Deleting a repository</h2>
<p>Using the appropriate token for the route you want to delete:</p>
<pre>
$ curl -i -H "Authorization: Bearer $TOKEN" -X DELETE https://vain/me/foo </pre>
<h2>go tool</h2>
<p> The <a href="https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies">go tool</a> doesn't need any modification in order to work, e.g. if vain is hosted on <code>https://go.example.com</code>: </p> <pre>$ go get go.example.com/foo</pre>
<p> should just work. A possible wrinkle is if the site is not hosted using TLS. In which case please encrypt your site. If this is impossible and you're not concerned with adversarial manipulation of your source (as would perhaps be the case during development) you can tell the go tool to run in insecure mode. Use with caution. </p>
<button id="send" class="btn btn-lg btn-block" type="button">
<span class="glyphicon glyphicon-send"></span> &nbsp; Submit
</button>
</div>
</div>
</div> </div>
<script src="/_static/js/jquery.js"></script> <script src="/_static/js/jquery.js"></script>

View File

@ -17,19 +17,27 @@ $(function() {
function send() { function send() {
$("#alert").hide(); $("#alert").hide();
$("#success").hide();
var name = $("#name").val(); var name = $("#name").val();
if (name == "") { if (name == "") {
$("#name-holder").removeClass("has-warning has-default").addClass("has-error"); $("#name-holder").removeClass("has-warning has-default").addClass("has-error");
$("#alert").show().text("Please provide an email address."); $("#alert").show().text("Please provide an email address.");
} else { } else {
$.get( route = "/api/v0/register/?email="+name;
"/api/v0/register/?email="+name if(window.location.href.indexOf("forgot") > -1) {
).done(function(data) { route = "/api/v0/forgot/?email="+name;
$("#name").val(""); }
console.log(data); $.get(route).done(
}).fail(function(e) { function(data) {
$("#alert").show().text(e.statusText + ": " + e.responseText); $("#input").val("").hide();
console.error(data);
$("#success").text(data["msg"]).show();
}
).fail(
function(e) {
$("#alert").show().text(e.responseText);
console.error(e); console.error(e);
}); }
);
} }
}; };

View File

@ -0,0 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/_static/css/bootstrap.min.css" rel="stylesheet">
<link href="/_static/css/vain.css" rel="stylesheet">
<title>vain</title>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">Vain</a>
</div>
</div>
</nav>
<div class="container">
<h1>Registration</h1>
<p>Please provide your email and instructions will be sent to your email.</p>
<div id="alert" class="alert alert-danger" style="display: none;">placeholder</div>
<div id="success" class="alert alert-success" style="display: none;" role="alert">...</div>
<div id="input" class="row">
<div class="col-md-2"></div>
<div class="input-group col-md-6">
<span class="input-group-addon">
<span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="text" class="form-control" id="name" placeholder="Email address" autofocus>
<span class="input-group-btn">
<button id="send" class="btn btn-block" type="button">
<span class="glyphicon glyphicon-send"></span> &nbsp; Submit
</button>
</span>
</div>
<div class="col-md-4"></div>
</div>
<p style="padding-top: 40px"><small>If you've forgotten your token please <a href="/_static/forgot/">request instructions to recover</a> a token.</small></p>
</div>
<script src="/_static/js/jquery.js"></script>
<script src="/_static/js/bootstrap.min.js"></script>
<script src="/_static/js/vain.js"></script>
</body>
</html>

View File

@ -154,7 +154,13 @@ func (s *Server) register(w http.ResponseWriter, req *http.Request) {
proto = "http" proto = "http"
} }
log.Printf("%s://%s/api/v0/confirm/%+v", proto, req.Host, tok) log.Printf("%s://%s/api/v0/confirm/%+v", proto, req.Host, tok)
fmt.Fprintf(w, "please check your email\n") resp := struct {
Msg string `json:"msg"`
}{
Msg: "please check your email\n",
}
w.Header().Set("Content-type", "application/json")
json.NewEncoder(w).Encode(resp)
} }
func (s *Server) confirm(w http.ResponseWriter, req *http.Request) { func (s *Server) confirm(w http.ResponseWriter, req *http.Request) {
@ -192,7 +198,13 @@ func (s *Server) forgot(w http.ResponseWriter, req *http.Request) {
return return
} }
log.Printf("http://%s/api/v0/confirm/%+v", req.Host, tok) log.Printf("http://%s/api/v0/confirm/%+v", req.Host, tok)
fmt.Fprintf(w, "please check your email\n") resp := struct {
Msg string `json:"msg"`
}{
Msg: "please check your email\n",
}
w.Header().Set("Content-type", "application/json")
json.NewEncoder(w).Encode(resp)
} }
func (s *Server) pkgs(w http.ResponseWriter, req *http.Request) { func (s *Server) pkgs(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-type", "application/json") w.Header().Set("Content-type", "application/json")

View File

@ -68,7 +68,7 @@ func (fi bindataFileInfo) Sys() interface{} {
return nil return nil
} }
var _sqlInitSql = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x74\x8f\xc1\x4e\x84\x30\x14\x45\xf7\xfd\x8a\xb7\x64\x12\x17\xee\x5d\xd5\xf2\x26\x21\x32\xa8\x9d\x92\xc8\xb2\xc2\x0b\x12\xa0\x45\x0a\x7e\xbf\x0d\x4d\x15\xe3\xd0\x5d\x7b\x6f\x7a\xce\x15\x12\xb9\x42\x50\xfc\x31\x47\x58\x1d\xcd\x0e\x12\x06\xfe\xd0\xa8\xbb\x01\x14\xbe\x29\x78\x91\xd9\x85\xcb\x0a\x9e\xb0\xba\xdb\xb2\xc5\xf6\x64\x42\x56\x16\xd9\x6b\x89\xe1\x79\xa6\xb6\x73\x0b\xcd\xd4\xc0\xbb\xb5\x03\x69\x03\x29\x9e\x79\x99\x2b\xb8\x8f\x8d\xcf\x95\x7c\xa5\x81\xd4\x53\x55\x76\x41\x76\x7a\x60\xec\x8f\x84\xd1\x23\xb9\x49\xd7\x14\x4d\x8c\x3b\xd0\xd8\x29\x4a\x3c\xa3\xc4\x42\xe0\x35\x8c\x48\xb6\xec\x04\xcf\x85\x57\xc8\xd1\x7f\x2e\xf8\x55\xf0\xf4\x06\xcf\xa3\x7a\xdd\xfe\xd0\xbe\xea\x80\x8b\xc2\x93\xdd\x5d\x27\xbd\x7c\xfc\xdf\x1d\x05\x77\x12\xbf\x23\x12\xe3\x0e\x34\xbe\x03\x00\x00\xff\xff\xc7\xbb\x93\xa7\x7b\x01\x00\x00") var _sqlInitSql = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x74\xcf\x31\x4f\xc3\x30\x14\x04\xe0\x3d\xbf\xe2\xc6\x54\x62\x60\x67\x32\xc9\x55\x8a\x48\x03\xb8\x2f\x12\x1d\x4d\xfa\x54\xaa\xb6\x4e\x88\x53\x7e\x3f\x52\x2d\x43\x10\xed\x68\xdf\x93\xee\xbb\xc2\xd2\x08\x21\xe6\xb1\x26\xce\x41\xc7\x80\x3c\x03\x00\x3d\xb9\xfd\x11\xc2\x37\xc1\x8b\xad\x56\xc6\x6e\xf0\xc4\xcd\xdd\x25\x9b\xfa\x83\xfa\x98\xb5\x4d\xf5\xda\x32\x7e\x8f\xba\xdb\x87\x49\x47\xdd\xe2\xbd\xef\x8f\xea\x3c\x4a\x2e\x4d\x5b\x0b\xee\xd3\xc5\xe7\x59\xc3\xa4\x5b\x94\x46\x28\xd5\x8a\xd9\xe2\x21\xcb\xfe\x20\xbc\x3b\x69\x18\x5c\xa7\x49\xe2\xc3\x0d\xc6\x8c\x68\xb9\xa4\x65\x53\x70\x1d\x47\xe4\x97\x6c\x81\xe7\x06\x25\x6b\x0a\x51\x98\x75\x61\xca\x2b\x7d\x83\xeb\x0e\x6e\xf7\xd3\xf6\xd5\xc5\xba\x04\x1e\xfa\xd9\x73\x70\xd3\xc7\xff\xdd\x09\x38\x43\xfc\x8e\xc8\x7d\xb8\xc1\xf8\x0e\x00\x00\xff\xff\xc7\xbb\x93\xa7\x7b\x01\x00\x00")
func sqlInitSqlBytes() ([]byte, error) { func sqlInitSqlBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@ -83,7 +83,7 @@ func sqlInitSql() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "sql/init.sql", size: 379, mode: os.FileMode(436), modTime: time.Unix(1461817783, 0)} info := bindataFileInfo{name: "sql/init.sql", size: 379, mode: os.FileMode(420), modTime: time.Unix(1463941605, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }

128
static.go

File diff suppressed because one or more lines are too long