Saturday, 15 April 2017

Navigating between Express, EJS and Node.js

How do I create a page which has a button, which onclick() will redirect to another page?



via Bugzy216

How to render the access to the page only after successful check using node js express

I try to make a page accessible only after some verification. Then I have a form for the verification whose route is "/", once the verification is completed successfully, it is redirected to the "/ send" page to send the money. If I type in URL "/", the form is displayed and all is passed well. But if I type "/ send" the page where I'm going to send the money opens without that it asks me for verification. How I can forbid access to a page every time the user accesses this page only when he fills out the verification form with success.

//get send money form
router.get('/send',function (req, res, next)
 {
    res.render('transfer.ejs');
 });

 // get the verification page
 router.get('/',function (req, res, next)
 {
    res.render('verification.ejs');
 });

//unlock account function
 function unlockAccount(val,myaddress,callback)
  {
      //here I make somme verification
  }

 //transfer token
  router.post('/send', function(req, res, next) {
   //here the code of the transfer page
  });

//checking account 
  router.post('/',function (req, res, next)
  { 
     unlockAccount(req.body.password,req.body.myaddress,
     function(err,response)   {
          var bool=Boolean(response);
          if (bool)
           {
              res.redirect("/send");
           }
          else
          {
              res.redirect("/");
          }
       });


  });



via takampika

gcloud app deploy does not remove previous versions

I am running a Node.js app on Google App Engine, using the following command to deploy my code:

gcloud app deploy --stop-previous-version

My desired behavior is for all instances running previous versions to be terminated, but they always seem to stick around. Is there something I'm missing?

I realize they are not receiving traffic, but I am still paying for them and they cause some background telemetry noise. Is there a better way of running this command?



via G. Alon

Require node module in angular2 component

I can not figure out how to require node modules in my angular2 components - especially in my case on how to open a new electron window within an angular2 component.

My component.html has something like this

<button class="btn btn-success" (click)="buttonLoginClick()">Login</button>

And within the component.ts I use the following

export class LoginComponent  {
  constructor() {}

  buttonLoginClick(): void {
    alert("just a test");

    const remote = require('electron').remote;
    const BrowserWindow = remote.BrowserWindow;

    var win = new BrowserWindow({ width: 800, height: 600 });
    win.loadURL('./test.html');
  }
}

The error at compiling is saying

Cannot find name 'require'.



via capc0

How can I change variable value from console in a file on a website

I am on a website, and on this website there is a file named "Away.js". Which starts:

var S = require('core/Storage');
var I = require('core/InputParser');
module.exports = function () { var tAfk;

And everything else is in the function(). I need somehow to change the value of tAfk, is that even possible?



via Josh

bcrypt compare always returning false at rest api authentication using nodejs and mongoose

Im trying to do a basic authentication using nodejs and mongoose. When i post at the authentication route, isMatch returns false for the user password. I can't even say this is the broken part of the code, can someone guide me out?

  userSchema.methods.comparePassword = function(passw, cb) {
    bcrypt.compare(passw, this.password, function(err, isMatch) {
      if (err) {
        return cb(err);
      }
      cb(null, isMatch);
    });
  };



via GreetingsFriend

Security of storing passwords with Passport and MySQL

I'm using Passport-Local to store my users password with MySQL db. But when I store the password, the string typed is stored as it is. What are the best practices to store passwords with MySQL/Sequelize/Passport in terms of security?



via Filipe Ferminiano