-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BG317958
committed
Apr 19, 2018
1 parent
ff34792
commit 46b40a7
Showing
633 changed files
with
72,160 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,99 @@ | ||
package controller; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import domain.UserInfo; | ||
import org.apache.log4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.servlet.ModelAndView; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.bind.support.SessionStatus; | ||
import service.LoginService; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
/** | ||
* Created by pengfei on 2017/9/22. | ||
*/ | ||
@Controller | ||
@SessionAttributes("user") | ||
public class LoginController { | ||
|
||
private final static Logger logger=Logger.getLogger(LoginController.class); | ||
private final static Logger logger = Logger.getLogger(LoginController.class); | ||
|
||
@Autowired | ||
private LoginService loginService; | ||
|
||
@RequestMapping(value = "/login", method = RequestMethod.GET) | ||
public String get(){ | ||
@RequestMapping(value = "/homePage") | ||
public String get(HttpSession session) { | ||
logger.info("Inside login get method"); | ||
return "home"; | ||
|
||
UserInfo currentUser = (UserInfo) session.getAttribute("user"); | ||
logger.info("Current User:" + currentUser.getName()); | ||
|
||
return "homePage"; | ||
} | ||
|
||
//public String login(@RequestParam("name") String name, String password, ModelMap model){ | ||
//public String login(String name, String password, ModelMap model){ | ||
|
||
@RequestMapping(value = "/loginHere",method=RequestMethod.POST) | ||
public String login(@RequestParam("name") String name, String password, ModelMap model){ | ||
@RequestMapping(value = "/loginHere") | ||
public String login(@RequestParam("name") String name, String password, ModelMap model) { | ||
logger.info("Login controller begin service"); | ||
|
||
model.addAttribute("password",password); | ||
model.addAttribute("name",name); | ||
UserInfo user = new UserInfo(); | ||
user.setName(name); | ||
user.setPassword(password); | ||
|
||
if(password==null) | ||
throw new RuntimeException("Password should not be null!"); | ||
model.addAttribute("bean", user); | ||
|
||
logger.info("Login controller end service!"); | ||
if (loginService.checkUserAccess(name, password)) { | ||
logger.info("Login controller end service!"); | ||
|
||
return "homePage"; | ||
user.setPassword(""); | ||
model.addAttribute("user", user); | ||
|
||
return "redirect:/homePage"; | ||
} else { | ||
return "login"; | ||
} | ||
} | ||
|
||
@RequestMapping(value="/toLoginPage",method = RequestMethod.GET) | ||
public String redirect(){ | ||
@RequestMapping(value = "/toLoginPage", method = RequestMethod.GET) | ||
public String redirect() { | ||
return "redirect:login"; | ||
} | ||
|
||
@RequestMapping(value = "/visitStaticPage",method = RequestMethod.GET) | ||
public String visitStaticPage(){ | ||
@RequestMapping(value = "/visitStaticPage", method = RequestMethod.GET) | ||
public String visitStaticPage() { | ||
|
||
return "redirect:/pages/static.html"; | ||
} | ||
|
||
|
||
//Return to previous path | ||
@ResponseBody | ||
@RequestMapping(value = "/getUserSession") | ||
public String getUserSession( HttpSession session) { | ||
String result=""; | ||
|
||
Object obj=session.getAttribute("user"); | ||
if (obj instanceof String){ | ||
result= (String) obj; | ||
}else if (obj instanceof UserInfo){ | ||
result=((UserInfo) obj).getName(); | ||
} | ||
|
||
result= JSON.toJSONString(result); | ||
|
||
return result; | ||
} | ||
|
||
@RequestMapping("/logOut") | ||
@ResponseBody | ||
public String logout( SessionStatus status){ | ||
status.setComplete(); | ||
return "logout"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package service; | ||
|
||
import domain.UserInfo; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by pengfei on 2017/9/12. | ||
*/ | ||
public interface LoginService { | ||
|
||
public void addUser(UserInfo info); | ||
|
||
public void deleteUser(UserInfo info); | ||
|
||
public UserInfo queryUser(UserInfo info); | ||
|
||
public boolean checkUserAccess(String userName, String pwd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package service; | ||
|
||
import Utility.RedisCache; | ||
import com.alibaba.fastjson.JSON; | ||
import dao.UserDao; | ||
import domain.UserInfo; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Created by pengfei on 2017/9/12. | ||
*/ | ||
|
||
@Service("LoginService") | ||
public class LoginServiceImpl implements LoginService { | ||
|
||
@Autowired | ||
private RedisCache redisCache; | ||
|
||
@Autowired | ||
private UserDao userDao; | ||
|
||
public void addUser(UserInfo info) { | ||
this.userDao.saveUserData(info); | ||
System.out.println("Service:add user"); | ||
} | ||
|
||
public void deleteUser(UserInfo info) { | ||
this.userDao.delUser(info); | ||
System.out.println("Service:delete user"); | ||
} | ||
|
||
public UserInfo queryUser(UserInfo info) { | ||
|
||
//First check Redis redisCache. | ||
String userJsonValue = (String) this.redisCache.get("user:" + info.getId()); | ||
if (!StringUtils.isEmpty(userJsonValue)) { | ||
UserInfo result = JSON.parseObject(userJsonValue, UserInfo.class); | ||
System.out.println("Cache got"); | ||
return result; | ||
} | ||
|
||
//If redis not found, check Database. | ||
UserInfo user = (UserInfo) this.userDao.findUser(info.getId()); | ||
|
||
//Save in Redis. | ||
this.redisCache.set("user:" + info.getId(), user); | ||
System.out.println("DB got"); | ||
return user; | ||
} | ||
|
||
public boolean checkUserAccess(String userName, String pwd){ | ||
UserInfo user=(UserInfo) userDao.findUser(userName); | ||
|
||
if (user ==null ||!user.getPassword().equals(pwd)){ | ||
return false; | ||
}else{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function checkrst(data) { | ||
dataobj=JSON.parse(data); | ||
if(dataobj.rst_code === 0){ | ||
return dataobj.rst_data; | ||
} | ||
$.messager.alert('Warning', dataobj.rst_msg); | ||
return false; | ||
} |
Oops, something went wrong.