| | |
| | | |
| | | import com.ycl.jxkg.base.SystemCode; |
| | | import com.ycl.jxkg.domain.entity.UserEventLog; |
| | | import com.ycl.jxkg.enums.general.YesOrNoEnum; |
| | | import com.ycl.jxkg.event.UserEvent; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | User springUser = (User) object; |
| | | com.ycl.jxkg.domain.entity.User user = userService.getUserByUserName(springUser.getUsername()); |
| | | if (null != user) { |
| | | // 密码过期返回强制修改密码标识 |
| | | if (YesOrNoEnum.YES.equals(user.getNeedUpdatePassword())) { |
| | | RestUtil.response(response, 205, "密码过期,请修改密码", user.getId()); |
| | | return; |
| | | } |
| | | UserEventLog userEventLog = new UserEventLog(user.getId(), user.getUserName(), user.getRealName(), new Date()); |
| | | userEventLog.setContent(user.getUserName() + " 登录了江西语音视频培训系统"); |
| | | eventPublisher.publishEvent(new UserEvent(userEventLog)); |
| | |
| | | .and().authenticationProvider(restAuthenticationProvider) |
| | | .authorizeRequests() |
| | | .antMatchers(securityIgnoreUrls.toArray(ignores)).permitAll() |
| | | .antMatchers("/api/admin/user/update/password").permitAll() |
| | | .antMatchers("/api/admin/**").hasRole(RoleEnum.ADMIN.getName()) |
| | | .antMatchers("/api/student/**").hasRole(RoleEnum.STUDENT.getName()) |
| | | .antMatchers("/api/register/**").anonymous() |
| | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.form.UpdatePwdForm; |
| | | import com.ycl.jxkg.enums.RoleEnum; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | |
| | | return Result.ok(keyValues); |
| | | } |
| | | |
| | | @PostMapping("/update/password") |
| | | public Result<Object> updatePassword(@RequestBody @Validated UpdatePwdForm form) { |
| | | userService.updatePassword(form); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.ycl.jxkg.domain.base.AbsEntity; |
| | | import com.ycl.jxkg.enums.general.YesOrNoEnum; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | @TableField("wx_open_id") |
| | | private String wxOpenId; |
| | | |
| | | @TableField("need_update_password") |
| | | /** |
| | | * 是否需要修改密码 |
| | | */ |
| | | private YesOrNoEnum needUpdatePassword; |
| | | |
| | | @TableField("last_update_password_time") |
| | | /** |
| | | * 上一次修改密码的时间 |
| | | */ |
| | | private Date lastUpdatePasswordTime; |
| | | |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.domain.form; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | /** |
| | | * 修改密码表单数据 |
| | | * |
| | | * @author:xp |
| | | * @date:2024/7/9 16:23 |
| | | */ |
| | | @Data |
| | | public class UpdatePwdForm { |
| | | |
| | | @NotNull(message = "修改失败") |
| | | private Integer userId; |
| | | |
| | | /** 新密码 */ |
| | | @NotBlank(message = "请输入新密码") |
| | | private String newPassword; |
| | | |
| | | } |
New file |
| | |
| | | package com.ycl.jxkg.enums.general; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.EnumValue; |
| | | import com.fasterxml.jackson.annotation.JsonValue; |
| | | import lombok.Getter; |
| | | |
| | | /** |
| | | * 是否 |
| | | * |
| | | * @author:xp |
| | | * @date:2024/6/4 9:35 |
| | | */ |
| | | @Getter |
| | | public enum YesOrNoEnum { |
| | | |
| | | NO(0, "否"), |
| | | YES(1, "是"), |
| | | ; |
| | | |
| | | @EnumValue |
| | | private final Integer value; |
| | | |
| | | @JsonValue |
| | | private final String desc; |
| | | |
| | | YesOrNoEnum(Integer value, String desc) { |
| | | this.value = value; |
| | | this.desc = desc; |
| | | } |
| | | } |
| | |
| | | /** |
| | | * authUser |
| | | * |
| | | * @param username username |
| | | * @param password password |
| | | * @return boolean |
| | | */ |
| | | boolean authUser(String username, String password); |
| | | |
| | | |
| | | |
| | | /** |
| | | * authUser |
| | | * |
| | | * @param user user |
| | | * @param username username |
| | | * @param password password |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ycl.jxkg.domain.form.RegisterForm; |
| | | import com.ycl.jxkg.domain.form.UpdatePwdForm; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.domain.vo.StudentVO; |
| | |
| | | * @return |
| | | */ |
| | | List<StudentVO> classesStudent(Integer classesId); |
| | | |
| | | /** |
| | | * 修改密码 |
| | | * |
| | | * @param form |
| | | */ |
| | | void updatePassword(UpdatePwdForm form); |
| | | } |
| | |
| | | @Service |
| | | public class AuthenticationServiceImpl implements AuthenticationService { |
| | | |
| | | |
| | | private final UserService userService; |
| | | private final SystemConfig systemConfig; |
| | | |
| | | @Autowired |
| | | public AuthenticationServiceImpl(UserService userService, SystemConfig systemConfig) { |
| | | this.userService = userService; |
| | | public AuthenticationServiceImpl(SystemConfig systemConfig) { |
| | | this.systemConfig = systemConfig; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param username username |
| | | * @param password password |
| | | * @return boolean |
| | | */ |
| | | @Override |
| | | public boolean authUser(String username, String password) { |
| | | User user = userService.getUserByUserName(username); |
| | | return authUser(user, username, password); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public boolean authUser(User user, String username, String password) { |
| | |
| | | package com.ycl.jxkg.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.qiniu.util.Md5; |
| | | import com.ycl.jxkg.domain.entity.UserEventLog; |
| | | import com.ycl.jxkg.domain.form.UpdatePwdForm; |
| | | import com.ycl.jxkg.enums.RoleEnum; |
| | | import com.ycl.jxkg.enums.UserStatusEnum; |
| | | import com.ycl.jxkg.domain.form.RegisterForm; |
| | | import com.ycl.jxkg.domain.other.KeyValue; |
| | | import com.ycl.jxkg.domain.vo.StudentVO; |
| | | import com.ycl.jxkg.enums.general.YesOrNoEnum; |
| | | import com.ycl.jxkg.event.UserEvent; |
| | | import com.ycl.jxkg.exception.BusinessException; |
| | | import com.ycl.jxkg.domain.entity.User; |
| | | import com.ycl.jxkg.event.OnRegistrationCompleteEvent; |
| | | import com.ycl.jxkg.mapper.UserMapper; |
| | | import com.ycl.jxkg.service.AuthenticationService; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import com.ycl.jxkg.domain.vo.admin.user.UserPageRequestVO; |
| | | import com.github.pagehelper.PageHelper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | |
| | | |
| | |
| | | |
| | | private final UserMapper userMapper; |
| | | private final ApplicationEventPublisher eventPublisher; |
| | | private final AuthenticationService authenticationService; |
| | | |
| | | |
| | | public List<User> getUsers() { |
| | |
| | | public List<StudentVO> classesStudent(Integer classesId) { |
| | | return userMapper.classesStudent(classesId); |
| | | } |
| | | |
| | | @Override |
| | | public void updatePassword(UpdatePwdForm form) { |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .eq(User::getId, form.getUserId()) |
| | | .set(User::getPassword, authenticationService.pwdEncode(form.getNewPassword())) |
| | | .set(User::getNeedUpdatePassword, YesOrNoEnum.NO) |
| | | .set(User::getLastUpdatePasswordTime, new Date()) |
| | | .update(); |
| | | } |
| | | } |
| | |
| | | <result column="last_active_time" jdbcType="TIMESTAMP" property="lastActiveTime"/> |
| | | <result column="deleted" jdbcType="BIT" property="deleted"/> |
| | | <result column="wx_open_id" jdbcType="VARCHAR" property="wxOpenId"/> |
| | | <result column="need_update_password" property="needUpdatePassword" typeHandler="com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler"/> |
| | | <result column="last_update_password_time" property="lastUpdatePasswordTime"/> |
| | | </resultMap> |
| | | <sql id="Base_Column_List"> |
| | | id |
| | | , user_uuid, user_name, password, real_name, age, sex, birth_day, user_level, phone, |
| | | role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id |
| | | role, status, image_path, create_time, modify_time, last_active_time, deleted, wx_open_id, |
| | | need_update_password, last_update_password_time |
| | | </sql> |
| | | |
| | | |