2014-03-03 62 views
1

護照單選選項按鈕重定向到註冊頁面

如果用戶擁有「否」單選選項選擇的按鈕,我怎麼重定向到/註冊?

ROUTE

// app/routes/users.js 

app.post('/users/session', passport.authenticate('local', { 
    failureRedirect: '/signin', 
    failureFlash: true 
}), users.session); 

VIEW

<form action="https://stackoverflow.com/users/session" method="post"> 
    <input ng-change="change()" ng-model="NotSureWhatToPutHere" type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked> 
    <label for="optionsRadios1"> 
     No, I am a <b>new customer</b>. 
    </label> 
    <input type="radio" ng-model="NotSureWhatToPutHere" ng-change="change()" name="optionsRadios" id="optionsRadios2" value="option2"> 
    <label class="control-label" for="optionsRadios2"> 
    Yes, I have a password: 
    </label> 
    <button type="submit">Sign in</button> 
</form> 

CONTROLLER

// controllers/index.js 

'use strict'; 

angular.module('mean.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) { 
    $scope.global = Global; 
}]); 

回答

0
Ť

他並不是很多節點/護照問題,這是一個有問題的問題。

我猜你用任何角度(如,$http.post('/users/session',...)提交,或者你有一個<form action='/users/session' ...>

你需要告訴角度,對於單選按鈕(如,NG-變化或類似的東西)。當監聽用戶之間切換沒有密碼和密碼,你應該改變你的網址/註冊。

因此,沒有必要擊中服務器在那裏如果你想繼續,你可以在那裏添加另一箇中間件?如:

app.post('/users/session', function(req, res, next) { if (req.body.youroptionselected) return res.redirect('/somewhere'); next(); }, .... other handler here)

雖然這不會重定向到POST /註冊 - 重定向從來沒有做過。

你的角度控制器(客戶端)的例子是這樣的:

angular.service('loginService', function($http){ 
    var service = { 
     signin: function(email, password){ 
      $http.post('/users/session', {email: email, password: password}) 
      .success(function(response){ 
       // You're logged in here, you could do something like a redirect. 
      }) 
      .catch(function(err){ 
       console.log('Something wen\'t wrong, show this message or something.'); 
      }); 
     } 
     , signup: function(email) { 
      $http.post('/signup', {email: email}) 
      .success(function(response){ 
       // You've handled this in your backend, now on the client you're in. 
      }) 
      .catch(function(err){ 
       console.log('Something wen\'t wrong with signup., show this message or something.'); 
      }); 
     } 
    } 
}) 

angular.controller('loginController', function(loginService){ 
    // get a hold of the button here 
    $scope.buttonClickHandler = function(){ 
     // if new user, use loginService.signup($scope.email)... 
     // else use loginService.signin($scope.email, $scope.password) ... 
    } 
}) 
+0

我加了NG-變化中的index.html。有沒有一個教程,我可以看看有關如何更改網址,而無需連接到服務器的更多信息? – user3373281

+0

呃,很多方法。谷歌或Stackoverflow搜索「Javascript更改表單操作」應該有所幫助。 在您添加的版本中,您的$ scope.change函數應該看起來像function(){/ *如果是新客戶,請採取行動* /}。但是,如果你發佈角度控制器和更多的index.html,我可以幫助更多。 – Zlatko

+0

哦,不,我的意思是角度控制器。你知道,客戶端的JavaScript? – Zlatko

相關問題