|
|
@ -1,12 +1,10 @@ |
|
|
|
package com.community.pocket.api; |
|
|
|
package com.community.pocket.api; |
|
|
|
|
|
|
|
|
|
|
|
import com.community.pocket.Result; |
|
|
|
import com.community.pocket.entity.po.Manager; |
|
|
|
import com.community.pocket.domain.Manager; |
|
|
|
import com.community.pocket.entity.po.Token; |
|
|
|
import com.community.pocket.domain.Res; |
|
|
|
import com.community.pocket.entity.vo.*; |
|
|
|
import com.community.pocket.domain.Token; |
|
|
|
|
|
|
|
import com.community.pocket.domain.form.ManagerLogin; |
|
|
|
|
|
|
|
import com.community.pocket.domain.form.ManagerRegister; |
|
|
|
|
|
|
|
import com.community.pocket.repository.ManagerDao; |
|
|
|
import com.community.pocket.repository.ManagerDao; |
|
|
|
|
|
|
|
import com.community.pocket.util.EmailService; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.util.DigestUtils; |
|
|
|
import org.springframework.util.DigestUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
@ -14,6 +12,7 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@RestController |
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/manager") |
|
|
|
@RequestMapping("/api/manager") |
|
|
@ -25,16 +24,22 @@ public class ManagerController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ManagerDao managerDao; |
|
|
|
private ManagerDao managerDao; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private Common common; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private EmailService emailService; |
|
|
|
|
|
|
|
|
|
|
|
// 登陆
|
|
|
|
// 登陆
|
|
|
|
@PostMapping("login") |
|
|
|
@PostMapping("login") |
|
|
|
public Res<Token> login(@RequestBody ManagerLogin managerLogin){ |
|
|
|
public JSONResponse<Token> login(@RequestBody ManagerLogin managerLogin){ |
|
|
|
if(StringUtils.isEmpty(managerLogin.getManagerName())){ |
|
|
|
if(StringUtils.isEmpty(managerLogin.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空!",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"管理员不能为空!",null); |
|
|
|
}else if(StringUtils.isEmpty(managerLogin.getPassword())){ |
|
|
|
}else if(StringUtils.isEmpty(managerLogin.getPassword())){ |
|
|
|
return new Res<>(Result.FAIL,"密码不能为空!",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"密码不能为空!",null); |
|
|
|
//校验账号密码
|
|
|
|
//校验账号密码
|
|
|
|
}else if(!managerDao.login(managerLogin)){ |
|
|
|
}else if(!managerDao.login(managerLogin)){ |
|
|
|
return new Res<>(Result.FAIL,"账号或密码错误!",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"账号或密码错误!",null); |
|
|
|
} |
|
|
|
} |
|
|
|
else{ |
|
|
|
else{ |
|
|
|
// 验证通过生成令牌响应给服务端
|
|
|
|
// 验证通过生成令牌响应给服务端
|
|
|
@ -47,27 +52,46 @@ public class ManagerController { |
|
|
|
token.setUseTime(c.getTimeInMillis()); |
|
|
|
token.setUseTime(c.getTimeInMillis()); |
|
|
|
// 生成token
|
|
|
|
// 生成token
|
|
|
|
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes())); |
|
|
|
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes())); |
|
|
|
return new Res<>(Result.OK,"登陆成功",token); |
|
|
|
token.setManagerName(managerLogin.getManagerName()); |
|
|
|
|
|
|
|
return new JSONResponse<>(Result.OK,"登陆成功",token); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 获取邮箱类型 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@GetMapping("emailType") |
|
|
|
|
|
|
|
public JSONResponse<List<EmailType>> getEmailType(){ |
|
|
|
|
|
|
|
return new JSONResponse<>(Result.OK,"获取邮箱类型成功", common.getSupportType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("sendcode") |
|
|
|
|
|
|
|
public JSONResponse<String> sendEmail(String sender){ |
|
|
|
|
|
|
|
if(emailService.sendCode(sender)){ |
|
|
|
|
|
|
|
return new JSONResponse<>(Result.OK,"发送邮件成功",null); |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
return new JSONResponse<>(Result.OK,"发送邮件失败",null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 注册
|
|
|
|
// 注册
|
|
|
|
@PostMapping("register") |
|
|
|
@PostMapping("register") |
|
|
|
public Res<String> register(@RequestBody ManagerRegister manager){ |
|
|
|
public JSONResponse<String> register(@RequestBody ManagerRegister manager){ |
|
|
|
if(StringUtils.isEmpty(manager.getManagerName())){ |
|
|
|
if(StringUtils.isEmpty(manager.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"管理员不能为空",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"管理员不能为空",null); |
|
|
|
}else if(StringUtils.isEmpty(manager.getPassword())){ |
|
|
|
}else if(StringUtils.isEmpty(manager.getPassword())){ |
|
|
|
return new Res<>(Result.FAIL,"密码不能为空",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"密码不能为空",null); |
|
|
|
}else if(StringUtils.isEmpty(manager.getConfirmPassword())){ |
|
|
|
}else if(StringUtils.isEmpty(manager.getConfirmPassword())){ |
|
|
|
return new Res<>(Result.FAIL,"确认密码不能为空",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"确认密码不能为空",null); |
|
|
|
}else if(!manager.getPassword().equals(manager.getConfirmPassword())){ |
|
|
|
}else if(!manager.getPassword().equals(manager.getConfirmPassword())){ |
|
|
|
return new Res<>(Result.FAIL,"两次密码输入不一致",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"两次密码输入不一致",null); |
|
|
|
}else if(StringUtils.isEmpty(manager.getMobie())){ |
|
|
|
}else if(StringUtils.isEmpty(manager.getMobie())){ |
|
|
|
return new Res<>(Result.FAIL,"手机号不能为空",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"手机号不能为空",null); |
|
|
|
}else if(StringUtils.isEmpty(manager.getEmail())){ |
|
|
|
}else if(StringUtils.isEmpty(manager.getEmail())){ |
|
|
|
return new Res<>(Result.FAIL,"邮箱不能为空",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"邮箱不能为空",null); |
|
|
|
}else if(managerDao.hasUser(manager.getManagerName())){ |
|
|
|
}else if(managerDao.hasUser(manager.getManagerName())){ |
|
|
|
return new Res<>(Result.FAIL,"用户已存在",null); |
|
|
|
return new JSONResponse<>(Result.FAIL,"用户已存在",null); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
// 表单数据转换到管理员实体,调用dao层持久化到数据库
|
|
|
|
// 表单数据转换到管理员实体,调用dao层持久化到数据库
|
|
|
|
Manager m=new Manager(); |
|
|
|
Manager m=new Manager(); |
|
|
@ -76,7 +100,7 @@ public class ManagerController { |
|
|
|
m.setMobie(manager.getMobie()); |
|
|
|
m.setMobie(manager.getMobie()); |
|
|
|
m.setEmail(manager.getEmail()); |
|
|
|
m.setEmail(manager.getEmail()); |
|
|
|
managerDao.save(m); |
|
|
|
managerDao.save(m); |
|
|
|
return new Res<>(Result.OK,"注册成功",null); |
|
|
|
return new JSONResponse<>(Result.OK,"注册成功",null); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|