Apos-People Reset Password customization

20 views
Skip to first unread message

Fotis Paraskevopoulos

unread,
Jul 9, 2015, 4:38:57 AM7/9/15
to apostr...@googlegroups.com
Hello Tom,

I need to customize several aspects of the Apos-People reset password functionality without throwing out all of your implementation.

Specifically I need:

1) To change the "Email From" of the e-mail being sent
2) To change the "url" parameter which is appended to the e-mail. At the moment it seems that this is a HOST environment variable, but in this specific case our urls are a bit more dynamic than that and are created at runtime.


Before writing my own implementation which copies your :) any pointers?

Fotis Paraskevopoulos

unread,
Jul 9, 2015, 8:54:24 AM7/9/15
to apostr...@googlegroups.com
Hello Again,

Ok so it seems I can override stuff under apostrophe-people { email: }  in app.js. But I have a follow up question.


Can I add the option of the "email" in data/local.js, I can't seem to figure that out ? 

Can I use a function which returns a "baseUrl" at runtime instead of a static value?

Thanks,
FP

Tom Boutell

unread,
Jul 10, 2015, 9:13:47 AM7/10/15
to apostr...@googlegroups.com
Everything in data/local.js is merged with the object you pass to apostrophe-site. It's a deep merge. So you can just set up

module.exports = {
  modules: {
    apostrophe-people: {
      email: whatever
    }
  }
}

Etc.

--
You received this message because you are subscribed to the Google Groups "apostrophenow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apostropheno...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


THOMAS BOUTELL, DEV & OPS
P'UNK AVENUE | (215) 755-1330  |  punkave.com

Tom Boutell

unread,
Jul 10, 2015, 9:14:07 AM7/10/15
to apostr...@googlegroups.com
Currently baseUrl cannot be dynamic ordinarily. However you could write middleware that repopulates baseUrl.

Fotis Paraskevopoulos

unread,
Jul 10, 2015, 9:16:19 AM7/10/15
to apostr...@googlegroups.com
Thanks Tom,

Is that apsotrophe middleware or express middleware?

FP

Tom Boutell

unread,
Jul 10, 2015, 9:18:07 AM7/10/15
to apostr...@googlegroups.com
Express middleware... as long as you set req.baseUrl early, and you *don't* set it in local.js/app.js, it should be respected.

Tom Boutell

unread,
Jul 10, 2015, 9:18:44 AM7/10/15
to apostr...@googlegroups.com
Use the "middleware" option in app.js to install it. That'll "use" it before the wildcard route is installed and it's too late.

Fotis Paraskevopoulos

unread,
Jul 13, 2015, 6:21:48 AM7/13/15
to apostr...@googlegroups.com
Hello Tom,

There seems to be a chicken and egg issue here.

You write "as long as you set req.baseUrl early, and you *don't* set it in local.js/app.js, it should be respected" but it seems that baseUrl is set using the "hostName" option in app.js. However if I remove that option then app.js doesn't start and displays 

"Specify the `hostName` option and set it to the preferred hostname of your site, such as mycompany.com"

That means that in apostrophe/lib/emailMixin.js:182  "self.options.baseUrl" will always be set which in turn means that req.baseUrl will never be used.

What am I missing here?

Best,
FP

Tom Boutell

unread,
Jul 13, 2015, 8:01:48 AM7/13/15
to apostr...@googlegroups.com
      var baseUrl = self.options.baseUrl || req.baseUrl || (req.protocol + '://' + req.get('Host'));

The option wins.

Are you using up to date code?

Fotis Paraskevopoulos

unread,
Jul 14, 2015, 2:47:53 PM7/14/15
to apostr...@googlegroups.com
Hello Tom,

Thanks for getting back. Yes I am using up to date code.

The problem as you state is that the "option" does win, but neither in my app.js nor in local.js I have **not** specified "baseUrl" anywhere.

Upon debugging I found out that self.options.baseUrl somehow inherits from the  "hostName" variable **required** in app.js. This means that "self.options.baseUrl" is **always** set in turn means that req.baseUrl will never be used even though I set it in my middleware.

Is this clearer?  Any ideas?

Best,
Fotis

Tom Boutell

unread,
Jul 14, 2015, 3:14:33 PM7/14/15
to apostr...@googlegroups.com
OK, now I am confused... why aren't you setting baseUrl in data/local.js? Isn't that what you wanted?

Fotis Paraskevopoulos

unread,
Jul 14, 2015, 3:29:57 PM7/14/15
to apostr...@googlegroups.com
Hello Tom,

I can understand why you are confused, please bear with me, I will start from the beginning.


My initial question was:

"How can I dynamically set baseUrl" which is used in the email template.


After our discussion we concluded that the best way to do so is to set req.baseUrl in a custom middleware. 

So this is my current approach just to test it out:


   function(site,req,res,next){
      req.baseUrl = "http://acme.com"
      next();
   }


Even though req.baseUrl is set in the middleware,  it does not work because in the emailMixin.js code 

   var baseUrl = self.options.baseUrl || req.baseUrl || (req.protocol + '://' + req.get('Host'));



first checks for "self.options.baseUrl". I  **do not** set this either on app.js or in local.js because I want the code to use req.baseUrl. Even though I do not set this anywhere in my code "self.options.baseUrl" is always set to the **required** configuration option "hostName", which is mandatory. 


This means that "self.options.baseUrl" is always set, and req.baseUrl is never used.


I hope this is clearer now.


FP












Fotis Paraskevopoulos

unread,
Jul 20, 2015, 4:53:24 AM7/20/15
to Fotis Paraskevopoulos, apostr...@googlegroups.com
Hello Tom,


Here is a fork of the Sandbox which shows the issue with baseUrl.





All you need to do is add a user that can log in, and then go through the "Forgot Password" flow. As you can see the req.baseUrl set in the middleware is completely ignored.


Best,
Fotis

 

Fotis Paraskevopoulos

unread,
Jul 22, 2015, 11:56:56 AM7/22/15
to apostr...@googlegroups.com
Hello Again,

Sorry to be bumping this, but short of re-implementing the reset password functionality (which I really really really like to avoid) I haven't been able to figure out what is wrong here.

Best,
FP

Tom Boutell

unread,
Jul 24, 2015, 9:36:13 AM7/24/15
to apostr...@googlegroups.com
Hi Fotis,

Just published this fix. req.baseUrl wins. I checked and it's never set automatically by standard middleware, so if it's there we can safely assume it's important and coming from the developer.
Reply all
Reply to author
Forward
0 new messages