密码,邮箱手机号码验证
This commit is contained in:
@@ -7189,6 +7189,13 @@
|
|||||||
检验验证码并且绑定
|
检验验证码并且绑定
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Ewide.Core.Service.SysUserService.GetPwdRule">
|
||||||
|
<summary>
|
||||||
|
获取密码强度配置
|
||||||
|
</summary>
|
||||||
|
<param name="input"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="F:Ewide.Core.Util.CodeHelper.code_Countdown">
|
<member name="F:Ewide.Core.Util.CodeHelper.code_Countdown">
|
||||||
<summary>
|
<summary>
|
||||||
发送验证码间隔时间(秒)
|
发送验证码间隔时间(秒)
|
||||||
@@ -7271,6 +7278,13 @@
|
|||||||
<param name="length"></param>
|
<param name="length"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Ewide.Core.Util.CodeHelper.CheckRepeat(System.String)">
|
||||||
|
<summary>
|
||||||
|
检测是否重复
|
||||||
|
</summary>
|
||||||
|
<param name="Target"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Ewide.Core.Util.MailHelper.#ctor(System.String,System.String)">
|
<member name="M:Ewide.Core.Util.MailHelper.#ctor(System.String,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
邮箱类
|
邮箱类
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ namespace Ewide.Core.Service
|
|||||||
/// 新密码
|
/// 新密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Required(ErrorMessage = "新密码不能为空")]
|
[Required(ErrorMessage = "新密码不能为空")]
|
||||||
[StringLength(32, MinimumLength = 5, ErrorMessage = "密码需要大于5个字符")]
|
|
||||||
public string NewPassword { get; set; }
|
public string NewPassword { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace Ewide.Core.Service
|
|||||||
|
|
||||||
Task<dynamic> SendCode(Usermailphone input);
|
Task<dynamic> SendCode(Usermailphone input);
|
||||||
Task<dynamic> CheckBindcode(Usermailphone input);
|
Task<dynamic> CheckBindcode(Usermailphone input);
|
||||||
|
Task<dynamic> GetPwdRule();
|
||||||
Task<dynamic> GetOrgUserTree(OrgUserInput input);
|
Task<dynamic> GetOrgUserTree(OrgUserInput input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Ewide.Core.Service.Role;
|
using Ewide.Core.Service.Role;
|
||||||
using Ewide.Core.Service.User.Dto;
|
using Ewide.Core.Service.User.Dto;
|
||||||
using Ewide.Core.Util;
|
using Ewide.Core.Util;
|
||||||
|
using Furion;
|
||||||
using Furion.DatabaseAccessor;
|
using Furion.DatabaseAccessor;
|
||||||
using Furion.DatabaseAccessor.Extensions;
|
using Furion.DatabaseAccessor.Extensions;
|
||||||
using Furion.DataEncryption;
|
using Furion.DataEncryption;
|
||||||
@@ -312,11 +313,26 @@ namespace Ewide.Core.Service
|
|||||||
public async Task UpdateUserPwd(ChangePasswordUserInput input)
|
public async Task UpdateUserPwd(ChangePasswordUserInput input)
|
||||||
{
|
{
|
||||||
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
|
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
|
||||||
if (MD5Encryption.Encrypt(input.Password) != user.Password)
|
var Password = RSAHandler.RSADecrypt(input.Password);
|
||||||
throw Oops.Oh(ErrorCode.D1004);
|
Password = MD5Encryption.Encrypt(Password);
|
||||||
if (MD5Encryption.Encrypt(input.NewPassword).Equals(user.Password))
|
if (Password != user.Password)
|
||||||
|
{
|
||||||
|
throw Oops.Oh("旧密码不正确");
|
||||||
|
}
|
||||||
|
var newPassword = RSAHandler.RSADecrypt(input.NewPassword);
|
||||||
|
// 验证新密码强度
|
||||||
|
var pattern = App.Configuration.GetSection("SimplePassword:Pattern").Value;
|
||||||
|
if (!Regex.Match(newPassword, pattern).Success)
|
||||||
|
{
|
||||||
|
throw Oops.Oh("新密码强度不符合规则");
|
||||||
|
}
|
||||||
|
|
||||||
|
newPassword = MD5Encryption.Encrypt(newPassword);
|
||||||
|
if (newPassword.Equals(user.Password))
|
||||||
throw Oops.Oh(ErrorCode.D10041);
|
throw Oops.Oh(ErrorCode.D10041);
|
||||||
user.Password = MD5Encryption.Encrypt(input.NewPassword);
|
|
||||||
|
user.Password = newPassword;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -467,7 +483,7 @@ namespace Ewide.Core.Service
|
|||||||
var Mailcode_Key = "ewide_mailcode";
|
var Mailcode_Key = "ewide_mailcode";
|
||||||
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
|
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
|
||||||
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
|
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
|
||||||
CodeHelper ch = new CodeHelper(_iMemoryCache);
|
CodeHelper ch = new CodeHelper(_iMemoryCache, _sysUserRep, _userManager);
|
||||||
//Type为1时,给原手机号发送验证码
|
//Type为1时,给原手机号发送验证码
|
||||||
if (input.Type == 1)
|
if (input.Type == 1)
|
||||||
{
|
{
|
||||||
@@ -484,7 +500,7 @@ namespace Ewide.Core.Service
|
|||||||
//Type为2时,给原邮箱发送验证码
|
//Type为2时,给原邮箱发送验证码
|
||||||
else if (input.Type == 2)
|
else if (input.Type == 2)
|
||||||
{
|
{
|
||||||
if (new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$").IsMatch(_userManager.User.Email))
|
if (new Regex(Regex_Email).IsMatch(_userManager.User.Email))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -500,6 +516,7 @@ namespace Ewide.Core.Service
|
|||||||
//Type为null时,则发验证码
|
//Type为null时,则发验证码
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
await ch.CheckRepeat(input.Target);
|
||||||
//通过正则判断绑定类型
|
//通过正则判断绑定类型
|
||||||
if (new Regex(Regex_phone).IsMatch(input.Target))
|
if (new Regex(Regex_phone).IsMatch(input.Target))
|
||||||
{
|
{
|
||||||
@@ -542,7 +559,7 @@ namespace Ewide.Core.Service
|
|||||||
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
|
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
|
||||||
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
|
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
|
||||||
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
|
var user = await _sysUserRep.FirstOrDefaultAsync(u => u.Id == _userManager.UserId);
|
||||||
CodeHelper ch = new CodeHelper(_iMemoryCache);
|
CodeHelper ch = new CodeHelper(_iMemoryCache, _sysUserRep,_userManager);
|
||||||
if (input.Type == 1)
|
if (input.Type == 1)
|
||||||
{
|
{
|
||||||
if (ch.Checkcode(_userManager.User.Phone, input.Orgcode, Orgcode_Key))
|
if (ch.Checkcode(_userManager.User.Phone, input.Orgcode, Orgcode_Key))
|
||||||
@@ -655,6 +672,23 @@ namespace Ewide.Core.Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取密码强度配置
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("/sysUser/getPwdRule")]
|
||||||
|
public async Task<dynamic> GetPwdRule()
|
||||||
|
{
|
||||||
|
return new LoginOutput
|
||||||
|
{
|
||||||
|
Pattern = App.Configuration.GetSection("SimplePassword:Pattern").Value,
|
||||||
|
Descriptions = App.Configuration.GetSection("SimplePassword:Descriptions").Value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpPost("/sysUser/GetOrgUserTree")]
|
[HttpPost("/sysUser/GetOrgUserTree")]
|
||||||
public async Task<dynamic> GetOrgUserTree(OrgUserInput input)
|
public async Task<dynamic> GetOrgUserTree(OrgUserInput input)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
using Aliyun.Acs.Core.Exceptions;
|
using Aliyun.Acs.Core.Exceptions;
|
||||||
using Aliyun.Acs.Core.Profile;
|
using Aliyun.Acs.Core.Profile;
|
||||||
using Furion;
|
using Furion;
|
||||||
|
using Furion.DatabaseAccessor;
|
||||||
using Furion.FriendlyException;
|
using Furion.FriendlyException;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -19,9 +21,17 @@ namespace Ewide.Core.Util
|
|||||||
public class CodeHelper
|
public class CodeHelper
|
||||||
{
|
{
|
||||||
private readonly IMemoryCache _IMemoryCache;
|
private readonly IMemoryCache _IMemoryCache;
|
||||||
public CodeHelper(IMemoryCache IMemoryCache)
|
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
|
||||||
{
|
private readonly IUserManager _userManager;
|
||||||
|
|
||||||
|
public CodeHelper(
|
||||||
|
IMemoryCache IMemoryCache,
|
||||||
|
IRepository<SysUser> sysUserRep,
|
||||||
|
IUserManager userManager
|
||||||
|
){
|
||||||
_IMemoryCache = IMemoryCache;
|
_IMemoryCache = IMemoryCache;
|
||||||
|
_sysUserRep = sysUserRep;
|
||||||
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
public static string Aliyun_AccessKey = App.Configuration["SmsHelper:Aliyun_AccessKey"];
|
public static string Aliyun_AccessKey = App.Configuration["SmsHelper:Aliyun_AccessKey"];
|
||||||
public static string Aliyun_AccessSecret = App.Configuration["SmsHelper:Aliyun_AccessSecret"];
|
public static string Aliyun_AccessSecret = App.Configuration["SmsHelper:Aliyun_AccessSecret"];
|
||||||
@@ -246,7 +256,25 @@ namespace Ewide.Core.Util
|
|||||||
throw Oops.Oh(ErrorCode.xg1100);
|
throw Oops.Oh(ErrorCode.xg1100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检测是否重复
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Target"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> CheckRepeat(string Target)
|
||||||
|
{
|
||||||
|
var Regex_phone = @"^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0,1,3,6-8])|(18[0-9])|(19[8,9])|(166))[0-9]{8}$";
|
||||||
|
var Regex_Email = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
|
||||||
|
if(new Regex(Regex_phone).IsMatch(Target)){
|
||||||
|
var isExist = await _sysUserRep.DetachedEntities.AnyAsync(u => (u.Id != _userManager.UserId ) && (u.Account == Target || u.Phone == Target));
|
||||||
|
if (isExist) throw Oops.Oh("手机号与他人账号或者手机号重复");
|
||||||
|
}else if(new Regex(Regex_Email).IsMatch(Target))
|
||||||
|
{
|
||||||
|
var isExist3 = await _sysUserRep.DetachedEntities.AnyAsync(u => (u.Id != _userManager.UserId) && (u.Account == Target || u.Email == Target));
|
||||||
|
if (isExist3) throw Oops.Oh("邮箱与他人账号或者邮箱重复");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ const urls = {
|
|||||||
*/
|
*/
|
||||||
sysUserCheckBindcode: ['/sysUser/checkBindcode', 'post'],
|
sysUserCheckBindcode: ['/sysUser/checkBindcode', 'post'],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取密码验证配置
|
||||||
|
*/
|
||||||
|
getPwdRule: ['/sysUser/getPwdRule', 'post'],
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default urls
|
export default urls
|
||||||
@@ -115,9 +115,9 @@ export default class form extends Component {
|
|||||||
</List.Item>
|
</List.Item>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<ModalForm title={`更新密码`} action={apiAction.updatePwd} ref={this.updatePwdForm}>
|
{/* <ModalForm title={`更新密码`} action={apiAction.updatePwd} ref={this.updatePwdForm}> */}
|
||||||
<PasswordForm loadData={loadData} />
|
<PasswordForm ref={this.updatePwdForm} loadData={loadData} />
|
||||||
</ModalForm>
|
{/* </ModalForm> */}
|
||||||
<Phone ref={this.mhoneForm} loadData={loadData} />
|
<Phone ref={this.mhoneForm} loadData={loadData} />
|
||||||
<Mail ref={this.mailForm} loadData={loadData} />
|
<Mail ref={this.mailForm} loadData={loadData} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,24 +1,68 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Form, Input } from 'antd'
|
import { Form, Input, message as Message, Modal } from 'antd'
|
||||||
|
import { api } from 'common/api'
|
||||||
|
import { RSA_PUBLIC_KEY } from 'util/global'
|
||||||
|
import { cloneDeep } from 'lodash'
|
||||||
|
import { Button } from 'antd/lib/radio'
|
||||||
|
import { encryptByRSA } from 'util/rsa'
|
||||||
|
|
||||||
|
const initData = {
|
||||||
|
exist: false,
|
||||||
|
pattern: '',
|
||||||
|
descriptions: '',
|
||||||
|
visible: false,
|
||||||
|
}
|
||||||
|
|
||||||
export default class form extends Component {
|
export default class form extends Component {
|
||||||
state = {
|
state = cloneDeep(initData)
|
||||||
// 加载状态
|
|
||||||
exist: false,
|
|
||||||
}
|
|
||||||
// 表单实例
|
// 表单实例
|
||||||
form = React.createRef()
|
form = React.createRef()
|
||||||
|
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
record = {}
|
record = {}
|
||||||
|
|
||||||
|
open = () => {
|
||||||
|
this.setState({ visible: true })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mount后回调
|
* mount后回调
|
||||||
*/
|
*/
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.created && this.props.created(this)
|
this.props.created && this.props.created(this)
|
||||||
|
api.getPwdRule({}).then(({ success, data, message }) => {
|
||||||
|
if (success) {
|
||||||
|
const { pattern, descriptions } = data
|
||||||
|
this.setState({
|
||||||
|
pattern,
|
||||||
|
descriptions,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Message.Error(message)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePwd(values) {
|
||||||
|
let { password, newPassword } = values.current.getFieldsValue()
|
||||||
|
password = encryptByRSA(password, RSA_PUBLIC_KEY)
|
||||||
|
newPassword = encryptByRSA(newPassword, RSA_PUBLIC_KEY)
|
||||||
|
const confirm = newPassword
|
||||||
|
api.sysUserUpdatePwd({ password, newPassword, confirm }).then(
|
||||||
|
({ success, data, message }) => {
|
||||||
|
if (success) {
|
||||||
|
Message.success('密码修改完成')
|
||||||
|
this.close()
|
||||||
|
} else {
|
||||||
|
Message.warn(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.setState(cloneDeep(initData))
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 填充数据
|
* 填充数据
|
||||||
* 可以在设置this.record之后对其作出数据结构调整
|
* 可以在设置this.record之后对其作出数据结构调整
|
||||||
@@ -46,42 +90,56 @@ export default class form extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { pattern, descriptions, visible } = this.state
|
||||||
return (
|
return (
|
||||||
<Form className="yo-form" ref={this.form}>
|
<Modal
|
||||||
<div className="yo-form-group">
|
destroyOnClose
|
||||||
<Form.Item
|
onCancel={() => this.close()}
|
||||||
label="旧密码"
|
onOk={() => this.updatePwd(this.form)}
|
||||||
rules={[{ required: true, message: '请输入旧密码' }]}
|
visible={visible}
|
||||||
name="password"
|
className="yo-modal-form"
|
||||||
>
|
title="更新密码"
|
||||||
<Input.Password autoComplete="off" placeholder="请输入旧密码" />
|
>
|
||||||
</Form.Item>
|
<Form className="yo-form" ref={this.form}>
|
||||||
<Form.Item
|
<div className="yo-form-group">
|
||||||
label="新密码"
|
<Form.Item
|
||||||
rules={[{ required: true, message: '请输入新密码' }]}
|
label="旧密码"
|
||||||
name="newPassword"
|
rules={[{ required: true, message: '请输入旧密码' }]}
|
||||||
>
|
name="password"
|
||||||
<Input.Password autoComplete="off" placeholder="请输入新密码" />
|
>
|
||||||
</Form.Item>
|
<Input.Password autoComplete="off" placeholder="请输入旧密码" />
|
||||||
<Form.Item
|
</Form.Item>
|
||||||
label="确认新密码"
|
<Form.Item
|
||||||
rules={[
|
label="新密码"
|
||||||
{ required: true, message: '请确认新密码' },
|
rules={[
|
||||||
({ getFieldValue }) => ({
|
{ required: true, message: '请输入新密码' },
|
||||||
validator(_, value) {
|
{ pattern, message: '密码格式错误' },
|
||||||
if (!value || getFieldValue('newPassword') === value) {
|
]}
|
||||||
return Promise.resolve()
|
name="newPassword"
|
||||||
}
|
tooltip={descriptions}
|
||||||
return Promise.reject(new Error('确认新密码不匹配'))
|
>
|
||||||
},
|
<Input.Password autoComplete="off" placeholder="请输入新密码" />
|
||||||
}),
|
</Form.Item>
|
||||||
]}
|
<Form.Item
|
||||||
name="confirm"
|
label="确认新密码"
|
||||||
>
|
rules={[
|
||||||
<Input.Password autoComplete="off" placeholder="请确认新密码" />
|
{ required: true, message: '请确认新密码' },
|
||||||
</Form.Item>
|
({ getFieldValue }) => ({
|
||||||
</div>
|
validator(_, value) {
|
||||||
</Form>
|
if (!value || getFieldValue('newPassword') === value) {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error('确认新密码不匹配'))
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]}
|
||||||
|
name="confirm"
|
||||||
|
>
|
||||||
|
<Input.Password autoComplete="off" placeholder="请确认新密码" />
|
||||||
|
</Form.Item>
|
||||||
|
</div>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user