use of com.hfut.entity.User in project Workload by amoxu.
the class UserServiceImpl method register.
@Override
public boolean register(User user) throws Exception {
System.out.println("user register:" + user.getUser() + " " + user.getPassword() + " " + user.getMail());
if (StringUtils.isEmpty(user.getUser()) || StringUtils.isEmpty(user.getPassword())) {
throw new CustomException("用户或密码不能为空!");
} else if (StringUtils.isEmpty(user.getMail())) {
throw new CustomException("邮箱不能为空!");
} else if (user.getPassword().length() < 6) {
throw new CustomException("密码过短!");
}
UserExample userExample = new UserExample();
UserExample.Criteria criteria = userExample.createCriteria();
criteria.andUserEqualTo(user.getUser());
List<User> list = userMapper.selectByExample(userExample);
if (list.size() != 0) {
throw new CustomException("账号已存在!");
}
userExample = new UserExample();
criteria = userExample.createCriteria();
criteria.andMailEqualTo(user.getMail());
list = userMapper.selectByExample(userExample);
if (list.size() != 0) {
throw new CustomException("邮箱已存在!");
}
int ret = userMapper.insert(user);
if (ret > 0) {
return true;
} else {
return false;
}
}
use of com.hfut.entity.User in project Workload by amoxu.
the class UserServiceImpl method findByName.
/* private SimpleMailMessage mailMessage;
private JavaMailSender mailSender;*/
@Override
public User findByName(String name) throws Exception {
UserExample userExample = new UserExample();
UserExample.Criteria criteria = userExample.createCriteria();
criteria.andUserEqualTo(name);
List<User> list = userMapper.selectByExample(userExample);
if (list.size() == 0) {
return null;
} else {
return list.get(0);
}
}
use of com.hfut.entity.User in project Workload by amoxu.
the class UserServiceImpl method getList.
@Override
public List<User> getList(Integer page, Integer limit) throws Exception {
UserExample example = new UserExample();
example.setLimit(limit);
if (page != 0) {
page -= 1;
}
example.setOffset(page);
List<User> list = userMapper.selectByExample(example);
for (User user : list) {
user.setPassword("*****");
user.setAnswer("****");
}
return list;
}
use of com.hfut.entity.User in project Workload by amoxu.
the class UserServiceImpl method getList.
@Override
public List<User> getList(int typeId, int page, int limit) throws Exception {
UserExample example = new UserExample();
UserExample.Criteria criteria = example.createCriteria();
criteria.andLevelEqualTo(typeId);
example.setLimit(limit);
if (page != 0) {
page -= 1;
}
example.setOffset(page);
List<User> list = userMapper.selectByExample(example);
for (User user : list) {
user.setPassword("*****");
user.setAnswer("****");
}
return list;
}
use of com.hfut.entity.User in project Workload by amoxu.
the class loginRealm method doGetAuthenticationInfo.
/**
* 在这个方法中,进行身份验证
* login时调用
*/
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// 用户名
String username = (String) token.getPrincipal();
// 密码
String password = new String((char[]) token.getCredentials());
User userlogin = null;
try {
userlogin = userService.findByName(username);
} catch (Exception e) {
e.printStackTrace();
}
if (userlogin == null) {
// 没有该用户名
throw new UnknownAccountException();
} else if (!password.equals(userlogin.getPassword())) {
// 密码错误
throw new IncorrectCredentialsException();
}
AuthenticationInfo aInfo = new SimpleAuthenticationInfo(username, password, getName());
return aInfo;
}
Aggregations