meteor resetpassword is not working - meteor

i'm making custom meteor account.
referring to this url >> Building a customized accounts ui for Meteor
but i have problem.
if (Accounts._resetPasswordToken) {
Session.set('resetPassword', Accounts._resetPasswordToken);
}
client side called this code is always undifined.(Accounts._resetPasswordToken)
finally i want to call
Accounts.resetPassword(Session.get('resetPassword'), pw, function(err){

Related

Meteor Iron Router Login Route Pass-thru for Facebook accounts not working

The Issue:
When my regular users using the standard email/password 'accounts-password' go to a login redirected page , they can enter the credentials and the router will proceed to render the requested page.
For example:
/private_page (requires login). The user attempts to go to http://foo.com/private_page they are presented with the Login page. The user enters username/password correctly and now the /private_page displays.
This works, what does NOT work...
Same example as above, but now the user is authenticating with Facebook 'accounts-facebook'. Everything is the same as before and the user has succesful login with Facebook and is able to get into my web application except the route never displays the /private_page. It stays on the authenticated /login page without showing the login template.
IN A NUTSHELL
How do I make the facebook authenticated users pass-thru and route to the requested route like the regular password based users operate ?
Iron Router Config:
Router.onBeforeAction(function () {
if (!Meteor.userId() && !Meteor.loggingIn()) {
this.redirect('login');
this.stop();
} else {
this.next();
}
},{except: ['login', 'contact, 'terms']});
Meteor packages:
accounts-password#1.3.6
accounts-facebook#1.2.0
service-configuration#1.0.11
useraccounts:bootstrap
useraccounts:iron-routing
I finally came to a solution.
After reviewing the Github issues for the Meteor package: (meteor-useraccounts)I found the exact issue I have been having.
https://github.com/meteor-useraccounts/core/issues/685
I spent too much time trying to make the hooks fire correctly for my usage of oAuth Facebook with Meteor. My final solution was too just connect directly into the Meteor method calls and create my own login, registration, password reset, etc forms.
The up-side is that I now have full control of the forms and I don't need to deal with extra package.
If anyone comes finds this posting and is having issues making 'meteor-useraccounts' fire hooks like the postSignUpHook , you may decide to just scrap the package and make your own user account templates and connect the logic to use the native Meteor methods.
This particular question I submitted was because the oAuth Facebook would login but I was unable to make it redirect to the originally requested route. The oAuth works and my user can login to my web app, but I cannot get them to the originally requested url.
How did I solve this:
lib/routes
Router.onBeforeAction(function () {
if (!Meteor.userId() && !Meteor.loggingIn()) {
originalUrl = this.originalUrl;
this.redirect('login');
this.stop();
} else {
this.next();
}
},{except: ['login', 'resetPwd', 'help'] });
The key point to take away from the snippet above is the global variable I declare originalUrl. This is using the routers this.originalUrl. This url contains the original url that the user entered and is captured the moment before the iron-router redirects to the login page.
Now on the login page I created my two different login methods using my own custom template. They both are using the Meteor.loginWithPassword and Meteor.loginWithFacebook methods.
client/login.js
'click #fb-login' : function(e){
e.preventDefault();
Meteor.loginWithFacebook({}, function(err){
if(err) {
// some error occured
}
else {
if(Router.current().route._path == "/login" && typeof originalUrl == "undefined")
Router.go('/');
else
Router.go(originalUrl);
}
});
}
Hope this helps anyone else who might come across this issue.

How can I get the URL in Google AppMaker?

I am trying to get the current URL in an AppMaker app. However, the standard JavaScript ways do not work, ScriptApp is not available in AppMaker, and the objects that are in AppMaker do not return the correct URL (that starts with https://script.google.com).
Thanks for any suggestions.
You can run a backend/serverside script and use Apps Script
ScriptApp.getService().getUrl()
See the doc ScriptApp Documentation
To have an app URL on client side, you can load it during app startup. Firstly, let's create server script that returns app URL:
/**
* Get the URL of the published web app.
*/
function getAppUrl() {
return ScriptApp.getService().getUrl();
}
Open your Project settings and put next code to App startup script section:
loader.suspendLoad();
google.script.run.withSuccessHandler(function(url) {
appUrl = url;
loader.resumeLoad();
}).getAppUrl();
Now you are able to use appUrl everywhere in Client Scripts.
Using this approach you can create initial app config on startup that requires specific data from server.

Hijacking the Meteor accounts-ui logout button

I am using the accounts-ui package for Meteor to create a Sign-up/Log-in widget. I want users who are not signed in to be able to continue to use my app anonymously, so I want to detect when a user signs out.
As far as I can tell, there is a way to register a function when the user logs in but no similar event is triggered when the user logs out. The next best thing is the Meteor.logout(\[callback\]) command, which accepts a callback function.
I have found the following lines of code in /Users/<name>/.meteor/packages/accounts-ui-unstyled/.1.1.8.cfkrwq++os+web.browser+web.cordova/web.browser/login_buttons.js
Template.loginButtons.events({
'click #login-buttons-logout': function() {
Meteor.logout(function () {
loginButtonsSession.closeDropdown();
});
}
});
I want to add a call to a method of my own here, but I don't want this method to be called in all the projects where I use accounts-ui. I understand that I could copy the accounts-ui-unstyled/ folder to the packages folder at the root of this project, and modify it there, but then I will miss any updates that may be delivered for the package.
What is the best-practice method of intercepting the log-out call?
Another approach is just to track the logged-in state in a Tracker:
Tracker.autorun(function(){
if ( Meteor.userId() ){
... do things for a logged-in user
} else {
... do things for a logged-out user
}
});
This autorun block will run automatically whenever the login state changes as Meteor.userId() is a reactive data source.

Meteor: How can I use the user account information for my app to login to a fork of the Telescope app?

I have an app where users have already signed up. When a user clicks the telescope button in my app, they will be transferred to another server in which I am running my own fork of the telescope app.
Upon going to telescope I want to be able to automatically log the user in with the same account information as in my app. How can this be done? I can adjust the code for both Meteor apps since I am running them myself.
You need to set the Telescope app to use the accounts database of your other application.
You can do this by altering the Accounts.connection to use another Meteor app (your main app)
Add this line into your telescope app somewhere in the /server/lib directory:
var myOtherAppDDP = DDP.connect("http://your-other-app.com");
Accounts.connection = myOtherAppDDP;
This way the DDP connection for your accounts section of your meteor app will use your main apps database.
Next you need to transfer the login-tokens to the other app. For this you need to make a special link with the users current login token:
Template.registerHelper("telescopeUrl", function() {
return "https://your-telescope-app.com/?auto-login?token=" + localStorage.getItem("Meteor.loginToken") + "&userid=" + localStorage.getItem("Meteor.userId");
});
Then you can create a url:
Telescope App
Lastly, you need telescope to intercept these links and log in, you can create a route for this with iron router.
Again, create a file in /client/lib that contains something like this:
somefile.js
Router.map(function() {
this.route("loggin_in", {
onBeforeAction: function() {
var token = this.params("token");
var userId = this.params("userid");
localStorage.setItem("Meteor.loginToken", token);
localStorage.setItem("Meteor.userId", userId);
Tracker.flush();
window.location.href="/";
}
});
});
somefile.html
<template name="logging_in">
<h3>Logging you in</h3>
</template>
I've never tried it personally, but hopefully it is helpful.

Meteor deploy - MAIL_URL not being set

I recently started deploying a meteor app off of my local machine and it seems that the MAIL_URL property is not being set when deploying to a *.meteor.com domain. No matter what I have tried the email is sent via the default MailGun
What I have tried so far.
Verified that process.MAIL_URL is set and works locally - ensures
that I am setting MAIL_URL correctly
Verified that process.MAIL_URL
is set on *.meteor.com domain by checking meteor logs - ensures that
the process.env settings are being set on *.meteor.com
Tried multiple *.meteor.com domains - ensures it was not a subdomain specific
issue
Tried multiple smtp providers: gmail and Mandrill - ensures
that it was not an issue with the smtp provider
Tried creating a simple app with a simple test email button - ensures problem was not
related to my app code
Nothing works. With the simple app, my code is the following:
if (Meteor.isClient) {
Template.hello.greeting = function () {
return "Welcome to testmail.";
};
Template.hello.events({
'click input' : function () {
console.log("calling send mail");
Meteor.call('sendEmail',
'xxx#gmail.com',
'xxx#domain.com',
'Hello from Meteor!',
'This is a test of Email.send.');
}
});
}
if (Meteor.isServer) {
// In your server code: define a method that the client can call
Meteor.methods({
sendEmail: function (to, from, subject, text) {
check([to, from, subject, text], [String]);
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
Meteor.startup(function () {
// code to run on server at startup
process.env.MAIL_URL = 'smtp://blahblah:token#smtp.mandrillapp.com:587/';
console.log(process.env);
});
}
I am out of ideas at this point. Has anybody else experience this before and what was the resolution? Thanks.
By default meteor deploy can only use mailgun since you can't alter the environmental variables on meteor deploy hosting. Additionally meteor deploy hosting uses a galaxy configuration which takes precedence over environmental variables.
If you take a look at [this file] meteor deploy hosting uses some kind of App configuration that configures it over the environmental variable (see https://github.com/meteor/meteor/blob/devel/packages/email/email.js#L42). This is part of the galaxy configuration engine.
You have to modify the Email package to use a custom smtp server. To do this :
get the files from https://github.com/meteor/meteor/tree/devel/packages/email and place them in a directory in your project /packages/email.
add this package to your meteor project with meteor add email. It should override the default meteor-core package. If it says already using, thats okay.
Modify /packages/email/email.js around line 36 to be:
var smtpPool = makePool("<YOUR CUSTOM MAIL_URL>");
Then you should be good to go. Meteor should use this smtp host instead, even on meteor.com hosting.

Resources