From 787bdf1641615881e0169e7974431b741e6dc486 Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Thu, 16 Feb 2017 15:22:59 +0100 Subject: [PATCH 1/3] Fix Forgot Password link positioning Fixes #321 --- lib/views/base.jade | 12 +++++++++++- lib/views/verify.jade | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/views/base.jade b/lib/views/base.jade index 6942170a..82d0840d 100644 --- a/lib/views/base.jade +++ b/lib/views/base.jade @@ -219,7 +219,6 @@ html(class='no-js', lang='en') .view a.forgot, .view a.to-login { float: right; - padding: 17px 0; font-size: 13px; } @@ -296,12 +295,23 @@ html(class='no-js', lang='en') margin-top: 2em; } + .login-view .forgot-password-area { + padding: 17px 15px; + } + + @media (min-width: 767px) { + .login-view .forgot-password-area { + padding: 17px 50px; + } + } + .login-view .email-password-area { background-color: white; border-top-left-radius: 3px; border-bottom-left-radius: 3px; } + @media (min-width: 767px) { .login-view .email-password-area { padding: 0 30px; diff --git a/lib/views/verify.jade b/lib/views/verify.jade index ee5a85e7..03a4fdd2 100644 --- a/lib/views/verify.jade +++ b/lib/views/verify.jade @@ -58,4 +58,5 @@ block body button.login.btn.btn-login.btn-sp-green(type='submit') Submit if stormpathConfig.web.login.enabled - a.forgot(href="#{stormpathConfig.web.login.uri}") Back to Log In + div.forgot-password-area.col-xs-12 + a.forgot(href="#{stormpathConfig.web.login.uri}") Back to Log In From 49df9879411036b25f6da612566c18df1b507eea Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Thu, 16 Feb 2017 17:22:03 +0100 Subject: [PATCH 2/3] Migrate from Jade to Pug --- docs/templates.rst | 4 ++-- lib/controllers/login.js | 2 +- lib/helpers/render.js | 20 +++++++++---------- lib/views/{base.jade => base.pug} | 4 ++-- ...ange-password.jade => change-password.pug} | 0 ..._failed.jade => facebook_login_failed.pug} | 0 ...ogin_form.jade => facebook_login_form.pug} | 0 ...rgot-password.jade => forgot-password.pug} | 2 +- ..._login_form.jade => github_login_form.pug} | 0 ...in_failed.jade => google_login_failed.pug} | 0 ..._login_form.jade => google_login_form.pug} | 0 ...d.jade => id_site_verification_failed.pug} | 0 ...ogin_form.jade => linkedin_login_form.pug} | 0 lib/views/{login.jade => login.pug} | 20 ++++++++++--------- ...on-select.jade => organization-select.pug} | 2 +- lib/views/{register.jade => register.pug} | 2 +- .../{unauthorized.jade => unauthorized.pug} | 0 ...omplete.jade => verification_complete.pug} | 2 +- ..._sent.jade => verification_email_sent.pug} | 0 ...on_failed.jade => verification_failed.pug} | 0 lib/views/{verify.jade => verify.pug} | 4 ++-- package.json | 2 +- 22 files changed, 33 insertions(+), 31 deletions(-) rename lib/views/{base.jade => base.pug} (99%) rename lib/views/{change-password.jade => change-password.pug} (100%) rename lib/views/{facebook_login_failed.jade => facebook_login_failed.pug} (100%) rename lib/views/{facebook_login_form.jade => facebook_login_form.pug} (100%) rename lib/views/{forgot-password.jade => forgot-password.pug} (95%) rename lib/views/{github_login_form.jade => github_login_form.pug} (100%) rename lib/views/{google_login_failed.jade => google_login_failed.pug} (100%) rename lib/views/{google_login_form.jade => google_login_form.pug} (100%) rename lib/views/{id_site_verification_failed.jade => id_site_verification_failed.pug} (100%) rename lib/views/{linkedin_login_form.jade => linkedin_login_form.pug} (100%) rename lib/views/{login.jade => login.pug} (87%) rename lib/views/{organization-select.jade => organization-select.pug} (97%) rename lib/views/{register.jade => register.pug} (93%) rename lib/views/{unauthorized.jade => unauthorized.pug} (100%) rename lib/views/{verification_complete.jade => verification_complete.pug} (88%) rename lib/views/{verification_email_sent.jade => verification_email_sent.pug} (100%) rename lib/views/{verification_failed.jade => verification_failed.pug} (100%) rename lib/views/{verify.jade => verify.pug} (95%) diff --git a/docs/templates.rst b/docs/templates.rst index b60f939f..fbc03182 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -42,8 +42,8 @@ in the source code: https://github.com/stormpath/stormpath-express/tree/master/l .. note:: - Our library includes Jade and our default templates are written in Jade. If you - are using custom templates that are not written in Jade, you must enable a + Our library includes Pug and our default templates are written in Pug. If you + are using custom templates that are not written in Pug, you must enable a view renderer in your Express application. Please see `Using template engines with Express`_. diff --git a/lib/controllers/login.js b/lib/controllers/login.js index 0c932ba8..1e9571b8 100644 --- a/lib/controllers/login.js +++ b/lib/controllers/login.js @@ -97,7 +97,7 @@ module.exports = function (req, res, next) { var oauthStateToken = oauth.common.resolveStateToken(req, res); var hasSocialProviders = _.some(config.web.social, function (socialProvider) { - return socialProvider.enabled; + return socialProvider.providerId !== 'saml' && socialProvider.enabled; }); extend(options, { diff --git a/lib/helpers/render.js b/lib/helpers/render.js index 3f4cb2bc..d2d24f74 100644 --- a/lib/helpers/render.js +++ b/lib/helpers/render.js @@ -2,31 +2,31 @@ var path = require('path'); -var jade = require('jade'); +var pug = require('pug'); var mixin = require('utils-merge'); var viewCache = {}; -function renderJade(filepath, locals) { +function renderPug(filepath, locals) { var env = process.env.NODE_ENV; if (env === 'production') { if (!viewCache[filepath]) { - viewCache[filepath] = jade.compileFile(filepath); + viewCache[filepath] = pug.compileFile(filepath); } return viewCache[filepath](locals); } - return jade.renderFile(filepath, locals); + return pug.renderFile(filepath, locals); } /** * Render a view using app locals. * - * By default, use Jade as it is necessary because our library can't rely - * on the developer using Jade view as well -- so this allows us to use - * Jade templates for our library views, without negatively affecting the + * By default, use Pug as it is necessary because our library can't rely + * on the developer using Pug view as well -- so this allows us to use + * Pug templates for our library views, without negatively affecting the * developer's application. * * If, however, the developer has supplied a render handler in their settings, @@ -52,9 +52,9 @@ module.exports = function (req, res, view, options) { if (!extension && (filename === view)) { // This means that we have received a default config option, such as // 'login' - just continue to render our default page. - res.send(renderJade(path.join(path.dirname(__dirname), 'views', view + '.jade'), options)); - } else if (extension === '.jade') { - res.send(renderJade(view, options)); + res.send(renderPug(path.join(path.dirname(__dirname), 'views', view + '.pug'), options)); + } else if (extension === '.pug') { + res.send(renderPug(view, options)); } else if (extension) { // Delegate to the view engine. res.render(view, options); diff --git a/lib/views/base.jade b/lib/views/base.pug similarity index 99% rename from lib/views/base.jade rename to lib/views/base.pug index 82d0840d..dfd6b8c5 100644 --- a/lib/views/base.jade +++ b/lib/views/base.pug @@ -9,7 +9,7 @@ html(class='no-js', lang='en') head meta(charset='utf-8') title #{title} - meta(content='#{description}', name='description') + meta(content=description, name='description') meta(content='width=device-width', name='viewport') link(href='//fonts.googleapis.com/css?family=Open+Sans:300italic,300,400italic,400,600italic,600,700italic,700,800italic,800', rel='stylesheet', type='text/css') link(href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css', rel='stylesheet') @@ -420,7 +420,7 @@ html(class='no-js', lang='en') block head - body(class='#{bodytag}') + body(class=bodytag) block body diff --git a/lib/views/change-password.jade b/lib/views/change-password.pug similarity index 100% rename from lib/views/change-password.jade rename to lib/views/change-password.pug diff --git a/lib/views/facebook_login_failed.jade b/lib/views/facebook_login_failed.pug similarity index 100% rename from lib/views/facebook_login_failed.jade rename to lib/views/facebook_login_failed.pug diff --git a/lib/views/facebook_login_form.jade b/lib/views/facebook_login_form.pug similarity index 100% rename from lib/views/facebook_login_form.jade rename to lib/views/facebook_login_form.pug diff --git a/lib/views/forgot-password.jade b/lib/views/forgot-password.pug similarity index 95% rename from lib/views/forgot-password.jade rename to lib/views/forgot-password.pug index 1e436815..75eca6cd 100644 --- a/lib/views/forgot-password.jade +++ b/lib/views/forgot-password.pug @@ -51,4 +51,4 @@ block body button.login.btn.btn-login.btn-sp-green(type='submit') Send Email if stormpathConfig.web.login.enabled - a.forgot(href="#{stormpathConfig.web.login.uri}") Back to Log In + a.forgot(href=stormpathConfig.web.login.uri) Back to Log In diff --git a/lib/views/github_login_form.jade b/lib/views/github_login_form.pug similarity index 100% rename from lib/views/github_login_form.jade rename to lib/views/github_login_form.pug diff --git a/lib/views/google_login_failed.jade b/lib/views/google_login_failed.pug similarity index 100% rename from lib/views/google_login_failed.jade rename to lib/views/google_login_failed.pug diff --git a/lib/views/google_login_form.jade b/lib/views/google_login_form.pug similarity index 100% rename from lib/views/google_login_form.jade rename to lib/views/google_login_form.pug diff --git a/lib/views/id_site_verification_failed.jade b/lib/views/id_site_verification_failed.pug similarity index 100% rename from lib/views/id_site_verification_failed.jade rename to lib/views/id_site_verification_failed.pug diff --git a/lib/views/linkedin_login_form.jade b/lib/views/linkedin_login_form.pug similarity index 100% rename from lib/views/linkedin_login_form.jade rename to lib/views/linkedin_login_form.pug diff --git a/lib/views/login.jade b/lib/views/login.pug similarity index 87% rename from lib/views/login.jade rename to lib/views/login.pug index 48373397..6c207f9b 100644 --- a/lib/views/login.jade +++ b/lib/views/login.pug @@ -23,8 +23,10 @@ block body p. Before you can log into your account, you need to activate your account by clicking the link we sent to your inbox. - p. - Didn't get the email? Click Here. + p + | Didn't get the email? + a(href=stormpathConfig.web.verifyEmail.uri) Click Here + | . br if status === 'verified' span. @@ -80,7 +82,7 @@ block body div(class='form-group group-' + field.name) label( class='col-sm-' + (hasSocialProviders ? 12 : 4), - for='#{field.name}' + for=field.name ) #{field.label} div(class='col-sm-' + (hasSocialProviders ? 12 : 8)) @@ -103,15 +105,15 @@ block body .header   label Easy 1-click login: if socialProviders.facebook && socialProviders.facebook.enabled - include facebook_login_form.jade + include facebook_login_form if socialProviders.google && socialProviders.google.enabled - include google_login_form.jade + include google_login_form if socialProviders.linkedin && socialProviders.linkedin.enabled - include linkedin_login_form.jade + include linkedin_login_form if socialProviders.github && socialProviders.github.enabled - include github_login_form.jade + include github_login_form if stormpathConfig.web.verifyEmail.enabled - a.forgot(style="float:left", href="#{stormpathConfig.web.verifyEmail.uri}") Resend Verification Email? + a.forgot(style="float:left", href=stormpathConfig.web.verifyEmail.uri) Resend Verification Email? if stormpathConfig.web.forgotPassword.enabled - a.forgot(style="float:right", href="#{stormpathConfig.web.forgotPassword.uri}") Forgot Password? + a.forgot(style="float:right", href=stormpathConfig.web.forgotPassword.uri) Forgot Password? diff --git a/lib/views/organization-select.jade b/lib/views/organization-select.pug similarity index 97% rename from lib/views/organization-select.jade rename to lib/views/organization-select.pug index 07160081..7e392a18 100644 --- a/lib/views/organization-select.jade +++ b/lib/views/organization-select.pug @@ -39,7 +39,7 @@ block body div(class='form-group group-' + field.name) label( class='col-sm-12', - for='#{field.name}' + for=field.name ) #{field.label} div(class='col-sm-8') diff --git a/lib/views/register.jade b/lib/views/register.pug similarity index 93% rename from lib/views/register.jade rename to lib/views/register.pug index d3d94f39..87cd29ba 100644 --- a/lib/views/register.jade +++ b/lib/views/register.pug @@ -24,7 +24,7 @@ block body form.registration-form.form-horizontal.sp-form(method='post', role='form') each field in formModel.fields - div(form-group='true', class='form-group group-#{field.name}') + div(form-group='true', class='form-group group-' + field.name) label.col-sm-4 #{field.label} .col-sm-8 - var value = form ? form[field.name] : ''; diff --git a/lib/views/unauthorized.jade b/lib/views/unauthorized.pug similarity index 100% rename from lib/views/unauthorized.jade rename to lib/views/unauthorized.pug diff --git a/lib/views/verification_complete.jade b/lib/views/verification_complete.pug similarity index 88% rename from lib/views/verification_complete.jade rename to lib/views/verification_complete.pug index d58c6607..254e6c60 100644 --- a/lib/views/verification_complete.jade +++ b/lib/views/verification_complete.pug @@ -6,7 +6,7 @@ block vars - var bodytag = 'login' block head - meta(http-equiv='refresh' content="5; url=#{app.get('stormpathRedirectUrl')}") + meta(http-equiv='refresh' content='5; url=' + app.get('stormpathRedirectUrl')) block body .container.custom-container diff --git a/lib/views/verification_email_sent.jade b/lib/views/verification_email_sent.pug similarity index 100% rename from lib/views/verification_email_sent.jade rename to lib/views/verification_email_sent.pug diff --git a/lib/views/verification_failed.jade b/lib/views/verification_failed.pug similarity index 100% rename from lib/views/verification_failed.jade rename to lib/views/verification_failed.pug diff --git a/lib/views/verify.jade b/lib/views/verify.pug similarity index 95% rename from lib/views/verify.jade rename to lib/views/verify.pug index 03a4fdd2..ff31f2c6 100644 --- a/lib/views/verify.jade +++ b/lib/views/verify.pug @@ -1,6 +1,6 @@ extends base -block vars +block prepend vars - var title = 'Resend Account Verification Email?' - var description = 'Didn\'t receive your account verification email? No worries!' - var bodytag = 'login' @@ -59,4 +59,4 @@ block body if stormpathConfig.web.login.enabled div.forgot-password-area.col-xs-12 - a.forgot(href="#{stormpathConfig.web.login.uri}") Back to Log In + a.forgot(href=stormpathConfig.web.login.uri) Back to Log In diff --git a/package.json b/package.json index 38d69267..808246e1 100644 --- a/package.json +++ b/package.json @@ -30,11 +30,11 @@ "deep-extend": "^0.4.1", "express": "^4.13.4", "forms": "^1.1.4", - "jade": "^1.11.0", "lodash": "^4.6.1", "njwt": "^0.3.1", "parse-iso-duration": "^1.0.0", "psl": "^1.1.14", + "pug": "^2.0.0-beta11", "qs": "^6.0.2", "request": "^2.63.0", "stormpath": "0.20.x", From 9e11db75dd4d973179e26273d257c00ecb221a0f Mon Sep 17 00:00:00 2001 From: Luka Skukan Date: Fri, 17 Feb 2017 10:39:40 +0100 Subject: [PATCH 3/3] Use configured 'unauthorized' view in groups-required --- lib/middleware/groups-required.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/middleware/groups-required.js b/lib/middleware/groups-required.js index aaceffcb..d512a441 100644 --- a/lib/middleware/groups-required.js +++ b/lib/middleware/groups-required.js @@ -83,7 +83,11 @@ module.exports = function (groups, all) { isUserInGroups(function (err, isInGroup) { if (err || !isInGroup) { res.status(403); - return helpers.render(req, res, 'unauthorized'); + var view = config.web.unauthorized && config.web.unauthorized.view + ? config.web.unauthorized.view + : 'unauthorized'; + + return helpers.render(req, res, view); } next();