This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a password selection page (#568)
* password reset form * dont use initializer
- Loading branch information
Showing
3 changed files
with
148 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,115 @@ | ||
{{define "login/select-password"}} | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
{{template "floatingform" .}} | ||
{{template "head" .}} | ||
{{template "firebase" .}} | ||
</head> | ||
|
||
<body class="bg-light"> | ||
<main role="main" class="container"> | ||
{{template "flash" .}} | ||
|
||
<div class="d-flex vh-100"> | ||
<div class="d-flex w-100 justify-content-center align-self-center"> | ||
<div class="col-sm-6"> | ||
<div class="card shadow-sm"> | ||
<div class="card-header">Select new password</div> | ||
<div class="card-body"> | ||
<form id="loginForm" class="floating-form" action="/" method="POST"> | ||
<div class="form-label-group"> | ||
<input type="email" id="email" name="email" class="form-control" placeholder="Email address" required | ||
autofocus /> | ||
<label for="email">Email address</label> | ||
</div> | ||
|
||
<div class="form-label-group mb-2"> | ||
<input type="password" id="password" name="password" class="form-control" placeholder="Password" | ||
autocomplete="new-password" required /> | ||
<label for="password">Password</label> | ||
</div> | ||
<div class="form-label-group"> | ||
<input type="password" id="retype" name="retype" class="form-control" placeholder="Retype password" | ||
autocomplete="new-password" required /> | ||
<label for="retype">Retype password</label> | ||
</div> | ||
|
||
<button type="submit" id="submit" class="btn btn-primary btn-block">Set password</button> | ||
</form> | ||
</div> | ||
<div class="card-body"> | ||
<a class="card-link" href="/">← Login</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
|
||
{{template "scripts" .}} | ||
{{template "loginscripts" .}} | ||
|
||
<script type="text/javascript"> | ||
$(function() { | ||
let $form = $('#loginForm'); | ||
let $submit = $('#submit'); | ||
let $email = $('#email'); | ||
let $password = $('#password'); | ||
let $retype = $('#retype'); | ||
|
||
let urlVars = getUrlVars(); | ||
let code = urlVars["oobCode"]; | ||
if (!code) { | ||
code = "" | ||
} | ||
|
||
firebase.auth().verifyPasswordResetCode(code) | ||
.then(function(email) { | ||
$email.val(email); | ||
}).catch(function(error) { | ||
flash.error("Invalid password reset code. " | ||
+ "The code may be malformed, expired, or has already been used."); | ||
$submit.prop('disabled', true); | ||
}); | ||
|
||
$form.on('submit', function(event) { | ||
event.preventDefault(); | ||
|
||
let email = $email.val(); | ||
let pwd = $password.val(); | ||
if (pwd != $retype.val()) { | ||
flash("Password and retyped passwords must match.", "danger"); | ||
return; | ||
} | ||
|
||
// Disable the submit button so we only attempt once. | ||
$submit.prop('disabled', true); | ||
|
||
firebase.auth().confirmPasswordReset(code, pwd) | ||
.then(function() { | ||
flash.alert("New password confirmed."); | ||
}).catch(function(error) { | ||
clearExistingFlash(); | ||
flash.error(error) | ||
$submit.prop('disabled', false); | ||
}); | ||
}); | ||
}); | ||
|
||
function getUrlVars() { | ||
let vars = [], hash; | ||
let queryParams = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); | ||
for (var i = 0; i < queryParams.length; i++) { | ||
v = queryParams[i].split('='); | ||
vars.push(v[0]); | ||
vars[v[0]] = v[1]; | ||
} | ||
return vars; | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> | ||
{{end}} |
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,32 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package login defines the controller for the login page. | ||
package login | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/google/exposure-notifications-verification-server/pkg/controller" | ||
) | ||
|
||
func (c *Controller) HandleSelectPassword() http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
ctx := r.Context() | ||
|
||
m := controller.TemplateMapFromContext(ctx) | ||
m["firebase"] = c.config.Firebase | ||
c.h.RenderHTML(w, "login/select-password", m) | ||
}) | ||
} |