发表于: 2019-12-10 22:19:08
2 1309
今天做了什么:
前台-登录
前台-学生证
/*
学生证
*/
//用户信息
@GetMapping("/student/info")
public JSONObject studentI(String token) throws Exception {
JSONObject object = new JSONObject();
if (token.length()>1) {
object.put("code", "1");
object.put("message", "获取成功");
Student student = studentService.getInfo(token);
object.put("data", student);
log.error("查询用户信息结果: "+student);
}else {
object.put("code",0);
object.put("message","失败,无效的token");
}
return object;
}
//编辑信息
@PutMapping("/student/info")
public JSONObject putStudentI(@Valid Student student,BindingResult result) throws Exception {
JSONObject object = new JSONObject();
//校验无误
if (!result.hasErrors()){
if (studentService.changeInfo(student)){
object.put("code","1");
object.put("message","编辑成功");
return object;
}else {
object.put("code","0");
object.put("message","编辑失败");
return object;
}
}else {
object.put("code","0");
object.put("message","参数不合法");
return object;
}
}
//文章收藏
@GetMapping("/student/articleCollection")
public JSONObject studentArticleC(String token) throws Exception {
JSONObject object = new JSONObject();
object.put("code",1);
object.put("message","请求成功");
ArrayList<Article> articles = studentService.getArticleCollection(token);
object.put("data",articles);
return object;
}
//视频收藏
@GetMapping("/student/videoCollection")
public JSONObject studentVideoC(String token) throws Exception {
JSONObject object = new JSONObject();
object.put("code",1);
object.put("message","请求成功");
ArrayList<Video> videos = studentService.getVideoCollection(token);
object.put("data",videos);
return object;
}
//绑定手机
@PutMapping("/student/binding/phone")
public JSONObject studentBinding(String token,Long phone,int check_code) throws Exception {
JSONObject object = new JSONObject();
if (token.length()>0&&phone>10000000000L&&String.valueOf(check_code).length()==6){
if (studentService.bindPhone(token, phone,check_code)){
object.put("code",1);
object.put("message","绑定成功");
return object;
}else {
object.put("code",0);
object.put("message","绑定失败");
return object;
}
}else {
object.put("code","0");
object.put("message","请求参数不合法");
return object;
}
}
//绑定邮箱
@PutMapping("/student/binding/email")
public JSONObject studentBindingEmail(String token,String email,int check_code) throws Exception {
JSONObject object = new JSONObject();
if (email!=null&&email.length()>0&&String.valueOf(check_code).length()==6){
if (studentService.bindEmail(token, email, check_code)){
object.put("code",1);
object.put("message","绑定成功");
return object;
}else {
object.put("code",0);
object.put("message","绑定失败");
return object;
}
}else {
object.put("code","0");
object.put("message","请求失败");
return object;
}
}
//发邮件
@PostMapping("/student/email")
public JSONObject studentSendM(String email) throws IOException {
final int random_code =random.nextInt(899999)+100000;
JSONObject object = mpService.sendMail(email,random_code);
stringRedisTemplate.opsForValue().set(email, String.valueOf(random_code),60*5, TimeUnit.SECONDS);
return object;
}
//发短信
@PostMapping("/student/message")
public JSONObject studentSendM(Long phone) throws IOException, ClientException {
final int random_code =random.nextInt(899999)+100000;
JSONObject object = smsService.sendSms(String.valueOf(phone),random_code);
stringRedisTemplate.opsForValue().set(String.valueOf(phone), String.valueOf(random_code),60*5, TimeUnit.SECONDS);
return object;
}
//图片上传
@RequestMapping(value = "/student/picture",method = RequestMethod.POST)
@ResponseBody
public JSONObject postPicture(MultipartFile file) throws IOException {
if (ossService==null)
log.error("ossService注入失败");
JSONObject object = new JSONObject();
String name = file.getOriginalFilename();
String end = name.substring(name.length()-5,name.length());
String objectName = String.valueOf(System.currentTimeMillis())+end.substring(end.indexOf("."),end.length());
log.error(objectName);
if (ossService.uploadFile(objectName,file)){
object.put("code","1");
object.put("message","图片上传成功");
object.put("data","https://wangquan-picture-storage.oss-cn-beijing.aliyuncs.com/"+objectName);
}else {
object.put("code","0");
object.put("message","图片上传失败");
object.put("data",null);
}
log.error(object);
return object;
}
收获:
问题:
明天的计划:
后台账户权限管理
评论