用户找回密码

This commit is contained in:
Zhang Liguo 2023-12-22 00:14:16 +08:00
parent ce05d3e5cd
commit b20b33ee53
5 changed files with 91 additions and 4 deletions

View File

@ -66,7 +66,7 @@ public class UserController {
map.put("msg","验证码错误");
return map;
}
map.put("code",0);
if(StringUtils.isEmpty(user.getUserLogin())||StringUtils.isEmpty(user.getUserPassword())){
map.put("msg","用户或密码为空!");
return map;
@ -75,10 +75,16 @@ public class UserController {
User user1 = userService.userLogin(user);
if(user1!=null){
map.put("code",200);
String token= tokenUtils.sign(user1);
map.put("cod",1);
map.put("data",user1);
map.put("userEmail",user1.getUserEmail());
map.put("userLogin",user1.getUserLogin());
map.put("user",user1.getUserEmail());
map.put("userStatus",user1.getUserStatus());
map.put("Id",user1.getId());
map.put("nickname",user1.getNickname());
map.put("roleId",user1.getRoleId());
map.put("userRegistered",user1.getUserRegistered());
map.put("token",token);
}else {
map.put("msg","用户名或密码错误!");
@ -99,6 +105,36 @@ public class UserController {
}
}
@RequestMapping("/findThePassword")
public Map<String,Object> findThePassword(User user,HttpSession session){
Map<String,Object> map=new HashMap<>();
User user1=userService.selectUserAlreadyExist(user);
if (user1==null){
map.put("msg","无此邮箱");
return map;
}
// 比较验证码
// if (!user.getActiveCode().equals((String) session.getAttribute(user.getUserEmail()))) {
// map.put("msg","验证码不正确") ;
// return map;
// }
if (user1 != null) {
int result=userService.updatePassword(user1);
if(result==1){
map.put("Data",user1.getUserLogin());
map.put("Data",user1.getUserEmail());
map.put("msg","重置成功");
return map;
}else {
map.put("msg","重置失败");
return map;
}
}
return map;
}
}

View File

@ -25,4 +25,6 @@ public interface UserDao {
User selectByUserLogin(String user_Login);
int updateByEmail(User user);
}

View File

@ -13,4 +13,6 @@ public interface UserService {
public User userLogin(User user);
public int updatePassword(User user);
}

View File

@ -9,6 +9,8 @@ import com.lovenav.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
@ -23,9 +25,15 @@ public class UserServiceImpl implements UserService {
@Override
public int UserRegister(User user) {
user.setRoleId(Byte.valueOf("1"));
user.setUserStatus(Byte.valueOf("1"));
user.setUserPassword(MD5Utils.md5(user.getUserPassword()));
Date date=new Date();
user.setUserRegistered(date);
return userDao.insert(user);
}
@ -67,5 +75,11 @@ public class UserServiceImpl implements UserService {
}
}
@Override
public int updatePassword(User user) {
user.setUserPassword(MD5Utils.md5(user.getUserPassword()));
return userDao.updateByEmail(user);
}
}

View File

@ -145,6 +145,39 @@
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByEmail" parameterType="com.lovenav.entity.User">
update ln_user
<set>
<if test="userLogin != null">
user_login = #{userLogin,jdbcType=VARCHAR},
</if>
<if test="userPassword != null">
user_password = #{userPassword,jdbcType=VARCHAR},
</if>
<if test="phone != null">
phone = #{phone,jdbcType=BIGINT},
</if>
<if test="avatar != null">
avatar = #{avatar,jdbcType=VARCHAR},
</if>
<if test="nickname != null">
nickname = #{nickname,jdbcType=VARCHAR},
</if>
<if test="userEmail != null">
user_email = #{userEmail,jdbcType=VARCHAR},
</if>
<if test="userStatus != null">
user_status = #{userStatus,jdbcType=TINYINT},
</if>
<if test="userRegistered != null">
user_registered = #{userRegistered,jdbcType=TIMESTAMP},
</if>
<if test="roleId != null">
role_id = #{roleId,jdbcType=TINYINT},
</if>
</set>
where user_email = #{userEmail,jdbcType=VARCHAR}
</update>
<select id="selectByEmail" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />