parent
772f1fed6e
commit
08b94e54f2
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
|
||||
*/
|
||||
package com.tamguo.config.image;
|
||||
package com.tamguo.common.image;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
@ -0,0 +1,5 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
public enum Status {
|
||||
SUCCESS , ERROR
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.tamguo.common.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class UploaderMessage {
|
||||
private Status status;
|
||||
private String statusMsg = "";
|
||||
private ArrayList<Integer> errorKys;
|
||||
private String error = "";
|
||||
private String filePath = "";
|
||||
private String fileDomain = "";
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getStatusMsg() {
|
||||
return statusMsg;
|
||||
}
|
||||
|
||||
public void setStatusMsg(String statusMsg) {
|
||||
this.statusMsg = statusMsg;
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getErrorKys() {
|
||||
return errorKys;
|
||||
}
|
||||
|
||||
public void setErrorKys(ArrayList<Integer> errorKys) {
|
||||
this.errorKys = errorKys;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getFileDomain() {
|
||||
return fileDomain;
|
||||
}
|
||||
|
||||
public void setFileDomain(String fileDomain) {
|
||||
this.fileDomain = fileDomain;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.tamguo.modules.member.dao;
|
||||
|
||||
import com.tamguo.config.dao.SuperMapper;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
|
||||
public interface MemberMapper extends SuperMapper<MemberEntity>{
|
||||
|
||||
}
|
@ -0,0 +1,189 @@
|
||||
package com.tamguo.modules.member.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotations.TableField;
|
||||
import com.baomidou.mybatisplus.annotations.TableName;
|
||||
import com.tamguo.config.dao.SuperEntity;
|
||||
|
||||
/**
|
||||
* The persistent class for the tiku_ad database table.
|
||||
*
|
||||
*/
|
||||
@TableName(value="tiku_member")
|
||||
public class MemberEntity extends SuperEntity<MemberEntity> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String subjectId;
|
||||
|
||||
private String courseId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String nickName;
|
||||
|
||||
private String password;
|
||||
|
||||
private String avatar;
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String email;
|
||||
|
||||
private Integer point;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private Long lastLoginTime;
|
||||
|
||||
private Integer paperNum;
|
||||
|
||||
private Integer questionNum;
|
||||
|
||||
private Integer downNum;
|
||||
|
||||
private Integer hitsNum;
|
||||
|
||||
@TableField(exist=false)
|
||||
private String verifyCode;
|
||||
|
||||
@TableField(exist=false)
|
||||
private String nowPassword;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setPoint(Integer point) {
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Long getLastLoginTime() {
|
||||
return lastLoginTime;
|
||||
}
|
||||
|
||||
public void setLastLoginTime(Long lastLoginTime) {
|
||||
this.lastLoginTime = lastLoginTime;
|
||||
}
|
||||
|
||||
public Integer getPaperNum() {
|
||||
return paperNum;
|
||||
}
|
||||
|
||||
public void setPaperNum(Integer paperNum) {
|
||||
this.paperNum = paperNum;
|
||||
}
|
||||
|
||||
public Integer getQuestionNum() {
|
||||
return questionNum;
|
||||
}
|
||||
|
||||
public void setQuestionNum(Integer questionNum) {
|
||||
this.questionNum = questionNum;
|
||||
}
|
||||
|
||||
public Integer getHitsNum() {
|
||||
return hitsNum;
|
||||
}
|
||||
|
||||
public void setHitsNum(Integer hitsNum) {
|
||||
this.hitsNum = hitsNum;
|
||||
}
|
||||
|
||||
public Integer getDownNum() {
|
||||
return downNum;
|
||||
}
|
||||
|
||||
public void setDownNum(Integer downNum) {
|
||||
this.downNum = downNum;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getVerifyCode() {
|
||||
return verifyCode;
|
||||
}
|
||||
|
||||
public void setVerifyCode(String verifyCode) {
|
||||
this.verifyCode = verifyCode;
|
||||
}
|
||||
|
||||
public String getSubjectId() {
|
||||
return subjectId;
|
||||
}
|
||||
|
||||
public void setSubjectId(String subjectId) {
|
||||
this.subjectId = subjectId;
|
||||
}
|
||||
|
||||
public String getCourseId() {
|
||||
return courseId;
|
||||
}
|
||||
|
||||
public void setCourseId(String courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public String getNowPassword() {
|
||||
return nowPassword;
|
||||
}
|
||||
|
||||
public void setNowPassword(String nowPassword) {
|
||||
this.nowPassword = nowPassword;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.tamguo.modules.member.service;
|
||||
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
|
||||
public interface IMemberService {
|
||||
|
||||
public Result login(String username , String password);
|
||||
|
||||
public Result checkUsername(String username);
|
||||
|
||||
public Result checkMobile(String mobile);
|
||||
|
||||
public Result register(MemberEntity member);
|
||||
|
||||
public Result checkAccount(String account);
|
||||
|
||||
public Result confirmAccount(String account , String veritycode);
|
||||
|
||||
public Result securityCheck(String username , String isEmail , String vcode);
|
||||
|
||||
public Result resetPassword(String resetPasswordKey , String username , String password, String verifypwd);
|
||||
|
||||
public Integer getLoginFailureCount(MemberEntity member);
|
||||
|
||||
public void updateMember(MemberEntity member);
|
||||
|
||||
public MemberEntity findByUid(String uid);
|
||||
|
||||
public MemberEntity findByUsername(String username);
|
||||
|
||||
public void updateLoginFailureCount(MemberEntity member , Integer loginFailureCount);
|
||||
|
||||
public void updateLastLoginTime(String string);
|
||||
|
||||
public MemberEntity findCurrMember(String id);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param member
|
||||
* @return
|
||||
*/
|
||||
public Result updatePwd(MemberEntity member);
|
||||
}
|
@ -0,0 +1,243 @@
|
||||
package com.tamguo.modules.member.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Condition;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.tamguo.common.utils.DateUtil;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.common.utils.SystemConstant;
|
||||
import com.tamguo.config.redis.CacheService;
|
||||
import com.tamguo.modules.member.dao.MemberMapper;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
|
||||
@Service
|
||||
public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> implements IMemberService{
|
||||
|
||||
@Autowired
|
||||
private MemberMapper memberMapper;
|
||||
@Autowired
|
||||
private CacheService cacheService;
|
||||
|
||||
@Override
|
||||
public Result login(String username, String password) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(username);
|
||||
MemberEntity member = memberMapper.selectOne(condition);
|
||||
if(member == null){
|
||||
return Result.result(201, member, "用户名或密码有误,请重新输入或找回密码");
|
||||
}
|
||||
Integer loginFailureCount = this.getLoginFailureCount(member);
|
||||
if(!new Sha256Hash(password).toHex().equals(member.getPassword())){
|
||||
loginFailureCount++;
|
||||
this.updateLoginFailureCount(member , loginFailureCount);
|
||||
return Result.result(202, member, "用户名或密码有误,请重新输入或找回密码");
|
||||
}
|
||||
this.updateLoginFailureCount(member , 0);
|
||||
return Result.result(200, member, "登录成功");
|
||||
}
|
||||
|
||||
public void updateLoginFailureCount(MemberEntity member , Integer loginFailureCount){
|
||||
cacheService.setObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId(), loginFailureCount , 2 * 60 * 60);
|
||||
}
|
||||
|
||||
public Integer getLoginFailureCount(MemberEntity member){
|
||||
if(member == null){
|
||||
return 0;
|
||||
}
|
||||
if(!cacheService.isExist(SystemConstant.LOGIN_FAILURE_COUNT + member.getId())){
|
||||
return 0;
|
||||
}
|
||||
return (Integer)cacheService.getObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result checkUsername(String username) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(username);
|
||||
MemberEntity member = memberMapper.selectOne(condition);
|
||||
if(member != null){
|
||||
return Result.result(201, null, "该用户名已经存在");
|
||||
}
|
||||
return Result.result(200, null, "该用户名可用");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result checkMobile(String mobile) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setMobile(mobile);
|
||||
MemberEntity member = memberMapper.selectOne(condition);
|
||||
if(member != null){
|
||||
return Result.result(201, null, "该手机号已经存在");
|
||||
}
|
||||
return Result.result(200, null, "该手机号可用");
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public Result register(MemberEntity member) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(member.getUsername());
|
||||
MemberEntity m = memberMapper.selectOne(condition);
|
||||
if(m != null){
|
||||
return Result.result(201, null, "该用户已经存在");
|
||||
}
|
||||
condition = new MemberEntity();
|
||||
condition.setMobile(member.getMobile());
|
||||
m = memberMapper.selectOne(condition);
|
||||
if(m != null){
|
||||
return Result.result(202, null, "该手机号已经存在");
|
||||
}
|
||||
if(!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){
|
||||
return Result.result(203, null, "验证码错误");
|
||||
}
|
||||
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile());
|
||||
if(!code.equals(member.getVerifyCode())){
|
||||
return Result.result(204, null, "验证码错误");
|
||||
}
|
||||
MemberEntity entity = new MemberEntity();
|
||||
entity.setAvatar(SystemConstant.DEFAULT_MEMBER_AVATAR);
|
||||
entity.setMobile(member.getMobile());
|
||||
entity.setPassword(new Sha256Hash(member.getPassword()).toHex());
|
||||
entity.setUsername(member.getUsername());
|
||||
entity.setNickName(member.getUsername());
|
||||
entity.setSubjectId(member.getSubjectId());
|
||||
entity.setCourseId(member.getCourseId());
|
||||
entity.setEmail(member.getEmail());
|
||||
memberMapper.insert(entity);
|
||||
return Result.result(200, entity, "注册成功");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Result checkAccount(String account) {
|
||||
if(StringUtils.isEmpty(account)){
|
||||
return Result.result(201, null, "帐号不存在!");
|
||||
}
|
||||
List<MemberEntity> members = memberMapper.selectList(Condition.create().eq("user_name", account).or().eq("mobile", account));
|
||||
if(members.size() == 0){
|
||||
return Result.result(201, null, "帐号不存在!");
|
||||
}
|
||||
return Result.result(200, members.get(0), "该帐号存在");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Result confirmAccount(String account, String veritycode) {
|
||||
if(StringUtils.isEmpty(account)){
|
||||
return Result.result(201, null, "帐号不存在!");
|
||||
}
|
||||
|
||||
List<MemberEntity> members = memberMapper.selectList(Condition.create().eq("user_name", account).or().eq("mobile", account));
|
||||
if(members.size() == 0){
|
||||
return Result.result(201, null, "帐号不存在!");
|
||||
}
|
||||
return Result.result(200, members.get(0), "该帐号存在");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result securityCheck(String username , String isEmail , String vcode) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(username);
|
||||
MemberEntity member = memberMapper.selectOne(condition);
|
||||
if("1".equals(isEmail)){
|
||||
if(!cacheService.isExist(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail())){
|
||||
return Result.result(201, member, "验证码错误");
|
||||
}
|
||||
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail());
|
||||
if(!code.equals(vcode)){
|
||||
return Result.result(202, member, "验证码错误");
|
||||
}
|
||||
}else{
|
||||
if(!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){
|
||||
return Result.result(203, member, "验证码错误");
|
||||
}
|
||||
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile());
|
||||
if(!code.equals(vcode)){
|
||||
return Result.result(204, member, "验证码错误");
|
||||
}
|
||||
}
|
||||
String key = UUID.randomUUID().toString();
|
||||
cacheService.setObject(SystemConstant.SECURITY_CHECK_PREFIX + key, username , 2 * 60 * 60);
|
||||
return Result.result(200, key, "安全验证通过");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result resetPassword(String resetPasswordKey , String username , String password, String verifypwd) {
|
||||
if(cacheService.isExist(SystemConstant.SECURITY_CHECK_PREFIX + resetPasswordKey)){
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(username);
|
||||
MemberEntity member = memberMapper.selectOne(condition);
|
||||
if(password.equals(verifypwd)){
|
||||
member.setPassword(new Sha256Hash(password).toHex());
|
||||
memberMapper.updateById(member);
|
||||
}
|
||||
}
|
||||
return Result.result(200, null, "更新成功");
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public void updateMember(MemberEntity member) {
|
||||
MemberEntity entity = memberMapper.selectById(member.getId());
|
||||
entity.setAvatar(member.getAvatar());
|
||||
entity.setEmail(member.getEmail());
|
||||
entity.setMobile(member.getMobile());
|
||||
entity.setCourseId(member.getCourseId());
|
||||
entity.setSubjectId(member.getSubjectId());
|
||||
entity.setNickName(member.getNickName());
|
||||
|
||||
memberMapper.updateById(entity);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=true)
|
||||
@Override
|
||||
public MemberEntity findByUid(String uid) {
|
||||
return memberMapper.selectById(uid);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=true)
|
||||
@Override
|
||||
public MemberEntity findByUsername(String username) {
|
||||
MemberEntity condition = new MemberEntity();
|
||||
condition.setUsername(username);
|
||||
return memberMapper.selectOne(condition);
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public void updateLastLoginTime(String uid) {
|
||||
MemberEntity member = memberMapper.selectById(uid);
|
||||
member.setLastLoginTime(DateUtil.getTime());
|
||||
memberMapper.updateById(member);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemberEntity findCurrMember(String id) {
|
||||
MemberEntity member = memberMapper.selectById(id);
|
||||
member.setPassword(null);
|
||||
return member;
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public Result updatePwd(MemberEntity member) {
|
||||
MemberEntity entity = memberMapper.selectById(member.getId());
|
||||
if(!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) {
|
||||
return Result.result(501, null, "旧密码错误!");
|
||||
}
|
||||
if(!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){
|
||||
return Result.result(502, null, "验证码错误");
|
||||
}
|
||||
entity.setPassword(new Sha256Hash(member.getNowPassword()).toHex());
|
||||
return Result.result(0, null, "修改成功");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.tamguo.modules.sys.service;
|
||||
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.tamguo.common.utils.Result;
|
||||
|
||||
public interface ISmsService {
|
||||
|
||||
public Result sendFindPasswordSms(String mobile) throws ClientException;
|
||||
|
||||
}
|
@ -1,8 +1,18 @@
|
||||
package com.tamguo.modules.tiku.service;
|
||||
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.IService;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.tiku.model.QuestionEntity;
|
||||
|
||||
public interface IQuestionService extends IService<QuestionEntity>{
|
||||
|
||||
public Result addQuestion(QuestionEntity question , String currMemberId);
|
||||
|
||||
public Page<QuestionEntity> queryQuestionList(String questionType, String uid, String content, String paperId, String currMemberId ,
|
||||
Page<QuestionEntity> p);
|
||||
|
||||
public Result updateQuestion(QuestionEntity question, String currMemberId);
|
||||
|
||||
public Result delete(String uid, String currMemberId);
|
||||
}
|
||||
|
@ -1,12 +1,81 @@
|
||||
package com.tamguo.modules.tiku.service.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baomidou.mybatisplus.mapper.Condition;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.tiku.dao.PaperMapper;
|
||||
import com.tamguo.modules.tiku.dao.QuestionMapper;
|
||||
import com.tamguo.modules.tiku.model.PaperEntity;
|
||||
import com.tamguo.modules.tiku.model.QuestionEntity;
|
||||
import com.tamguo.modules.tiku.service.IQuestionService;
|
||||
|
||||
@Service
|
||||
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEntity> implements IQuestionService{
|
||||
|
||||
@Autowired
|
||||
private PaperMapper paperMapper;
|
||||
@Autowired
|
||||
private QuestionMapper questionMapper;
|
||||
|
||||
@Override
|
||||
public Result addQuestion(QuestionEntity question , String currMemberId) {
|
||||
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
|
||||
if(!currMemberId.equals(paper.getCreaterId())) {
|
||||
return Result.result(501, null, "改试卷不属于您!");
|
||||
}
|
||||
question.setCourseId(paper.getCourseId());
|
||||
questionMapper.insert(question);
|
||||
return Result.result(0, null, "添加成功!");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Page<QuestionEntity> queryQuestionList(String questionType, String id, String content, String paperId, String currMemberId ,
|
||||
Page<QuestionEntity> p) {
|
||||
if(!currMemberId.equals(paperMapper.selectById(paperId).getCreaterId())) {
|
||||
return p.setRecords(null);
|
||||
}
|
||||
Condition condition = new Condition();
|
||||
if(!StringUtils.isEmpty(questionType)) {
|
||||
condition.eq("question_type", questionType);
|
||||
}
|
||||
if(!StringUtils.isEmpty(id)) {
|
||||
condition.eq("id", id);
|
||||
}
|
||||
if(!StringUtils.isEmpty(content)) {
|
||||
condition.like("content", content);
|
||||
}
|
||||
condition.eq("paper_id", paperId);
|
||||
return p.setRecords(questionMapper.selectPage(p, condition));
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public Result updateQuestion(QuestionEntity question , String currMemberId) {
|
||||
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
|
||||
if(!currMemberId.equals(paper.getCreaterId())) {
|
||||
return Result.result(501, null, "改试卷不属于您!");
|
||||
}
|
||||
questionMapper.updateById(question);
|
||||
return Result.result(0, null, "修改成功!");
|
||||
}
|
||||
|
||||
@Transactional(readOnly=false)
|
||||
@Override
|
||||
public Result delete(String uid , String currMemberId) {
|
||||
QuestionEntity question = questionMapper.selectById(uid);
|
||||
PaperEntity paper = paperMapper.selectById(question.getPaperId().toString());
|
||||
if(!currMemberId.equals(paper.getCreaterId())) {
|
||||
return Result.result(501, null, "改试卷不属于您!");
|
||||
}
|
||||
questionMapper.deleteById(uid);
|
||||
return Result.result(0, null, "删除成功!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,72 @@
|
||||
package com.tamguo.config.shiro;
|
||||
|
||||
import java.util.Set;
|
||||
import org.apache.shiro.authc.AuthenticationException;
|
||||
import org.apache.shiro.authc.AuthenticationInfo;
|
||||
import org.apache.shiro.authc.AuthenticationToken;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authz.AuthorizationInfo;
|
||||
import org.apache.shiro.authz.SimpleAuthorizationInfo;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.apache.shiro.realm.AuthorizingRealm;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
|
||||
/**
|
||||
* 认证
|
||||
*
|
||||
*/
|
||||
public class MemberRealm extends AuthorizingRealm {
|
||||
|
||||
@Autowired
|
||||
private IMemberService iMemberService;
|
||||
|
||||
/**
|
||||
* 授权(验证权限时调用)
|
||||
*/
|
||||
@Override
|
||||
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
|
||||
Set<String > permsSet = null;
|
||||
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
|
||||
info.setStringPermissions(permsSet);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证(登录时调用)
|
||||
*/
|
||||
@Override
|
||||
protected AuthenticationInfo doGetAuthenticationInfo(
|
||||
AuthenticationToken token) throws AuthenticationException {
|
||||
String username = (String) token.getPrincipal();
|
||||
String password = new String((char[]) token.getCredentials());
|
||||
|
||||
MemberEntity member = iMemberService.findByUsername(username);
|
||||
if(member == null) {
|
||||
throw new UnknownAccountException("用户名或密码有误,请重新输入或找回密码");
|
||||
}
|
||||
Integer loginFailureCount = iMemberService.getLoginFailureCount(member);
|
||||
if(loginFailureCount > 10) {
|
||||
throw new LockedAccountException("账号被锁定");
|
||||
}
|
||||
|
||||
if(!new Sha256Hash(password).toHex().equals(member.getPassword())){
|
||||
loginFailureCount++;
|
||||
iMemberService.updateLoginFailureCount(member , loginFailureCount);
|
||||
throw new IncorrectCredentialsException("用户名或密码有误,请重新输入或找回密码");
|
||||
}
|
||||
// 更新登录时间
|
||||
iMemberService.updateLastLoginTime(member.getId());
|
||||
|
||||
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(member, password, getName());
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.tamguo.config.shiro;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.shiro.cache.ehcache.EhCacheManager;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ShiroConfiguration {
|
||||
private static Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
|
||||
|
||||
@Bean(name = "shiroRealm")
|
||||
public MemberRealm getShiroRealm() {
|
||||
return new MemberRealm();
|
||||
}
|
||||
|
||||
@Bean(name = "shiroEhcacheManager")
|
||||
public EhCacheManager getEhCacheManager() {
|
||||
EhCacheManager em = new EhCacheManager();
|
||||
em.setCacheManagerConfigFile("classpath:ehcache-shiro.xml");
|
||||
return em;
|
||||
}
|
||||
|
||||
@Bean(name = "lifecycleBeanPostProcessor")
|
||||
public LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {
|
||||
DefaultAdvisorAutoProxyCreator daap = new DefaultAdvisorAutoProxyCreator();
|
||||
daap.setProxyTargetClass(true);
|
||||
return daap;
|
||||
}
|
||||
|
||||
@Bean(name = "securityManager")
|
||||
public DefaultWebSecurityManager getDefaultWebSecurityManager() {
|
||||
DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager();
|
||||
dwsm.setRealm(getShiroRealm());
|
||||
dwsm.setCacheManager(getEhCacheManager());
|
||||
return dwsm;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor() {
|
||||
AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
|
||||
aasa.setSecurityManager(getDefaultWebSecurityManager());
|
||||
return new AuthorizationAttributeSourceAdvisor();
|
||||
}
|
||||
|
||||
@Bean(name = "shiroFilter")
|
||||
public ShiroFilterFactoryBean getShiroFilterFactoryBean() {
|
||||
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
|
||||
shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
|
||||
shiroFilterFactoryBean.setLoginUrl("/login");
|
||||
shiroFilterFactoryBean.setSuccessUrl("/index");
|
||||
filterChainDefinitionMap.put("/member/**", "authc");
|
||||
filterChainDefinitionMap.put("/**", "anon");
|
||||
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
|
||||
return shiroFilterFactoryBean;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.tamguo.utils;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
|
||||
public class ShiroUtils {
|
||||
|
||||
public static Session getSession() {
|
||||
return SecurityUtils.getSubject().getSession();
|
||||
}
|
||||
|
||||
public static Subject getSubject() {
|
||||
return SecurityUtils.getSubject();
|
||||
}
|
||||
|
||||
public static MemberEntity getMember() {
|
||||
return (MemberEntity)SecurityUtils.getSubject().getPrincipal();
|
||||
}
|
||||
|
||||
public static String getMemberId() {
|
||||
return getMember().getId();
|
||||
}
|
||||
|
||||
public static void setSessionAttribute(Object key, Object value) {
|
||||
getSession().setAttribute(key, value);
|
||||
}
|
||||
|
||||
public static Object getSessionAttribute(Object key) {
|
||||
return getSession().getAttribute(key);
|
||||
}
|
||||
|
||||
public static boolean isLogin() {
|
||||
return SecurityUtils.getSubject().getPrincipal() != null;
|
||||
}
|
||||
|
||||
public static void logout() {
|
||||
SecurityUtils.getSubject().logout();
|
||||
}
|
||||
|
||||
public static String getKaptcha(String key) {
|
||||
String kaptcha = getSessionAttribute(key).toString();
|
||||
// getSession().removeAttribute(key);
|
||||
return kaptcha;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.common.utils.DateUtils;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.common.utils.Status;
|
||||
import com.tamguo.common.utils.UploaderMessage;
|
||||
import com.tamguo.config.redis.CacheService;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class AccountController {
|
||||
|
||||
@Autowired
|
||||
public IMemberService memberService;
|
||||
@Value("${file.storage.path}")
|
||||
private String fileStoragePath;
|
||||
@Value("${domain.name}")
|
||||
private String domainName;
|
||||
@Autowired
|
||||
private CacheService cacheService;
|
||||
|
||||
private static final String AVATOR_NO_FORMAT = "00000";
|
||||
private static final String AVATOR_PREFIX = "MTX";
|
||||
|
||||
public Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@RequestMapping(value = "member/account.html", method = RequestMethod.GET)
|
||||
public ModelAndView index(ModelAndView model , HttpSession session){
|
||||
model.setViewName("member/account");
|
||||
MemberEntity member = (MemberEntity) session.getAttribute("currMember");
|
||||
model.addObject("member" , memberService.findByUid(member.getId()));
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "member/account/update.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result updateMember(@RequestBody MemberEntity member){
|
||||
member.setId(ShiroUtils.getMemberId());
|
||||
memberService.updateMember(member);
|
||||
return Result.successResult(member);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "member/password.html", method = RequestMethod.GET)
|
||||
public ModelAndView password(ModelAndView model){
|
||||
model.setViewName("member/password");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "member/password/update.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result updatePwd(@RequestBody MemberEntity member){
|
||||
member.setId(ShiroUtils.getMemberId());
|
||||
return memberService.updatePwd(member);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/uploadFile.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException {
|
||||
|
||||
if (!file.isEmpty()) {
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
|
||||
try {
|
||||
String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd");
|
||||
File dir = new File(path);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
String avatorName = this.getAvatorNo() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
||||
in = file.getInputStream();
|
||||
out = new FileOutputStream(path + "/" + avatorName);
|
||||
byte[] b = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = in.read(b)) > 0) {
|
||||
out.write(b, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
logger.info("Server File Location=" + path + avatorName);
|
||||
|
||||
UploaderMessage msg = new UploaderMessage();
|
||||
msg.setStatus(Status.SUCCESS);
|
||||
msg.setStatusMsg("File upload success");
|
||||
msg.setFilePath("files/" + DateUtils.format(new Date(), "yyyyMMdd") + "/" + avatorName);
|
||||
msg.setFileDomain(domainName);
|
||||
return msg;
|
||||
} catch (Exception e) {
|
||||
UploaderMessage msg = new UploaderMessage();
|
||||
msg.setStatus(Status.ERROR);
|
||||
msg.setError("File upload file");
|
||||
return msg;
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
out = null;
|
||||
}
|
||||
|
||||
if (in != null) {
|
||||
in.close();
|
||||
in = null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
UploaderMessage msg = new UploaderMessage();
|
||||
msg.setStatus(Status.ERROR);
|
||||
msg.setError("File is empty");
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getAvatorNo() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
|
||||
String format = sdf.format(new Date());
|
||||
DecimalFormat df = new DecimalFormat(AVATOR_NO_FORMAT);
|
||||
String key = AVATOR_PREFIX + format;
|
||||
Long incr = cacheService.incr(key);
|
||||
String avatorNo = AVATOR_PREFIX + df.format(incr);
|
||||
return avatorNo;
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.common.image.CaptchaUtils;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.common.utils.SystemConstant;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class LoginController {
|
||||
|
||||
@RequestMapping("captcha.jpg")
|
||||
public void captcha(HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setHeader("Cache-Control", "no-store, no-cache");
|
||||
response.setContentType("image/jpeg");
|
||||
|
||||
String a = CaptchaUtils.generateCaptcha(response.getOutputStream());
|
||||
ShiroUtils.setSessionAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/login.html", method = RequestMethod.GET)
|
||||
public ModelAndView login(ModelAndView model){
|
||||
model.setViewName("login");
|
||||
model.addObject("isVerifyCode" , "0");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/submitLogin.html", method = RequestMethod.POST)
|
||||
public ModelAndView submitLogin(String username , String password , String verifyCode , ModelAndView model , HttpSession session , HttpServletResponse response) throws IOException{
|
||||
Result result = Result.successResult(null);
|
||||
if(StringUtils.isEmpty(verifyCode)) {
|
||||
result = Result.result(202, null, "请输入验证码");
|
||||
} else if(StringUtils.isNotEmpty(verifyCode)){
|
||||
String kaptcha = ShiroUtils.getKaptcha(SystemConstant.KAPTCHA_SESSION_KEY);
|
||||
if (!verifyCode.equalsIgnoreCase(kaptcha)) {
|
||||
result = Result.result(205, null, "验证码错误");
|
||||
} else {
|
||||
Subject subject = ShiroUtils.getSubject();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
||||
try {
|
||||
subject.login(token);
|
||||
|
||||
session.setAttribute("currMember", ShiroUtils.getMember());
|
||||
response.sendRedirect("member/index.html");
|
||||
return null;
|
||||
} catch (UnknownAccountException e) {
|
||||
result = Result.result(201, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (IncorrectCredentialsException e) {
|
||||
result = Result.result(202, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (LockedAccountException e) {
|
||||
result = Result.result(203, null, "账号被锁定");
|
||||
}
|
||||
}
|
||||
}
|
||||
model.setViewName("login");
|
||||
model.addObject("code", result.getCode());
|
||||
model.addObject("msg" , result.getMessage());
|
||||
model.addObject("username", username);
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/miniLogin.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result miniLogin(String username , String password , String captcha, ModelAndView model , HttpSession session) {
|
||||
Result result = null;
|
||||
if(StringUtils.isEmpty(captcha)) {
|
||||
result = Result.result(204, null, "请输入验证码");
|
||||
} else if(StringUtils.isNotEmpty(captcha)){
|
||||
String kaptcha = ShiroUtils.getKaptcha(SystemConstant.KAPTCHA_SESSION_KEY);
|
||||
if (!captcha.equalsIgnoreCase(kaptcha)) {
|
||||
result = Result.result(205, null, "验证码错误");
|
||||
}else {
|
||||
Subject subject = ShiroUtils.getSubject();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
|
||||
try {
|
||||
subject.login(token);
|
||||
session.setAttribute("currMember", ShiroUtils.getMember());
|
||||
result = Result.successResult(ShiroUtils.getMember());
|
||||
} catch (UnknownAccountException e) {
|
||||
result = Result.result(201, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (IncorrectCredentialsException e) {
|
||||
result = Result.result(202, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (LockedAccountException e) {
|
||||
result = Result.result(203, null, "账号被锁定");
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class LogoutController {
|
||||
|
||||
/**
|
||||
* 注销
|
||||
*/
|
||||
@RequestMapping(value = "logout.html", method = RequestMethod.GET)
|
||||
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
|
||||
if (session.getAttribute("currMember") != null) {
|
||||
session.removeAttribute("currMember");
|
||||
ShiroUtils.logout();
|
||||
}
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class MemberController {
|
||||
|
||||
@Autowired
|
||||
IMemberService iMemberService;
|
||||
|
||||
@RequestMapping(value = "/member/index.html", method = RequestMethod.GET)
|
||||
public ModelAndView index(ModelAndView model){
|
||||
model.setViewName("member/index");
|
||||
model.addObject("member" , iMemberService.findByUid(ShiroUtils.getMember().getId()));
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/findCurrMember.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result findCurrMember() {
|
||||
return Result.successResult(iMemberService.findCurrMember(ShiroUtils.getMemberId()));
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.mapper.Condition;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.tamguo.common.utils.ExceptionSupport;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
import com.tamguo.modules.tiku.model.PaperEntity;
|
||||
import com.tamguo.modules.tiku.model.enums.QuestionTypeEnum;
|
||||
import com.tamguo.modules.tiku.service.IPaperService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class MemberPaperController {
|
||||
|
||||
@Autowired
|
||||
private IPaperService iPaperService;
|
||||
|
||||
|
||||
@RequestMapping(value = "/member/paper.html", method = RequestMethod.GET)
|
||||
public ModelAndView paper(ModelAndView model, HttpSession session){
|
||||
model.setViewName("member/paperList");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/findPaper.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result findPaper(String paperId) {
|
||||
return Result.successResult(iPaperService.selectById(paperId));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked"})
|
||||
@RequestMapping(value = "member/paper/list.html" , method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Map<String, Object> paperList(String name , Integer page , Integer limit , HttpSession session){
|
||||
MemberEntity member = ((MemberEntity)session.getAttribute("currMember"));
|
||||
Page<PaperEntity> list = iPaperService.selectPage(new Page<>(page , limit) , Condition.create().like("name", name).eq("creater_id", member.getId()));
|
||||
return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages());
|
||||
}
|
||||
|
||||
@RequestMapping(value="member/paperList/addPaperQuestionInfo.html",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result addPaperQuestionInfo(@RequestBody JSONObject data){
|
||||
try {
|
||||
String paperId ; String title ; String name ;String type;
|
||||
paperId = data.getString("uid");
|
||||
title = data.getString("title");
|
||||
type = data.getString("type");
|
||||
name = QuestionTypeEnum.getQuestionType(type).getDesc();
|
||||
iPaperService.addPaperQuestionInfo(paperId , title , name , type);
|
||||
return Result.result(0, null, "修改成功");
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("添加questionInfo", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("member/paperList/updatePaperQuestionInfo.html")
|
||||
@ResponseBody
|
||||
public Result updatePaperQuestionInfo(@RequestBody JSONObject data){
|
||||
try {
|
||||
String paperId ; String title ; String name ; String type ; String uid;
|
||||
paperId = data.getString("uid");
|
||||
title = data.getString("title");
|
||||
type = data.getString("type");
|
||||
name = QuestionTypeEnum.getQuestionType(type).getDesc();
|
||||
uid = data.getString("infoUid");
|
||||
iPaperService.updatePaperQuestionInfo(paperId , title , name , type , uid);
|
||||
return Result.result(0, null, "修改成功");
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("修改questionInfo", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("member/paperList/deletePaper")
|
||||
@ResponseBody
|
||||
public Result deletePaper(String paperId){
|
||||
try {
|
||||
return iPaperService.deletePaper(ShiroUtils.getMemberId() , paperId);
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("删除试卷", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping("member/paperList/deletePaperQuestionInfoBtn.html")
|
||||
@ResponseBody
|
||||
public Result deletePaperQuestionInfoBtn(String paperId , String uid){
|
||||
try {
|
||||
return iPaperService.deletePaperQuestionInfoBtn(ShiroUtils.getMemberId() , paperId , uid);
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("删除子卷", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value="member/paperList/addPaper.html",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result addPaper(@RequestBody PaperEntity paper,HttpSession session){
|
||||
try {
|
||||
MemberEntity member = (MemberEntity) session.getAttribute("currMember");
|
||||
paper.setCreaterId(member.getId());
|
||||
iPaperService.addPaper(paper);
|
||||
return Result.result(Result.SUCCESS_CODE, paper, "添加成功");
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("添加试卷", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value="member/paperList/updatePaper.html",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result updatePaper(@RequestBody PaperEntity paper){
|
||||
try {
|
||||
return iPaperService.updatePaper(paper , ShiroUtils.getMemberId());
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("修改试卷", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.common.utils.SystemConstant;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class PasswordController {
|
||||
|
||||
@Autowired
|
||||
private IMemberService iMemberService;
|
||||
|
||||
@RequestMapping(value = "password/find.html", method = RequestMethod.GET)
|
||||
public ModelAndView confirmAccount(ModelAndView model){
|
||||
model.setViewName("password/confirmAccount");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "password/confirmAccount.html", method = RequestMethod.POST)
|
||||
public ModelAndView submitConfirmAccount(String username , String veritycode , ModelAndView model){
|
||||
Result result = iMemberService.confirmAccount(username, veritycode);
|
||||
String kaptcha = ShiroUtils.getKaptcha(SystemConstant.KAPTCHA_SESSION_KEY);
|
||||
if (!veritycode.equalsIgnoreCase(kaptcha)) {
|
||||
result = Result.result(202, null, "验证码错误");
|
||||
}
|
||||
if(result.getCode() == 200){
|
||||
model.setViewName("password/securityCheck");
|
||||
model.addObject("result", result);
|
||||
model.addObject("isEmail", username.contains("@") ? "1" : "0");
|
||||
}else{
|
||||
model.setViewName("password/confirmAccount");
|
||||
model.addObject("account", username);
|
||||
model.addObject("username",username);
|
||||
model.addObject("veritycode", veritycode);
|
||||
model.addObject("code", result.getCode());
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "password/securityCheck.html", method = RequestMethod.POST)
|
||||
public ModelAndView securityCheck(String username , String isEmail , String mobileVcode , ModelAndView model){
|
||||
Result result = iMemberService.securityCheck(username , isEmail , mobileVcode);
|
||||
if(result.getCode() == 200){
|
||||
model.addObject("username", username);
|
||||
model.addObject("resetPasswordKey" , result.getResult());
|
||||
model.setViewName("password/resetPassword");
|
||||
}else{
|
||||
model.addObject("result", result);
|
||||
model.addObject("isEmail", isEmail);
|
||||
model.addObject("codeError", "1");
|
||||
model.setViewName("password/securityCheck");
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "password/resetPassword.html", method = RequestMethod.POST)
|
||||
public ModelAndView resetPassword(String resetPasswordKey , String username , String password , String verifypwd , ModelAndView model){
|
||||
Result result = iMemberService.resetPassword(resetPasswordKey , username , password , verifypwd);
|
||||
if(result.getCode() == 200){
|
||||
model.setViewName("password/resetPwSuccess");
|
||||
}else{
|
||||
model.setViewName("password/resetPassword");
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "password/checkAccount.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result checkAccount(String account){
|
||||
return iMemberService.checkAccount(account);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.plugins.Page;
|
||||
import com.tamguo.common.utils.ExceptionSupport;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.tiku.model.QuestionEntity;
|
||||
import com.tamguo.modules.tiku.service.IPaperService;
|
||||
import com.tamguo.modules.tiku.service.IQuestionService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller(value="memberQuestionController")
|
||||
public class QuestionController {
|
||||
|
||||
@Autowired
|
||||
private IQuestionService iQuestionService;
|
||||
@Autowired
|
||||
private IPaperService iPaperService;
|
||||
|
||||
@RequestMapping(value = "/member/addQuestion.html", method = RequestMethod.GET)
|
||||
public ModelAndView index(String paperId , ModelAndView model){
|
||||
model.setViewName("member/addQuestion");
|
||||
model.addObject("paper", iPaperService.selectById(paperId));
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/submitQuestion.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result submitQuestion(QuestionEntity question){
|
||||
try {
|
||||
return iQuestionService.addQuestion(question , ShiroUtils.getMemberId());
|
||||
} catch (Exception e) {
|
||||
return ExceptionSupport.resolverResult("添加试题", this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/questionList.html", method = RequestMethod.GET)
|
||||
public ModelAndView questionList(String paperId , ModelAndView model){
|
||||
model.addObject("paper", iPaperService.selectById(paperId));
|
||||
model.setViewName("member/questionList");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/queryQuestionList.html" , method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Map<String, Object> queryQuestionList(@RequestBody JSONObject data){
|
||||
String questionType ; String uid ; String content ; String paperId ;
|
||||
Integer page ; Integer limit;
|
||||
questionType = data.getString("questionType");
|
||||
uid = data.getString("uid");
|
||||
content = data.getString("content");
|
||||
paperId = data.getString("paperId");
|
||||
page = data.getInteger("page");
|
||||
limit = data.getInteger("limit");
|
||||
Page<QuestionEntity> p = new Page<>();
|
||||
p.setCurrent(page);
|
||||
p.setSize(limit);
|
||||
Page<QuestionEntity> list = iQuestionService.queryQuestionList(questionType , uid , content , paperId , ShiroUtils.getMemberId() , p);
|
||||
return Result.jqGridResult(list.getRecords(), list.getTotal(), limit, page, list.getPages());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/editQuestion.html", method = RequestMethod.GET)
|
||||
public ModelAndView editQuestion(String paperId , String questionId , ModelAndView model){
|
||||
model.setViewName("member/editQuestion");
|
||||
model.addObject("paper", iPaperService.selectById(paperId));
|
||||
model.addObject("questionId" , questionId);
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/getQuestion.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result getQuestion(String questionId) {
|
||||
return Result.successResult(iQuestionService.selectById(questionId));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/member/updateQuestion.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result updateQuestion(QuestionEntity question) {
|
||||
return iQuestionService.updateQuestion(question , ShiroUtils.getMemberId());
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/member/deleteQuestion.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result deleteQuestion(@RequestBody String uid) {
|
||||
return iQuestionService.delete(uid , ShiroUtils.getMemberId());
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.tamguo.web.member;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.shiro.authc.IncorrectCredentialsException;
|
||||
import org.apache.shiro.authc.LockedAccountException;
|
||||
import org.apache.shiro.authc.UnknownAccountException;
|
||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.member.model.MemberEntity;
|
||||
import com.tamguo.modules.member.service.IMemberService;
|
||||
import com.tamguo.utils.ShiroUtils;
|
||||
|
||||
@Controller
|
||||
public class RegisterController {
|
||||
|
||||
@Autowired
|
||||
private IMemberService iMemberService;
|
||||
|
||||
@RequestMapping(value = "/register.html", method = RequestMethod.GET)
|
||||
public ModelAndView register(ModelAndView model , HttpSession session) {
|
||||
model.setViewName("register");
|
||||
return model;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/checkUsername.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result checkUsername(String username){
|
||||
return iMemberService.checkUsername(username);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/checkMobile.html", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result checkMobile(String mobile){
|
||||
return iMemberService.checkMobile(mobile);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/subRegister.html", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Result subRegister(@RequestBody MemberEntity member , HttpSession session){
|
||||
Result result = iMemberService.register(member);
|
||||
if(result.getCode() == 200) {
|
||||
Subject subject = ShiroUtils.getSubject();
|
||||
MemberEntity memberEntity = (MemberEntity) result.getResult();
|
||||
UsernamePasswordToken token = new UsernamePasswordToken(memberEntity.getUsername(), member.getPassword());
|
||||
try {
|
||||
subject.login(token);
|
||||
|
||||
session.setAttribute("currMember", ShiroUtils.getMember());
|
||||
} catch (UnknownAccountException e) {
|
||||
return Result.result(201, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (IncorrectCredentialsException e) {
|
||||
return Result.result(202, null, "用户名或密码有误,请重新输入或找回密码");
|
||||
} catch (LockedAccountException e) {
|
||||
return Result.result(203, null, "账号被锁定");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.tamguo.web.tiku;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.tamguo.common.utils.Result;
|
||||
import com.tamguo.modules.sys.service.ISmsService;
|
||||
|
||||
@Controller
|
||||
public class SmsController {
|
||||
|
||||
@Autowired
|
||||
ISmsService iSmsService;
|
||||
|
||||
@RequestMapping(value = {"sms/sendFindPasswordSms.html"}, method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Result sendFindPasswordSms(String mobile){
|
||||
try {
|
||||
return iSmsService.sendFindPasswordSms(mobile);
|
||||
} catch (ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.result(500, null, "");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue