[英]Login authentication using angular + java rest api
我一直在努力解決此問題,以便使用angular作為客戶端和jersey作為后端Web服務公開的登錄身份驗證。
這是我過去三天取得的成就。
捕獲電子郵件和密碼的角度代碼:
myApp.controller('loginController',['$scope','$http', function($scope, $http)
{
$scope.email = "" ;
$scope.password = "" ;
$scope.loginForm = function(){
alert("login controller called");
console.log($scope.email);
console.log($scope.password);
var encodedString = 'email=' +
encodeURIComponent($scope.email) +
'&password=' +
encodeURIComponent($scope.password);
$http({
method:'POST',
url: 'rs/loginResource',
data: encodedString,
headers: {'Content-Type' : 'application/x-www-form-urlencoded'}
});
};
}]);
Java其余代碼:
@Path("/loginResource")
public class LoginResource {
public LoginResource() {
}
@POST
@Consumes("application/x-www-form-urlencoded")
public void login(@FormParam("email") String email,
@FormParam("password") String password) {
System.out.println("Email is: " + email); //prints output
System.out.println("Password is: " + password); //prints output
}
}
現在我的問題是從表單提交獲取POST數據后從這里去哪里。 如您所見,我只是打印值,而是想針對database(oracle)檢查電子郵件和密碼。 我將如何處理? 我應該使用簡單的連接類和dao還是選擇尚未學習的JPA-它的學習曲線是什么?
是否涉及任何設計模式? 通常我會使用Dao和pojo(如果它是純Java),但是我是新來休息api的人,因為api太麻煩了。 我在香草java + angular上幾乎找不到任何示例,這些示例大多數基於spring + angular。
通常登錄是這樣的:
為此,您需要閱讀會話。 以下是一些鏈接:
互聯網上有很多有關此問題的信息。
另外,對於通用REST API,身份驗證通常以令牌的形式進行。 流程看起來有些不同:
從客戶端->服務器發送密碼時,有很多方法可以對密碼進行加密。 我建議您嘗試以下簡單方法: RESTful身份驗證
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.