新版
This commit is contained in:
@@ -42,23 +42,23 @@ public class AppLoginController {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@PostMapping("login")
|
||||
@ApiOperation("登录")
|
||||
public R login(@RequestBody LoginForm form){
|
||||
//表单校验
|
||||
ValidatorUtils.validateEntity(form);
|
||||
|
||||
//用户登录
|
||||
long userId = userService.login(form);
|
||||
|
||||
//生成token
|
||||
String token = jwtUtils.generateToken(userId);
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("token", token);
|
||||
map.put("expire", jwtUtils.getExpire());
|
||||
|
||||
return R.ok(map);
|
||||
}
|
||||
// @PostMapping("login")
|
||||
// @ApiOperation("登录")
|
||||
// public R login(@RequestBody LoginForm form){
|
||||
// //表单校验
|
||||
// ValidatorUtils.validateEntity(form);
|
||||
//
|
||||
// //用户登录
|
||||
// long userId = userService.login(form);
|
||||
//
|
||||
// //生成token
|
||||
// String token = jwtUtils.generateToken(userId);
|
||||
//
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("token", token);
|
||||
// map.put("expire", jwtUtils.getExpire());
|
||||
//
|
||||
// return R.ok(map);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ package com.peanut.modules.app.controller;
|
||||
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.common.validator.ValidatorUtils;
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import com.peanut.modules.app.form.RegisterForm;
|
||||
import com.peanut.modules.app.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -37,19 +36,19 @@ public class AppRegisterController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("register")
|
||||
@ApiOperation("注册")
|
||||
public R register(@RequestBody RegisterForm form){
|
||||
//表单校验
|
||||
ValidatorUtils.validateEntity(form);
|
||||
|
||||
UserEntity user = new UserEntity();
|
||||
user.setMobile(form.getMobile());
|
||||
user.setUsername(form.getMobile());
|
||||
user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
|
||||
user.setCreateTime(new Date());
|
||||
userService.save(user);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
// @PostMapping("register")
|
||||
// @ApiOperation("注册")
|
||||
// public R register(@RequestBody RegisterForm form){
|
||||
// //表单校验
|
||||
// ValidatorUtils.validateEntity(form);
|
||||
//
|
||||
// UserEntity user = new UserEntity();
|
||||
// user.setMobile(form.getMobile());
|
||||
// user.setUsername(form.getMobile());
|
||||
// user.setPassword(DigestUtils.sha256Hex(form.getPassword()));
|
||||
// user.setCreateTime(new Date());
|
||||
// userService.save(user);
|
||||
//
|
||||
// return R.ok();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ package com.peanut.modules.app.controller;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.app.annotation.Login;
|
||||
import com.peanut.modules.app.annotation.LoginUser;
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import com.peanut.modules.book.entity.UserEntity;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.app.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Mapper
|
||||
public interface UserDao extends BaseMapper<UserEntity> {
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2016-2019 人人开源 All rights reserved.
|
||||
*
|
||||
* https://www.renren.io
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
|
||||
package com.peanut.modules.app.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*
|
||||
* @author Mark sunlightcs@gmail.com
|
||||
*/
|
||||
@Data
|
||||
@TableName("tb_user")
|
||||
public class UserEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
}
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
package com.peanut.modules.app.resolver;
|
||||
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import com.peanut.modules.app.service.UserService;
|
||||
import com.peanut.modules.app.annotation.LoginUser;
|
||||
import com.peanut.modules.app.interceptor.AuthorizationInterceptor;
|
||||
import com.peanut.modules.book.entity.UserEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -10,8 +10,8 @@ package com.peanut.modules.app.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import com.peanut.modules.app.form.LoginForm;
|
||||
import com.peanut.modules.book.entity.UserEntity;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
@@ -20,12 +20,12 @@ import com.peanut.modules.app.form.LoginForm;
|
||||
*/
|
||||
public interface UserService extends IService<UserEntity> {
|
||||
|
||||
UserEntity queryByMobile(String mobile);
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param form 登录表单
|
||||
* @return 返回用户ID
|
||||
*/
|
||||
long login(LoginForm form);
|
||||
// UserEntity queryByMobile(String mobile);
|
||||
//
|
||||
// /**
|
||||
// * 用户登录
|
||||
// * @param form 登录表单
|
||||
// * @return 返回用户ID
|
||||
// */
|
||||
// long login(LoginForm form);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.exception.RRException;
|
||||
import com.peanut.common.validator.Assert;
|
||||
import com.peanut.modules.app.dao.UserDao;
|
||||
import com.peanut.modules.app.entity.UserEntity;
|
||||
import com.peanut.modules.book.dao.UserDao;
|
||||
import com.peanut.modules.app.form.LoginForm;
|
||||
import com.peanut.modules.app.service.UserService;
|
||||
import com.peanut.modules.book.entity.UserEntity;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -24,21 +24,21 @@ import org.springframework.stereotype.Service;
|
||||
@Service("userService")
|
||||
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
|
||||
|
||||
@Override
|
||||
public UserEntity queryByMobile(String mobile) {
|
||||
return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("mobile", mobile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long login(LoginForm form) {
|
||||
UserEntity user = queryByMobile(form.getMobile());
|
||||
Assert.isNull(user, "手机号或密码错误");
|
||||
// public UserEntity queryByMobile(String mobile) {
|
||||
// return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("mobile", mobile));
|
||||
// }
|
||||
|
||||
//密码错误
|
||||
if(!user.getPassword().equals(DigestUtils.sha256Hex(form.getPassword()))){
|
||||
throw new RRException("手机号或密码错误");
|
||||
}
|
||||
|
||||
return user.getUserId();
|
||||
}
|
||||
// public long login(LoginForm form) {
|
||||
// UserEntity user = queryByMobile(form.getMobile());
|
||||
// Assert.isNull(user, "手机号或密码错误");
|
||||
//
|
||||
// //密码错误
|
||||
// if(!user.getPassword().equals(DigestUtils.sha256Hex(form.getPassword()))){
|
||||
// throw new RRException("手机号或密码错误");
|
||||
// }
|
||||
//
|
||||
// return user.getUserId();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user