liuyuhang_branch
刘宇航 10 months ago
parent c8b737855a
commit 2176d7dde4

@ -0,0 +1,131 @@
package com.wsk.controller;
import com.wsk.pojo.UserInformation;
import com.wsk.response.BaseResponse;
import com.wsk.service.UserInformationService;
import com.wsk.tool.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
/**
* Created by wsk1103 on 2017/4/30.
*/
@Controller
public class SendEmailController {
@Resource
private UserInformationService userInformationService;
private static final Logger log = LoggerFactory.getLogger(SendEmailController.class);
//send the Email to the phone
@RequestMapping(value = "sendCode.do", method = {RequestMethod.POST, RequestMethod.GET})
@ResponseBody
public BaseResponse sendEmail(HttpServletRequest req, HttpServletResponse res,
@RequestParam String phone, @RequestParam String action,
@RequestParam String token) {
res.setContentType("text/html;charset=UTF-8");
//token防止重复提交
String sendCodeToken = (String) req.getSession().getAttribute("token");
if (StringUtils.getInstance().isNullOrEmpty(sendCodeToken) || !sendCodeToken.equals(token)) {
return BaseResponse.fail();
}
//判断手机号码是否为正确
if (!StringUtils.getInstance().isPhone(phone)) {
return BaseResponse.fail();
}
//如果是忘记密码提交的发送短信
if ("forget".equals(action)) {
if (!isUserPhoneExists(phone)) {
//失败
return BaseResponse.fail();
}
} else if ("register".equals(action)) {
//失败
if (isUserPhoneExists(phone)) {
return BaseResponse.fail();
}
}
//get the random num to phone which should check the phone to judge the phone is belong user
getRandomForCodePhone(req);
String ra = (String) req.getSession().getAttribute("codePhone");
String text1 = "【WSK的验证码】您的验证码是";
String text2 = ",请保护好自己的验证码。";
String text = text1 + ra + text2;
Properties prop = new Properties();
prop.setProperty("mail.host", "smtp.139.com");
prop.setProperty("mail.transport.protocol", "smtp");
prop.setProperty("mail.smtp.auth", "true");
prop.setProperty("mail.smtp.port", "25");
try {
String realPhone = phone;
// phone += "@139.com";
// message.setRecipient(Message.RecipientType.TO, new InternetAddress(phone));
// message.setSubject("来自WSK的验证码");
// message.setContent(text, "text/html;charset=UTF-8");
//这里先不发生信息,以后要开启的
// ts.sendMessage(message, message.getAllRecipients());
// ts.close();
req.getSession().setAttribute("phone", realPhone);
return BaseResponse.success();
} catch (Exception me) {
me.printStackTrace();
return BaseResponse.fail();
}
}
// get the random phone`s code
private void getRandomForCodePhone(HttpServletRequest req) {
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 4; i++) {
sb.append(random.nextInt(10));
}
log.info("短信验证码={}", sb);
System.out.println(sb.toString());
req.getSession().setAttribute("codePhone", sb.toString());
}
// //检验验证码
// private boolean checkPhoto(String photo, HttpServletRequest request) {
// photo = photo.toLowerCase();
// String true_photo = (String) request.getSession().getAttribute("rand");
// return true_photo.equals(photo);
// }
//To determine whether the user's mobile phone number exists
private boolean isUserPhoneExists(String phone) {
boolean result = false;
try {
int id = userInformationService.selectIdByPhone(phone);
if (id == 0) {
return result;
}
UserInformation userInformation = userInformationService.selectByPrimaryKey(id);
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return false;
}
String userPhone = userInformation.getPhone();
result = !userPhone.equals("");
} catch (Exception e) {
e.printStackTrace();
return result;
}
return result;
}
}

@ -0,0 +1,23 @@
package com.wsk.dao;
import com.wsk.pojo.ShopCar;
public interface ShopCarMapper {
int deleteByPrimaryKey(Integer id);
int insert(ShopCar record);
int insertSelective(ShopCar record);
ShopCar selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ShopCar record);
int updateByPrimaryKey(ShopCar record);
int getCounts(int uid);
// List<ShopCar> selectByUid(int uid, int start);
ShopCar selectByUid(int uid);
}

@ -0,0 +1,46 @@
package com.wsk.pojo;
import java.io.Serializable;
import java.util.Date;
public class ShopCar implements Serializable {
private Integer id;
private Date modified;
private Integer display;
private Integer uid;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getModified() {
return modified == null ? null : (Date) modified.clone();
}
public void setModified(Date modified) {
this.modified = modified == null ? null : (Date) modified.clone();
}
public Integer getDisplay() {
return display;
}
public void setDisplay(Integer display) {
this.display = display;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
}

@ -0,0 +1,26 @@
package com.wsk.service;
import com.wsk.pojo.ShopCar;
/**
* Created by wsk1103 on 2017/5/13.
*/
public interface ShopCarService {
int deleteByPrimaryKey(Integer id);
int insert(ShopCar record);
int insertSelective(ShopCar record);
ShopCar selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(ShopCar record);
int updateByPrimaryKey(ShopCar record);
int getCounts(int uid);
// List<ShopCar> selectByUid(int uid, int start);
ShopCar selectByUid(int uid);
}
Loading…
Cancel
Save