|
|
@@ -7,6 +7,7 @@ import cn.enilu.flash.bean.entity.front.Ids;
|
|
|
import cn.enilu.flash.bean.vo.business.CityInfo;
|
|
|
import cn.enilu.flash.bean.vo.business.LoginVo;
|
|
|
import cn.enilu.flash.bean.vo.front.Rets;
|
|
|
+import cn.enilu.flash.cache.TokenCache;
|
|
|
import cn.enilu.flash.dao.MongoRepository;
|
|
|
import cn.enilu.flash.service.front.IdsService;
|
|
|
import cn.enilu.flash.service.front.PositionService;
|
|
|
@@ -19,11 +20,7 @@ import org.nutz.mapl.Mapl;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-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.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -42,99 +39,104 @@ public class User2Controller extends BaseController {
|
|
|
private IdsService idsService;
|
|
|
@Autowired
|
|
|
private PositionService positionService;
|
|
|
+ @Autowired
|
|
|
+ private TokenCache tokenCache;
|
|
|
|
|
|
- @RequestMapping(value = "/v1/user",method = RequestMethod.GET)
|
|
|
- public Object getUser(){
|
|
|
+ @RequestMapping(value = "/v1/user", method = RequestMethod.GET)
|
|
|
+ public Object getUser() {
|
|
|
return getSession("currentUser");
|
|
|
}
|
|
|
+
|
|
|
@RequestMapping(method = RequestMethod.GET)
|
|
|
- public Object getUser(@RequestParam("user_id") Long userId){
|
|
|
+ public Object getUser(@RequestParam("user_id") Long userId) {
|
|
|
return getSession("currentUser");
|
|
|
}
|
|
|
- @RequestMapping(value = "/list",method = RequestMethod.GET)
|
|
|
- public Object list(@RequestParam("offset") Integer offset,@RequestParam("limit") Integer limit){
|
|
|
+
|
|
|
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
+ public Object list(@RequestParam("offset") Integer offset, @RequestParam("limit") Integer limit) {
|
|
|
List list = mongoRepository.findAll("userinfos");
|
|
|
return list;
|
|
|
}
|
|
|
- @RequestMapping(value = "/count",method = RequestMethod.GET)
|
|
|
- public Object count(){
|
|
|
- return Rets.success("count",2);
|
|
|
+
|
|
|
+ @RequestMapping(value = "/count", method = RequestMethod.GET)
|
|
|
+ public Object count() {
|
|
|
+ return Rets.success("count", 2);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/v2/login",method = RequestMethod.POST)
|
|
|
- public Object login(@RequestBody LoginVo loginVo){
|
|
|
- String captch = (String) getSession(CaptchaCode.CAPTCH_KEY);
|
|
|
- if(!Strings.equals(loginVo.getCaptchaCode(),captch)){
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_CAPTCHA","message","验证码不正确"));
|
|
|
+ @RequestMapping(value = "/v2/login", method = RequestMethod.POST)
|
|
|
+ public Object login(@RequestBody LoginVo loginVo) {
|
|
|
+ String captchCode = tokenCache.get(loginVo.getCaptchCodeId(),String.class);
|
|
|
+ if (!Strings.equals(loginVo.getCaptchaCode(), captchCode)) {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_CAPTCHA", "message", "验证码不正确"));
|
|
|
}
|
|
|
- Map user = mongoRepository.findOne("users","username",loginVo.getUsername());
|
|
|
- String newPassword = MD5.getMD5String(MD5.getMD5String(loginVo.getPassword()).substring(2,7)+MD5.getMD5String(loginVo.getPassword()));
|
|
|
- if(user==null){
|
|
|
+ Map user = mongoRepository.findOne("users", "username", loginVo.getUsername());
|
|
|
+ String newPassword = MD5.getMD5String(MD5.getMD5String(loginVo.getPassword()).substring(2, 7) + MD5.getMD5String(loginVo.getPassword()));
|
|
|
+ if (user == null) {
|
|
|
FrontUser frontUser = new FrontUser();
|
|
|
frontUser.setUser_id(idsService.getId(Ids.USER_ID));
|
|
|
- frontUser.setUsername(loginVo.getUsername());
|
|
|
+ frontUser.setUsername(loginVo.getUsername());
|
|
|
frontUser.setPassword(newPassword);
|
|
|
- mongoRepository.save(frontUser);
|
|
|
+ mongoRepository.save(frontUser);
|
|
|
FrontUserInfo userInfo = new FrontUserInfo();
|
|
|
userInfo.setId(frontUser.getUser_id());
|
|
|
userInfo.setUser_id(frontUser.getUser_id());
|
|
|
- userInfo.setRegiste_time(DateUtil.format(new Date(),"yyyy-MM-dd HH:mm"));
|
|
|
+ userInfo.setRegiste_time(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm"));
|
|
|
String ip = getIp();
|
|
|
CityInfo cityInfo = positionService.getPostion(ip);
|
|
|
userInfo.setCity(cityInfo.getCity());
|
|
|
userInfo.setUsername(frontUser.getUsername());
|
|
|
mongoRepository.save(userInfo);
|
|
|
Object result = Mapl.merge(frontUser, userInfo);
|
|
|
- setSession("currentUser",result);
|
|
|
+ setSession("currentUser", result);
|
|
|
return frontUser;
|
|
|
- }else{
|
|
|
- if(newPassword.equals(user.get("password"))){
|
|
|
+ } else {
|
|
|
+ if (newPassword.equals(user.get("password"))) {
|
|
|
Map userInfo = mongoRepository.findOne("userinfos", "user_id", Long.valueOf(user.get("user_id").toString()));
|
|
|
Object result = Mapl.merge(user, userInfo);
|
|
|
- setSession("currentUser",result);
|
|
|
+ setSession("currentUser", result);
|
|
|
return result;
|
|
|
- }else{
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_PASSWORD","message","密码错误"));
|
|
|
+ } else {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_PASSWORD", "message", "密码错误"));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
- @RequestMapping(value = "/v2/signout",method = RequestMethod.GET)
|
|
|
- public Object signOut(){
|
|
|
+
|
|
|
+ @RequestMapping(value = "/v2/signout", method = RequestMethod.GET)
|
|
|
+ public Object signOut() {
|
|
|
getRequest().getSession().removeAttribute("currentUser");
|
|
|
return Rets.success();
|
|
|
}
|
|
|
- @RequestMapping(value = "/v2/changepassword",method = RequestMethod.POST)
|
|
|
- public Object changePassword(@RequestParam("username")String userName,
|
|
|
- @RequestParam("oldpassWord")String oldPassword,
|
|
|
- @RequestParam("newpassword")String newPassword,
|
|
|
- @RequestParam("confirmpassword")String confirmPassword,
|
|
|
- @RequestParam("captcha_code")String captchaCode){
|
|
|
+
|
|
|
+ @RequestMapping(value = "/v2/changepassword", method = RequestMethod.POST)
|
|
|
+ public Object changePassword(@RequestParam("username") String userName,
|
|
|
+ @RequestParam("oldpassWord") String oldPassword,
|
|
|
+ @RequestParam("newpassword") String newPassword,
|
|
|
+ @RequestParam("confirmpassword") String confirmPassword,
|
|
|
+ @RequestParam("captcha_code") String captchaCode) {
|
|
|
|
|
|
String captch = (String) getSession(CaptchaCode.CAPTCH_KEY);
|
|
|
- if(!Strings.equals(captchaCode,captch)){
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_CAPTCHA","message","验证码不正确"));
|
|
|
+ if (!Strings.equals(captchaCode, captch)) {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_CAPTCHA", "message", "验证码不正确"));
|
|
|
}
|
|
|
- Map user = mongoRepository.findOne("users","username",userName);
|
|
|
- if(user==null){
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","用户不存在"));
|
|
|
+ Map user = mongoRepository.findOne("users", "username", userName);
|
|
|
+ if (user == null) {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_QUERY", "message", "用户不存在"));
|
|
|
}
|
|
|
- if(!Strings.equals(oldPassword,Strings.sNull(user.get("password")))){
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","原密码错误"));
|
|
|
+ if (!Strings.equals(oldPassword, Strings.sNull(user.get("password")))) {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_QUERY", "message", "原密码错误"));
|
|
|
}
|
|
|
- if(Strings.equals(newPassword,confirmPassword)){
|
|
|
- return Rets.failure(Maps.newHashMap("type","ERROR_QUERY","message","新密码不一致"));
|
|
|
+ if (Strings.equals(newPassword, confirmPassword)) {
|
|
|
+ return Rets.failure(Maps.newHashMap("type", "ERROR_QUERY", "message", "新密码不一致"));
|
|
|
}
|
|
|
|
|
|
- user.put("password",newPassword);
|
|
|
- mongoRepository.update(Long.valueOf(user.get("id").toString()),"users",user);
|
|
|
+ user.put("password", newPassword);
|
|
|
+ mongoRepository.update(Long.valueOf(user.get("id").toString()), "users", user);
|
|
|
|
|
|
return Rets.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|