Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Switch show-code to GET #777

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
29 changes: 13 additions & 16 deletions cmd/server/assets/codestatus/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ <h1>Verification code status</h1>
<div class="card mb-3 shadow-sm">
<div class="card-header">Code status</div>
<div class="card-body">
<form method="POST" id="code-form" action="show" class="floating-form">
{{ .csrfField }}
<form class="floating-form">
<div class="form-group">
<div class="form-label-group ">
<input type="text" id="uuid" name="uuid"
Expand All @@ -41,10 +40,10 @@ <h1>Verification code status</h1>
Identifier given from the Issue Code form.
</small>
</div>
</div>
</form>

<button class="btn btn-primary btn-block">Check status</button>
</form>
<button class="btn btn-primary btn-block" id="check">Check status</button>
</div>
</div>
</div>

Expand All @@ -53,7 +52,7 @@ <h1>Verification code status</h1>
<div class="card-body">
<div class="list-group">
{{range $code := .recentCodes}}
<a class="list-group-item list-group-item-action" onclick="clickCode('{{$code.UUID}}')">
<a href="/code/show/{{$code.UUID}}" class="list-group-item list-group-item-action">
{{$code.UUID}}
<small class="form-text text-muted">
Created at: {{$code.CreatedAt}}
Expand All @@ -67,12 +66,10 @@ <h1>Verification code status</h1>

{{template "scripts" .}}
<script type="text/javascript">
let $uuid
let $form

$(function() {
$uuid = $('#uuid');
$form = $('#code-form');
let $check= $('#check');
let $uuid = $('#uuid');

let allowedChars = new RegExp("[0-9a-fA-F]");
let dashLocations = [8, 13, 18, 23];

Expand All @@ -91,12 +88,12 @@ <h1>Verification code status</h1>
}
$uuid.val(r);
});
});

function clickCode(uuid) {
$uuid.val(uuid);
$form.submit();
}
$check.click(function(e) {
e.preventDefault();
window.location.assign("/code/show/"+$uuid.val());
});
});
</script>
</body>

Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func realMain(ctx context.Context) error {

codeStatusController := codestatus.NewServer(ctx, cfg, db, h)
sub.Handle("/status", codeStatusController.HandleIndex()).Methods("GET")
sub.Handle("/show", codeStatusController.HandleShow()).Methods("POST")
sub.Handle("/show/{uuid}", codeStatusController.HandleShow()).Methods("GET")
sub.Handle("/{uuid}/expire", codeStatusController.HandleExpirePage()).Methods("PATCH")
}

Expand Down
21 changes: 5 additions & 16 deletions pkg/controller/codestatus/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ import (

"github.com/google/exposure-notifications-verification-server/pkg/controller"
"github.com/google/exposure-notifications-verification-server/pkg/database"
"github.com/gorilla/mux"
)

func (c *Controller) HandleShow() http.Handler {
type FormData struct {
UUID string `form:"uuid"`
}

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)

realm := controller.RealmFromContext(ctx)
if realm == nil {
Expand All @@ -50,18 +48,9 @@ func (c *Controller) HandleShow() http.Handler {
controller.MissingSession(w, r, c.h)
return
}
flash := controller.Flash(session)

retCode := Code{}

var form FormData
if err := controller.BindForm(w, r, &form); err != nil {
flash.Error("Failed to process form: %v", err)
c.renderShow(ctx, w, retCode)
return
}

if form.UUID == "" {
if vars["uuid"] == "" {
var code database.VerificationCode
code.AddError("uuid", "cannot be blank")

Expand All @@ -71,10 +60,10 @@ func (c *Controller) HandleShow() http.Handler {
return
}

code, _, apiErr := c.CheckCodeStatus(r, form.UUID)
code, _, apiErr := c.CheckCodeStatus(r, vars["uuid"])
if apiErr != nil {
var code database.VerificationCode
code.UUID = form.UUID
code.UUID = vars["uuid"]
code.AddError("uuid", apiErr.Error)

if err := c.renderStatus(ctx, w, realm, currentUser, &code); err != nil {
Expand Down