2015-08-28 17 views
0

在我的Web應用程序的登錄頁面上,我添加了一個用於創建新用戶的鏈接。我希望用戶填寫表格(名字,姓氏,電子郵件,密碼),在服務器上創建新用戶並自動對新用戶進行簽名,而無需再次將其重定向到登錄頁面。另外,我希望用戶登陸特定頁面(比如說訂單列表)。創建用戶並使用Thymeleaf自動登錄

是否可行,如果有,如何正確執行?

回答

1

用戶保存到數據庫後,您可以在編程記錄它們,就像這樣:

Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails, null, authorities); 
SecurityContextHolder.getContext().setAuthentication(authentication); 

然後,只需發送重定向。

+0

謝謝,作品像一個魅力(雖然我用PreAuthenticatedAuthenticationToken istead)。 – rmaruszewski