Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Reset password script #458

Merged
merged 1 commit into from
Mar 27, 2015
Merged

Reset password script #458

merged 1 commit into from
Mar 27, 2015

Conversation

ilanbiala
Copy link
Member

I also added a scripts/ folder on 0.4.0, because we are missing one.

@lirantal
Copy link
Member

lirantal commented Mar 9, 2015

Hey @ilanbiala,

It needs some work to get it done:

  1. There's no ../config/lib/mongoose
  2. There's need to load the schemas like express.js is loading them through the getGlobbedFiles function

Can you work out the fixes and let's try again?

@wesleyfsmith
Copy link
Contributor

So does this only work if we have a mailer set up? Is there a way for us to do this without having to go through email, i.e. just do it for the user the next time they log in?

Thanks @ilanbiala for taking a crack at this.

@ilanbiala
Copy link
Member Author

@wesleyfsmith you can definitely add a flag to your model and set it to false and have the user reset and upon reset change it to true. That's a possible solution, too.

@ilanbiala
Copy link
Member Author

@lirantal I added a scripts folder, so now ../ goes to /, and then config/lib/mongoose is the mongoose connection handler file.

I believe the schemas are properly loaded now as well.

@ilanbiala
Copy link
Member Author

@lirantal Are there any other changes that need to be made?

@ilanbiala
Copy link
Member Author

@lirantal LGTY?

@ilanbiala ilanbiala modified the milestone: 0.4.0 Mar 23, 2015
@lirantal
Copy link
Member

I'm still unable to run it on the 0.4.0 branch.
I put the file in scripts/reset_password.js

04:25:12 {0.4.0 %} lirantal-meanjs-0.4$ node scripts/reset_password.js 

Application loaded using the "development" environment configuration

/lirantal-meanjs-0.4/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:299
          throw err;
                ^
TypeError: Object #<Object> has no method 'model'
    at /lirantal-meanjs-0.4/scripts/reset_password.js:9:22
    at /lirantal-meanjs-0.4/config/lib/mongoose.js:33:12

Did you try running it?

@ilanbiala
Copy link
Member Author

@lirantal just fixed the issue and it should be working now, let me know if you run into issues with the new script.

@lirantal
Copy link
Member

@ilanbiala did you remember to push the change? I'm getting the exact same error :)

@ilanbiala
Copy link
Member Author

Yep pushed and re based. It may be easier for you to just copy the raw or clone my fork branch.

@lirantal
Copy link
Member

@ilanbiala tried that too, still same error.
I put the file in scripts/ folder and I'm calling it from the top level meanjs folder with 'node scripts/reset-password.js'

it also complains on:

ReferenceError: transporter is not defined
    at Promise.<anonymous> (/lirantal-meanjs-0.4/scripts/reset-password.js:36:6)

@ilanbiala
Copy link
Member Author

Sorry, forgot the er. Should be good now. I also want to refactor the email functionality into a separate class, but I'll take care of that after.

@ilanbiala ilanbiala self-assigned this Mar 25, 2015
@lirantal
Copy link
Member

@ilanbiala great, it's running now, except a slight object issue - I noted in the code comments.

console.log('Error: ', err);
console.log('Could not send email for ', user.displayName);
} else {
console.log('Sent reset password email for ', user.displayName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notice that there's no user object here, only users.

@ilanbiala
Copy link
Member Author

@lirantal fixed code with your comments, let me know if anything else is missing. Also, should we have tests for this?

lirantal added a commit that referenced this pull request Mar 27, 2015
@lirantal lirantal merged commit 77535bd into meanjs:0.4.0 Mar 27, 2015
@lirantal
Copy link
Member

Looks good @ilanbiala I'm merging. Don't think we need to add tests for the script itself.

@mleanos
Copy link
Member

mleanos commented Jul 15, 2015

I'm having an issue with this script. I'm running just as @lirantal commented above.. from my top level meanjs folder. I've verified that my mailer config settings are getting set for the transporter correctly.

The script doesn't produce an error. It runs, and responds with "Sent all emails". However, no emails are sent; and it doesn't seem like the callback is getting executed.

My other emails, from my application, are being sent fine. For instance, when requesting a password reset. The only difference I notice with the forgot password, and this script, is that the callback is defined with err, info; the info param is not present in the password server controller.

Anyone else having issues with this? I'm using Amazon's SES.

@lirantal
Copy link
Member

@ilanbiala can you look into it now that we're on 0.4.0 branch? maybe some things changed with the merge from master?

@ilanbiala
Copy link
Member Author

@mleanos did you get any errors/logs before "Sent all emails". If you didn't, that seems like there are no users in the database. Can you check that?

@mleanos
Copy link
Member

mleanos commented Jul 15, 2015

@ilanbiala I logged events, and the user data to the console. The users were present, along with their emails. I verified that the transporter was getting populated with the correct config settings as well.

I didn't get any errors. The script correctly iterated through the users. However, it appears that the script stopped, or had an issue, with the sendMail line. All the other emails from the application are sending just fine; using the same config settings for the mailer.

I'll take a look at it again today, as I just merged the most recent changes. I did have some issues with merging the most recent changes from yesterday. Mostly, with dependencies. It could have been something funky going on with those issues.

@mleanos
Copy link
Member

mleanos commented Jul 16, 2015

@ilanbiala I've verified that I'm still having this issue, after merging the most recent commits from 0.4.0.

Is it working for you?

@ilanbiala
Copy link
Member Author

@mleanos can you log the sendMail and see what the message says?

@mleanos
Copy link
Member

mleanos commented Jul 16, 2015

@ilanbiala I logged the sendMail, and it output undefined for each iteration of my user's.

@lirantal
Copy link
Member

@mleanos is it possible that sendMail isn't defined in the configuration for the specific environment you are running this script with? would be good if you can check that angle.

@mleanos
Copy link
Member

mleanos commented Jul 16, 2015

@lirantal I've verified that my configuration settings are properly set to the transporter, with the createTransport method of nodemailer. I compared the transporter's configuration from this script, and from my applications password forgot server controller method. Both instances had the same settings.

My SES config was set properly. It's interesting to me that the sendMail method doesn't seem to be executing at all. The callback never gets fired. No errors, or any indication that anything went wrong with the sendMail.

I assume, this is working for you, in the most up to date 0.4.0 branch?

@mleanos
Copy link
Member

mleanos commented Jul 16, 2015

@lirantal Just to be sure. Can you clarify what you mean by the sendMail configuration being set in my environment?

If the sendMail wasn't configured correctly, due to the environment the script is running in, wouldn't the transporter settings not get set properly? Or is there something else that I'm not understanding?

@lirantal
Copy link
Member

@mleanos I was referring to the configuration here https://github.com/meanjs/mean/blob/0.4.0/config/env/development.js#L54-L61 - if it is set or not for your environment. If it's missing then obviously no emails will be sent out.

@mleanos
Copy link
Member

mleanos commented Jul 23, 2015

@lirantal Yes, those settings were definitely set. I was able to verify this by writing the settings to the console. Everything looked perfect. The email object had the correct properties as well.

@ilanbiala
Copy link
Member Author

@mleanos is the API key still in Mandrill or SendGrid or whatever service you are using, because I can't think of a reason for the sendMail not to log even..

@mleanos
Copy link
Member

mleanos commented Jul 23, 2015

Yes, it is. I'm using Amazon's SES. Using the same config settings, the sendMail works through my app. I don't have to run the script with any additional parameters to determine what ENV config should be used, right?

I'll look into any other possible reasons for this to fail, sometime today.

@mleanos
Copy link
Member

mleanos commented Aug 4, 2015

@lirantal @ilanbiala This has been resolved with #755 .

This can be closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants