注册用户
This commit is contained in:
@@ -1,4 +1,49 @@
|
|||||||
package com.lovenav.controller;
|
package com.lovenav.controller;
|
||||||
|
|
||||||
|
import com.lovenav.entity.User;
|
||||||
|
import com.lovenav.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
import javax.websocket.Session;
|
||||||
|
|
||||||
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
@Autowired
|
||||||
|
UserService userService;
|
||||||
|
@GetMapping("/sendActiveCode")
|
||||||
|
public String sendActiveCode(HttpSession session, User user){
|
||||||
|
String activecode=userService.sendEmailActivecode(user);
|
||||||
|
session.setAttribute("realactivecode",activecode);
|
||||||
|
return "发送验证码成功!";
|
||||||
|
}
|
||||||
|
@RequestMapping("/register")
|
||||||
|
public String userRegister(HttpSession session,User user){
|
||||||
|
|
||||||
|
// 比较验证码
|
||||||
|
if (!user.getActiveCode().equalsIgnoreCase((String) session.getAttribute("realactivecode"))) {
|
||||||
|
return "验证码不正确";
|
||||||
|
}
|
||||||
|
System.out.println(user.getUserLogin());
|
||||||
|
System.out.println(user.getUserEmail());
|
||||||
|
// 用户注册之前根据用户名称查询该用户是否存在如果不存在的情况下才可以注册 如果存在的话就无法注册
|
||||||
|
User user1=userService.selectUserAlreadyExist(user);
|
||||||
|
System.out.println("zhuce");
|
||||||
|
|
||||||
|
if (user1 != null) {
|
||||||
|
return "用户名: " + user1.getUserEmail() + "已被注册!";
|
||||||
|
}
|
||||||
|
//用户数据注册
|
||||||
|
int register = userService.UserRegister(user);
|
||||||
|
if (register <= 0) {
|
||||||
|
// 注册失败了 //转发到错误页面
|
||||||
|
return "注册失败!";
|
||||||
|
}
|
||||||
|
return "注册成功!";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,12 @@
|
|||||||
package com.lovenav.dao;
|
package com.lovenav.dao;
|
||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
@Mapper
|
||||||
public interface UserDao {
|
public interface UserDao {
|
||||||
int deleteByPrimaryKey(Integer id);
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
@@ -17,6 +20,8 @@ public interface UserDao {
|
|||||||
|
|
||||||
int updateByPrimaryKey(User record);
|
int updateByPrimaryKey(User record);
|
||||||
|
|
||||||
|
User selectByEmail(String user_email);
|
||||||
|
|
||||||
|
|
||||||
|
User selectByUserLogin(String user_Login);
|
||||||
}
|
}
|
@@ -3,6 +3,7 @@ package com.lovenav.entity;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ln_user
|
* ln_user
|
||||||
@@ -14,6 +15,14 @@ public class User implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
|
public String getActiveCode() {
|
||||||
|
return activeCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActiveCode(String activeCode) {
|
||||||
|
this.activeCode = activeCode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户登录名
|
* 用户登录名
|
||||||
*/
|
*/
|
||||||
@@ -137,7 +146,12 @@ public class User implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 角色组
|
* 角色组
|
||||||
*/
|
*/
|
||||||
|
@Value("1")
|
||||||
private Byte roleId;
|
private Byte roleId;
|
||||||
|
|
||||||
|
private String activeCode;
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@@ -2,8 +2,15 @@ package com.lovenav.service;
|
|||||||
|
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
|
|
||||||
public interface UserService {
|
|
||||||
public void sendEmailActivecode(User user,String activecode);
|
|
||||||
|
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
|
||||||
|
public String sendEmailActivecode(User user);
|
||||||
|
public int UserRegister(User user);
|
||||||
|
|
||||||
|
public User selectUserAlreadyExist(User user);
|
||||||
|
|
||||||
|
public User userLogin(User user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,40 @@
|
|||||||
package com.lovenav.service.serviceImpl;
|
package com.lovenav.service.serviceImpl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.lovenav.dao.UserDao;
|
||||||
import com.lovenav.utils.EmailUtils;
|
import com.lovenav.utils.EmailUtils;
|
||||||
import com.lovenav.entity.User;
|
import com.lovenav.entity.User;
|
||||||
import com.lovenav.service.UserService;
|
import com.lovenav.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
@Service
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
@Autowired
|
||||||
|
UserDao userDao;
|
||||||
@Override
|
@Override
|
||||||
public void sendEmailActivecode(User user,String activecode) {
|
public String sendEmailActivecode(User user) {
|
||||||
EmailUtils.sendEmail(user,activecode);
|
return EmailUtils.sendEmail(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int UserRegister(User user) {
|
||||||
|
return userDao.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User selectUserAlreadyExist(User user) {
|
||||||
|
System.out.println(user.getUserEmail());
|
||||||
|
User user1=userDao.selectByEmail(user.getUserEmail());
|
||||||
|
return user1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User userLogin(User user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,8 @@ import java.util.Properties;
|
|||||||
* */
|
* */
|
||||||
public class EmailUtils {
|
public class EmailUtils {
|
||||||
|
|
||||||
public static void sendEmail(User user,String activecode) {
|
public static String sendEmail(User user) {
|
||||||
|
|
||||||
//邮箱 lx_teach@163.com
|
//邮箱 lx_teach@163.com
|
||||||
String myAccount = "482370576@qq.com";
|
String myAccount = "482370576@qq.com";
|
||||||
//授权码 java168
|
//授权码 java168
|
||||||
@@ -39,6 +40,7 @@ public class EmailUtils {
|
|||||||
prop.setProperty("mail.smtp.auth", "true");
|
prop.setProperty("mail.smtp.auth", "true");
|
||||||
//1、创建会话
|
//1、创建会话
|
||||||
Session session = Session.getDefaultInstance(prop);
|
Session session = Session.getDefaultInstance(prop);
|
||||||
|
String activecode=RandomUtils.createActive();
|
||||||
//设置是否需要调试
|
//设置是否需要调试
|
||||||
session.setDebug(false);
|
session.setDebug(false);
|
||||||
//2、创建发送信息
|
//2、创建发送信息
|
||||||
@@ -56,6 +58,7 @@ public class EmailUtils {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return activecode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//生成邮件消息
|
//生成邮件消息
|
||||||
|
@@ -144,4 +144,20 @@
|
|||||||
role_id = #{roleId,jdbcType=TINYINT}
|
role_id = #{roleId,jdbcType=TINYINT}
|
||||||
where id = #{id,jdbcType=INTEGER}
|
where id = #{id,jdbcType=INTEGER}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="selectByEmail" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_user
|
||||||
|
where user_email = #{user_email,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
<select id="selectByUserLogin" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from ln_user
|
||||||
|
where user_email = #{user_login,jdbcType=VARCHAR}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Reference in New Issue
Block a user