Skip to content
Permalink
Browse files
API support for Lockdown
  • Loading branch information
hijohnnylin committed Feb 6, 2020
1 parent 4a7290d commit 69be43c013fb2dfff80377b13a617089011b1b02
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
@@ -57,12 +57,16 @@ router.get("/reset-password",
.isLength({ min: 32, max: 32 }).withMessage("Invalid reset code.")
.isAlphanumeric().withMessage("Invalid reset code.")
.trim(),
check("lockdown")
.toBoolean(false),
validateCheck
],
(request, response, next) => {
const code = request.values.code;
const lockdown = request.values.lockdown;
response.render("reset-password", {
code: code
code: code,
lockdown: lockdown
});
});

@@ -82,14 +86,22 @@ router.post("/reset-password",
passwordRules(value);
return value;
}),
check("lockdown")
.toBoolean(false),
validateCheck
],
(request, response, next) => {
const code = request.values.code;
const newPassword = request.values.newPassword;
const lockdown = request.values.lockdown;
User.resetPassword(code, newPassword)
.then( success => {
request.flashRedirect("success", "New password set successfully.", "/signin");
if (lockdown) {
return response.render("reset-password-success-lockdown");
}
else {
request.flashRedirect("success", "New password set successfully.", "/signin");
}
})
.catch(error => { next(error); });
});
@@ -82,20 +82,23 @@ router.post("/signup",
body("refer")
.isEmpty()
]),
check("lockdown")
.toBoolean(false),
validateCheck
],
(request, response, next) => {
const email = request.values.email;
const password = request.values.password;
const browser = request.values.browser;
const refer = request.values.refer;
const lockdown = request.values.lockdown;
var chain = Promise.resolve();
if (refer) {
chain = User.getReferrerUserId(refer);
}
return chain
.then(referrerUserId => {
return User.createWithEmailAndPassword(email, password, browser, referrerUserId);
return User.createWithEmailAndPassword(email, password, browser, referrerUserId, lockdown);
})
.then(user => {
if (browser) {
@@ -131,15 +134,21 @@ router.get(["/confirm-email"],
.trim(),
query("browser")
.toBoolean(false),
check("lockdown")
.toBoolean(false),
validateCheck
],
(request, response, next) => {
const email = decodeURI(request.values.email);
const code = request.values.code;
const browser = request.values.browser;
const lockdown = request.values.lockdown;
return User.confirmEmail(code, email)
.then(success => {
if (browser) {
if (lockdown) {
return response.render("confirm-email-success-lockdown");
}
else if (browser) {
return request.flashRedirect("success", "Email confirmed. Please sign in.", "/signin?redirecturi=" + encodeURI("/new-subscription?browser=true"));
}
else {
@@ -167,11 +176,14 @@ router.post("/resend-confirm-code",
.exists().withMessage("Missing email address.")
.isEmail().withMessage("Invalid email address.")
.normalizeEmail(),
check("lockdown")
.toBoolean(false),
validateCheck
],
(request, response, next) => {
const email = request.values.email;
User.resendConfirmCode(email)
const lockdown = request.values.lockdown;
User.resendConfirmCode(email, true)
.then( results => {
request.flashRedirect("info", "Confirmation email re-sent. Be sure to check your spam folder, as sometimes the email can get stuck there.", "/signin");
})
@@ -0,0 +1,33 @@
{{> header title="Lockdown Notification" }}

<body class="text-center">

{{> nav-loggedout }}

<div class="container mt-5">
<div class="col-xl-4 offset-xl-4 col-md-6 offset-md-3 col-sm-8 offset-sm-2 text-left">

<div class="alert alert-success" role="alert" style="margin-left:auto; margin-right: auto;">
Email confirmed. Redirecting you back to finish signup...
</div>

<div class="container-fluid p-3 mt-3 confirmed-bg">
<p style="font-size: 12px; margin-bottom: 4px; text-align: center;">If you aren't redirected, click below:</p>
<a href="lockdown://emailconfirmed" id="backButton" class="btn confirmed-blue-btn btn-sm text-white btn-block mt-2">Open Lockdown</a>

</div>
</div>
</div>

{{> footer}}

{{> bootstrapjs}}

<script>
setTimeout(function(){
window.location.href = 'lockdown://emailconfirmed';
}, 2000);
</script>

</body>

@@ -0,0 +1,33 @@
{{> header title="Lockdown Notification" }}

<body class="text-center">

{{> nav-loggedout }}

<div class="container mt-5">
<div class="col-xl-4 offset-xl-4 col-md-6 offset-md-3 col-sm-8 offset-sm-2 text-left">

<div class="alert alert-success" role="alert" style="margin-left:auto; margin-right: auto;">
Password successfully reset. Redirecting you back to Lockdown...
</div>

<div class="container-fluid p-3 mt-3 confirmed-bg">
<p style="font-size: 12px; margin-bottom: 4px; text-align: center;">If you aren't redirected, click below:</p>
<a href="lockdown://resetsuccessful" id="backButton" class="btn confirmed-blue-btn btn-sm text-white btn-block mt-2">Open Lockdown</a>

</div>
</div>
</div>

{{> footer}}

{{> bootstrapjs}}

<script>
setTimeout(function(){
window.location.href = 'lockdown://resetsuccessful';
}, 2000);
</script>

</body>

@@ -11,7 +11,7 @@

<div class="container-fluid p-3 mt-5 confirmed-panel">
<h1 class="h5 text-center">Reset Password</h1>
<form action="/reset-password?code={{code}}" onsubmit="return validatePasswordMatch()" method="POST">
<form action="/reset-password?code={{code}}&lockdown={{lockdown}}" onsubmit="return validatePasswordMatch()" method="POST">
<input type="hidden" id="code" style="display:none" name="code" value="{{code}}">
<p style="font-size: 11px; margin-bottom: 2px">New Password</p>
<div style="margin-bottom: 6px;">

0 comments on commit 69be43c

Please sign in to comment.