验证码登录
This commit is contained in:
parent
84091da9d5
commit
50dcb6898c
@ -136,7 +136,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {getCodeImg, gettelcode, gettellogin,} from "@/api/login";
|
import {getCodeImg, gettelcode, gettellogin,} from "@/api/login";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||||
import BalanceRecharge from "@/views/member/balanceRecharge.vue";
|
import BalanceRecharge from "@/views/member/balanceRecharge.vue";
|
||||||
@ -152,7 +152,7 @@ export default {
|
|||||||
timer: null,
|
timer: null,
|
||||||
dlyzm:[
|
dlyzm:[
|
||||||
{text:'登录',type:'0'},
|
{text:'登录',type:'0'},
|
||||||
{text: "验证码",type:'1'}
|
// {text: "验证码",type:'1'}
|
||||||
],
|
],
|
||||||
actindex:0,
|
actindex:0,
|
||||||
codeUrl: "",
|
codeUrl: "",
|
||||||
|
@ -63,11 +63,20 @@ orderCancel.job.time = 0 0/1 * * * ?
|
|||||||
|
|
||||||
################## \u963F\u91CC\u4E91\u77ED\u4FE1\u914D\u7F6E #######################
|
################## \u963F\u91CC\u4E91\u77ED\u4FE1\u914D\u7F6E #######################
|
||||||
# \u77ED\u4FE1\u63A5\u53E3\u6A21\u5F0F[0-\u5173\u95ED 1-\u6253\u5F00]
|
# \u77ED\u4FE1\u63A5\u53E3\u6A21\u5F0F[0-\u5173\u95ED 1-\u6253\u5F00]
|
||||||
|
#aliyun.sms.mode = 0
|
||||||
|
#aliyun.sms.accessKeyId=LTAI4GJMjV123oXsrQJLnPZt
|
||||||
|
#aliyun.sms.accessKeySecret=eGVBL30u5Ypj234d7XODlwYKWTaGT
|
||||||
|
## \u963F\u91CC\u4E91\u77ED\u4FE1\u7B7E\u540D
|
||||||
|
#aliyun.sms.signName=\u5EF6\u79BE\u6280\u672F
|
||||||
|
|
||||||
aliyun.sms.mode = 0
|
aliyun.sms.mode = 0
|
||||||
aliyun.sms.accessKeyId=LTAI4GJMjV123oXsrQJLnPZt
|
aliyun.sms.accessKeyId=LTAI5tDaR1thArLkQ4gmRUMS
|
||||||
aliyun.sms.accessKeySecret=eGVBL30u5Ypj234d7XODlwYKWTaGT
|
aliyun.sms.accessKeySecret=whimt0bhMMJ0amVZPsvJ2euz8nCiOp
|
||||||
|
aliyun.sms.regionId=cn-hangzhou
|
||||||
|
aliyun.sms.templateCode=SMS_154950909
|
||||||
# \u963F\u91CC\u4E91\u77ED\u4FE1\u7B7E\u540D
|
# \u963F\u91CC\u4E91\u77ED\u4FE1\u7B7E\u540D
|
||||||
aliyun.sms.signName=\u5EF6\u79BE\u6280\u672F
|
aliyun.sms.signName=阿里云短信测试
|
||||||
|
|
||||||
|
|
||||||
################## \u963F\u91CC\u4E91OSS\u5B58\u50A8\u914D\u7F6E######################
|
################## \u963F\u91CC\u4E91OSS\u5B58\u50A8\u914D\u7F6E######################
|
||||||
# \u6A21\u5F0F[0-\u5173\u95ED 1-\u6253\u5F00]
|
# \u6A21\u5F0F[0-\u5173\u95ED 1-\u6253\u5F00]
|
||||||
|
0
fuintBackend/configure/dev/application2.properties
Normal file
0
fuintBackend/configure/dev/application2.properties
Normal file
@ -41,6 +41,7 @@ public interface ILJStaffService extends IService<LJStaff> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public LJStaff selectStaffByMobile(String mobile);
|
public LJStaff selectStaffByMobile(String mobile);
|
||||||
|
public LJStaff selectStaffByMobile2(String mobile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除员工信息
|
* 批量删除员工信息
|
||||||
|
@ -102,6 +102,17 @@ public class LJStaffServiceImpl extends ServiceImpl<LJStaffMapper, LJStaff> impl
|
|||||||
return staff;
|
return staff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LJStaff selectStaffByMobile2(String mobile) {
|
||||||
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
|
queryWrapper.eq("mobile",mobile);
|
||||||
|
queryWrapper.eq("status","qy");
|
||||||
|
queryWrapper.eq("if_delete","0");
|
||||||
|
LJStaff staff = baseMapper.selectOne(queryWrapper);
|
||||||
|
return staff;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id批量删除员工信息
|
* 根据id批量删除员工信息
|
||||||
* @param ids
|
* @param ids
|
||||||
|
@ -219,6 +219,7 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
|
|||||||
String accountStatus = param.get("accountStatus").toString();
|
String accountStatus = param.get("accountStatus").toString();
|
||||||
String realName = param.get("realName").toString();
|
String realName = param.get("realName").toString();
|
||||||
String password = param.get("password").toString();
|
String password = param.get("password").toString();
|
||||||
|
String mobile = param.get("mobile").toString();
|
||||||
|
|
||||||
// String roleIds = param.get("roleIds").toString();
|
// String roleIds = param.get("roleIds").toString();
|
||||||
String storeId = param.get("storeId") == null ? "0" : param.get("storeId").toString();
|
String storeId = param.get("storeId") == null ? "0" : param.get("storeId").toString();
|
||||||
@ -275,6 +276,7 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
|
|||||||
tAccount.setStaffId(Integer.parseInt(staffId));
|
tAccount.setStaffId(Integer.parseInt(staffId));
|
||||||
tAccount.setDeptId(Long.parseLong(deptId));
|
tAccount.setDeptId(Long.parseLong(deptId));
|
||||||
tAccount.setRoleIds(roleId);
|
tAccount.setRoleIds(roleId);
|
||||||
|
tAccount.setMobile(mobile);
|
||||||
|
|
||||||
TAccount resAccountInfo = createAccountInfo(tAccount, duties);
|
TAccount resAccountInfo = createAccountInfo(tAccount, duties);
|
||||||
|
|
||||||
@ -448,6 +450,7 @@ public class AccountServiceImpl extends ServiceImpl<TAccountMapper, TAccount> im
|
|||||||
account.setDeptId(tAccount.getDeptId());
|
account.setDeptId(tAccount.getDeptId());
|
||||||
account.setPassword(tAccount.getPassword());
|
account.setPassword(tAccount.getPassword());
|
||||||
account.setStaffId(tAccount.getStaffId());
|
account.setStaffId(tAccount.getStaffId());
|
||||||
|
account.setMobile(tAccount.getMobile());
|
||||||
this.entryptPassword(account);
|
this.entryptPassword(account);
|
||||||
int id = tAccountMapper.insert(account);
|
int id = tAccountMapper.insert(account);
|
||||||
|
|
||||||
|
@ -7,22 +7,38 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|||||||
import com.aliyuncs.exceptions.ClientException;
|
import com.aliyuncs.exceptions.ClientException;
|
||||||
import com.aliyuncs.profile.DefaultProfile;
|
import com.aliyuncs.profile.DefaultProfile;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信发送工具类
|
* 短信发送工具类
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Component
|
||||||
public class SMSUtils {
|
public class SMSUtils {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Environment env;
|
||||||
/**
|
/**
|
||||||
* 发送短信
|
* 发送短信
|
||||||
* @param signName 签名
|
|
||||||
* @param templateCode 模板
|
|
||||||
* @param phoneNumbers 手机号
|
* @param phoneNumbers 手机号
|
||||||
* @param param 参数
|
* @param param 参数
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(String signName, String templateCode,String phoneNumbers,String param){
|
|
||||||
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t7GEqGL46cwjYs6aanu", "d9MpwlyXbHOTrQaA5n8URVz40x5AX3");
|
public void sendMessage(String phoneNumbers,String param){
|
||||||
|
|
||||||
|
String signName = env.getProperty("aliyun.sms.signName");
|
||||||
|
String templateCode = env.getProperty("aliyun.sms.templateCode");
|
||||||
|
String regionId = env.getProperty("aliyun.sms.regionId");
|
||||||
|
String accessKeyId = env.getProperty("aliyun.sms.accessKeyId");
|
||||||
|
String accessKeySecret = env.getProperty("aliyun.sms.accessKeySecret");
|
||||||
|
signName = "阿里云短信测试";
|
||||||
|
DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
|
||||||
IAcsClient client = new DefaultAcsClient(profile);
|
IAcsClient client = new DefaultAcsClient(profile);
|
||||||
|
|
||||||
SendSmsRequest request = new SendSmsRequest();
|
SendSmsRequest request = new SendSmsRequest();
|
||||||
@ -33,7 +49,7 @@ public class SMSUtils {
|
|||||||
request.setTemplateParam("{\"code\":\""+param+"\"}");
|
request.setTemplateParam("{\"code\":\""+param+"\"}");
|
||||||
try {
|
try {
|
||||||
SendSmsResponse response = client.getAcsResponse(request);
|
SendSmsResponse response = client.getAcsResponse(request);
|
||||||
System.out.println("短信发送成功"+response);
|
log.info("--短信发送成功{}--",response.getMessage());
|
||||||
}catch (ClientException e) {
|
}catch (ClientException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package com.fuint.module.backendApi.controller;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.api.R;
|
import com.baomidou.mybatisplus.extension.api.R;
|
||||||
|
import com.fuint.business.member.entity.LJStaff;
|
||||||
|
import com.fuint.business.member.service.ILJStaffService;
|
||||||
import com.fuint.business.userManager.entity.LJUser;
|
import com.fuint.business.userManager.entity.LJUser;
|
||||||
import com.fuint.business.userManager.service.LJUserService;
|
import com.fuint.business.userManager.service.LJUserService;
|
||||||
import com.fuint.common.dto.AccountInfo;
|
import com.fuint.common.dto.AccountInfo;
|
||||||
@ -34,6 +36,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import com.fuint.common.domain.TreeNode;
|
import com.fuint.common.domain.TreeNode;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequestWrapper;
|
||||||
import javax.servlet.http.HttpSession;
|
import javax.servlet.http.HttpSession;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -123,6 +126,8 @@ public class BackendLoginController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
SMSUtils smsUtils;
|
||||||
/**
|
/**
|
||||||
* 发送手机验证码
|
* 发送手机验证码
|
||||||
* */
|
* */
|
||||||
@ -140,10 +145,9 @@ public class BackendLoginController extends BaseController {
|
|||||||
}
|
}
|
||||||
//生成随机的四位验证码
|
//生成随机的四位验证码
|
||||||
String code = ValidateCodeUtils.verificationCode(4);
|
String code = ValidateCodeUtils.verificationCode(4);
|
||||||
//String code = "1234";
|
code = "1234";
|
||||||
//调用阿里云提供的短信服务API完成发送短信
|
//调用阿里云提供的短信服务API完成发送短信
|
||||||
SMSUtils.sendMessage("阿里云短信测试","SMS_154950909",phone,code);
|
smsUtils.sendMessage(phone,code);
|
||||||
//SMSUtils.sendMessage("蓝鲸智慧油站", "SMS_291345282",phone,code);
|
|
||||||
//需要将生成的验证码保存到redis,过期时间300s
|
//需要将生成的验证码保存到redis,过期时间300s
|
||||||
redisTemplate.opsForValue().set(phone,code,300, TimeUnit.SECONDS);
|
redisTemplate.opsForValue().set(phone,code,300, TimeUnit.SECONDS);
|
||||||
return getSuccessResult("手机验证码发送成功");
|
return getSuccessResult("手机验证码发送成功");
|
||||||
@ -151,6 +155,9 @@ public class BackendLoginController extends BaseController {
|
|||||||
return getFailureResult("短信发送失败");
|
return getFailureResult("短信发送失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ILJStaffService iljStaffService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*手机验证码登录
|
*手机验证码登录
|
||||||
* @param map
|
* @param map
|
||||||
@ -158,20 +165,40 @@ public class BackendLoginController extends BaseController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/loginByPhone")
|
@PostMapping("/loginByPhone")
|
||||||
public ResponseObject loginByPhone(@RequestBody Map map) {
|
public ResponseObject loginByPhone(HttpServletRequest request, @RequestBody Map map) {
|
||||||
|
String userAgent = request.getHeader("user-agent");
|
||||||
|
|
||||||
//获取手机号
|
//获取手机号
|
||||||
String phone = map.get("mobile").toString();
|
String phone = map.get("mobile").toString();
|
||||||
//获取用户信息
|
//获取用户信息
|
||||||
LJUser ljUser = userService.selectUserByMobile(phone);
|
// LJUser ljUser = userService.selectUserByMobile(phone);
|
||||||
|
// 获取员工信息
|
||||||
|
LJStaff ljStaff = iljStaffService.selectStaffByMobile2(phone);
|
||||||
|
TAccount tAccount = accountService.selectAccountByStaffId(ljStaff.getId());
|
||||||
|
AccountInfo accountInfo = accountService.getAccountByName(tAccount.getAccountName());
|
||||||
|
|
||||||
//获取验证码
|
//获取验证码
|
||||||
String code = map.get("code").toString();
|
String code = map.get("code").toString();
|
||||||
//从redis中获取保存的验证码
|
//从redis中获取保存的验证码
|
||||||
Object codeInRedis = redisTemplate.opsForValue().get(phone);
|
Object codeInRedis = redisTemplate.opsForValue().get(phone);
|
||||||
//进行验证码的比对
|
//进行验证码的比对
|
||||||
if (codeInRedis != null && codeInRedis.equals(code) && ObjectUtils.isNotEmpty(ljUser)) {
|
if (codeInRedis != null && codeInRedis.equals(code) && ObjectUtils.isNotEmpty(ljStaff)) {
|
||||||
|
|
||||||
//如果能够比对成功,说明登录成功
|
//如果能够比对成功,说明登录成功
|
||||||
return getSuccessResult("登录成功!",ljUser);
|
Subject subject = SecurityUtils.getSubject();
|
||||||
}else if (codeInRedis != null && codeInRedis.equals(code) && ObjectUtils.isEmpty(ljUser)){
|
UsernamePasswordToken info = new UsernamePasswordToken(accountInfo.getAccountName(), tAccount.getPassword());
|
||||||
|
subject.login(info);
|
||||||
|
String token = TokenUtil.generateToken(userAgent, accountInfo.getId());
|
||||||
|
accountInfo.setToken(token);
|
||||||
|
TokenUtil.saveAccountToken(accountInfo);
|
||||||
|
LoginResponse response = new LoginResponse();
|
||||||
|
response.setLogin(true);
|
||||||
|
response.setToken(token);
|
||||||
|
response.setTokenCreatedTime(new Date());
|
||||||
|
return getSuccessResult(response);
|
||||||
|
|
||||||
|
// return getSuccessResult("登录成功!",ljUser);
|
||||||
|
}else if (codeInRedis != null && codeInRedis.equals(code) && ObjectUtils.isEmpty(accountInfo)){
|
||||||
return getSuccessResult("用户不存在,请先注册账号!");
|
return getSuccessResult("用户不存在,请先注册账号!");
|
||||||
}else {
|
}else {
|
||||||
return getFailureResult("登录失败,请输入正确的验证码");
|
return getFailureResult("登录失败,请输入正确的验证码");
|
||||||
|
@ -73,6 +73,6 @@ public class TAccount extends BaseEntity implements Serializable {
|
|||||||
private Long deptId;
|
private Long deptId;
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String deptName;
|
private String deptName;
|
||||||
@TableField(exist = false)
|
// @TableField(exist = false)
|
||||||
private String mobile;
|
private String mobile;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,15 @@ export function login(username, password, captchaCode, uuid) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取手机验证码
|
||||||
|
export function gettelcode(data) {
|
||||||
|
return request({
|
||||||
|
url: 'backendApi/login/sendMsg',
|
||||||
|
method: 'post',
|
||||||
|
data:data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 获取用户详细信息
|
// 获取用户详细信息
|
||||||
export function getInfo() {
|
export function getInfo() {
|
||||||
return request({
|
return request({
|
||||||
|
@ -94,6 +94,22 @@ const user = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 验证码登录
|
||||||
|
codeLogin({ commit }, userInfo) {
|
||||||
|
const mobile = userInfo.mobile
|
||||||
|
const code = userInfo.code
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
gettellogin(mobile, code).then(res => {
|
||||||
|
setToken(res.data.token)
|
||||||
|
commit('SET_TOKEN', res.data.token)
|
||||||
|
resolve()
|
||||||
|
}).catch(error => {
|
||||||
|
reject(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
// 前端登出
|
// 前端登出
|
||||||
FedLogOut({ commit }) {
|
FedLogOut({ commit }) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
style="width:100%;line-height: 24px;font-size: 16px;"
|
style="width:100%;line-height: 24px;font-size: 16px;"
|
||||||
@click.native.prevent="handleLogin"
|
@click.native.prevent="handleLogin"
|
||||||
>
|
>
|
||||||
<span v-if="!loading">立即登录</span>
|
<span v-if="!loading" >立即登录</span>
|
||||||
<span v-else>登 录 中...</span>
|
<span v-else>登 录 中...</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -136,7 +136,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from "@/api/login";
|
import { getCodeImg ,gettelcode} from "@/api/login";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ export default {
|
|||||||
timer: null,
|
timer: null,
|
||||||
dlyzm:[
|
dlyzm:[
|
||||||
{text:'登录',type:'0'},
|
{text:'登录',type:'0'},
|
||||||
{text: "验证码",type:'1'}
|
// {text: "验证码",type:'1'}
|
||||||
],
|
],
|
||||||
actindex:0,
|
actindex:0,
|
||||||
codeUrl: "",
|
codeUrl: "",
|
||||||
@ -232,7 +232,8 @@ export default {
|
|||||||
code:this.loginForm.telcode
|
code:this.loginForm.telcode
|
||||||
}
|
}
|
||||||
this.$store.dispatch("codeLogin", data).then(() => {
|
this.$store.dispatch("codeLogin", data).then(() => {
|
||||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
// this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
||||||
|
this.$router.push({ path:"/homeindex" || "/" }).catch(()=>{});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user