新增加注册功能
This commit is contained in:
parent
c5e6cfd771
commit
429f12ef01
@ -19,6 +19,8 @@ using ZR.Service.System;
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using UAParser;
|
using UAParser;
|
||||||
using IPTools.Core;
|
using IPTools.Core;
|
||||||
|
using Infrastructure.Extensions;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace ZR.Admin.WebApi.Controllers.System
|
namespace ZR.Admin.WebApi.Controllers.System
|
||||||
{
|
{
|
||||||
@ -107,7 +109,7 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
var name = HttpContext.GetName();
|
var name = HttpContext.GetName();
|
||||||
|
|
||||||
CacheService.RemoveUserPerms(GlobalConstant.UserPermKEY + userid);
|
CacheService.RemoveUserPerms(GlobalConstant.UserPermKEY + userid);
|
||||||
return SUCCESS(new { name , id = userid });
|
return SUCCESS(new { name, id = userid });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -198,9 +200,41 @@ namespace ZR.Admin.WebApi.Controllers.System
|
|||||||
ipaddr = ipAddr,
|
ipaddr = ipAddr,
|
||||||
userName = context.GetName(),
|
userName = context.GetName(),
|
||||||
loginLocation = ip_info.Province + "-" + ip_info.City
|
loginLocation = ip_info.Province + "-" + ip_info.City
|
||||||
};
|
};
|
||||||
|
|
||||||
return sysLogininfor;
|
return sysLogininfor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("/register")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[Log(Title = "注册", BusinessType = Infrastructure.Enums.BusinessType.INSERT)]
|
||||||
|
public IActionResult Register([FromBody] RegisterDto dto)
|
||||||
|
{
|
||||||
|
SysConfig config = sysConfigService.GetSysConfigByKey("sys.account.register");
|
||||||
|
if (config?.ConfigValue != "true")
|
||||||
|
{
|
||||||
|
return ToResponse(ResultCode.CUSTOM_ERROR, "当前系统没有开启注册功能!");
|
||||||
|
}
|
||||||
|
SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff");
|
||||||
|
if (sysConfig?.ConfigValue != "off" && CacheHelper.Get(dto.Uuid) is string str && !str.ToLower().Equals(dto.Code.ToLower()))
|
||||||
|
{
|
||||||
|
return ToResponse(ResultCode.CAPTCHA_ERROR, "验证码错误");
|
||||||
|
}
|
||||||
|
if (UserConstants.NOT_UNIQUE.Equals(sysUserService.CheckUserNameUnique(dto.Username)))
|
||||||
|
{
|
||||||
|
return ToResponse(ResultCode.CUSTOM_ERROR, $"保存用户{dto.Username}失败,注册账号已存在");
|
||||||
|
}
|
||||||
|
SysUser user = sysUserService.Register(dto);
|
||||||
|
if (user.UserId > 0)
|
||||||
|
{
|
||||||
|
return SUCCESS(user);
|
||||||
|
}
|
||||||
|
return ToResponse(ResultCode.CUSTOM_ERROR, "注册失败,请联系管理员");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -80,5 +80,38 @@ namespace ZR.Common
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计算密码强度
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="password">密码字符串</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool PasswordStrength(string password)
|
||||||
|
{
|
||||||
|
//空字符串强度值为0
|
||||||
|
if (string.IsNullOrEmpty(password)) return false;
|
||||||
|
|
||||||
|
//字符统计
|
||||||
|
int iNum = 0, iLtt = 0, iSym = 0;
|
||||||
|
foreach (char c in password)
|
||||||
|
{
|
||||||
|
if (c >= '0' && c <= '9') iNum++;
|
||||||
|
else if (c >= 'a' && c <= 'z') iLtt++;
|
||||||
|
else if (c >= 'A' && c <= 'Z') iLtt++;
|
||||||
|
else iSym++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iLtt == 0 && iSym == 0) return false; //纯数字密码
|
||||||
|
if (iNum == 0 && iLtt == 0) return false; //纯符号密码
|
||||||
|
if (iNum == 0 && iSym == 0) return false; //纯字母密码
|
||||||
|
|
||||||
|
if (password.Length >= 6 && password.Length < 16) return true;//长度不大于6的密码
|
||||||
|
|
||||||
|
if (iLtt == 0) return true; //数字和符号构成的密码
|
||||||
|
if (iSym == 0) return true; //数字和字母构成的密码
|
||||||
|
if (iNum == 0) return true; //字母和符号构成的密码
|
||||||
|
|
||||||
|
return true; //由数字、字母、符号构成的密码
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
ZR.Model/System/Dto/RegisterDto.cs
Normal file
33
ZR.Model/System/Dto/RegisterDto.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ZR.Model.System.Dto
|
||||||
|
{
|
||||||
|
public class RegisterDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 用户名
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "用户名不能为空")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 用户密码
|
||||||
|
/// </summary>
|
||||||
|
[Required(ErrorMessage = "密码不能为空")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
[Required(ErrorMessage = "确认密码不能为空")]
|
||||||
|
public string ConfirmPassword { get; set; }
|
||||||
|
/**
|
||||||
|
* 验证码
|
||||||
|
*/
|
||||||
|
public string Code { get; set; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一标识
|
||||||
|
*/
|
||||||
|
public string Uuid { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,12 @@ namespace ZR.Service.System.IService
|
|||||||
{
|
{
|
||||||
public interface ISysLoginService: IBaseService<SysLogininfor>
|
public interface ISysLoginService: IBaseService<SysLogininfor>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 登录
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="loginBody"></param>
|
||||||
|
/// <param name="logininfor"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public SysUser Login(LoginBodyDto loginBody, SysLogininfor logininfor);
|
public SysUser Login(LoginBodyDto loginBody, SysLogininfor logininfor);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,11 +1,6 @@
|
|||||||
using System;
|
using ZR.Model;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ZR.Model;
|
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
using ZR.Repository;
|
using ZR.Model.System.Dto;
|
||||||
|
|
||||||
namespace ZR.Service.System.IService
|
namespace ZR.Service.System.IService
|
||||||
{
|
{
|
||||||
@ -66,5 +61,12 @@ namespace ZR.Service.System.IService
|
|||||||
/// <param name="user"></param>
|
/// <param name="user"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int UpdatePhoto(SysUser user);
|
public int UpdatePhoto(SysUser user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
SysUser Register(RegisterDto dto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
|
using Infrastructure;
|
||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using ZR.Common;
|
||||||
using ZR.Model;
|
using ZR.Model;
|
||||||
using ZR.Model.System;
|
using ZR.Model.System;
|
||||||
|
using ZR.Model.System.Dto;
|
||||||
using ZR.Repository.System;
|
using ZR.Repository.System;
|
||||||
using ZR.Service.System.IService;
|
using ZR.Service.System.IService;
|
||||||
|
|
||||||
@ -156,5 +160,34 @@ namespace ZR.Service
|
|||||||
{
|
{
|
||||||
return UserRepository.UpdatePhoto(user);
|
return UserRepository.UpdatePhoto(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册用户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SysUser Register(RegisterDto dto)
|
||||||
|
{
|
||||||
|
//密码md5
|
||||||
|
string password = NETCore.Encrypt.EncryptProvider.Md5(dto.Password);
|
||||||
|
if (!Tools.PasswordStrength(dto.Password))
|
||||||
|
{
|
||||||
|
throw new CustomException("密码强度不符合要求");
|
||||||
|
}
|
||||||
|
SysUser user = new()
|
||||||
|
{
|
||||||
|
Create_time = DateTime.Now,
|
||||||
|
UserName = dto.Username,
|
||||||
|
NickName = dto.Username,
|
||||||
|
Password = password,
|
||||||
|
Status = "0",
|
||||||
|
DeptId = 0,
|
||||||
|
Remark = "用户注册"
|
||||||
|
};
|
||||||
|
|
||||||
|
user.UserId = UserRepository.AddUser(user);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,9 +9,9 @@ export function login(username, password, code, uuid) {
|
|||||||
uuid
|
uuid
|
||||||
}
|
}
|
||||||
return request({
|
return request({
|
||||||
url: '/login',
|
url: '/login',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ export function getInfo() {
|
|||||||
// 退出方法
|
// 退出方法
|
||||||
export function logout() {
|
export function logout() {
|
||||||
return request({
|
return request({
|
||||||
url: '/LogOut',
|
url: '/LogOut',
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,3 +38,15 @@ export function getCodeImg() {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function register(data) {
|
||||||
|
return request({
|
||||||
|
url: '/register',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -38,6 +38,11 @@ export const constantRoutes = [{
|
|||||||
path: '/login',
|
path: '/login',
|
||||||
component: (resolve) => require(['@/views/login'], resolve),
|
component: (resolve) => require(['@/views/login'], resolve),
|
||||||
hidden: true
|
hidden: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/register',
|
||||||
|
component: (resolve) => require(['@/views/register'], resolve),
|
||||||
|
hidden: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/404',
|
path: '/404',
|
||||||
|
|||||||
@ -47,5 +47,6 @@ module.exports = {
|
|||||||
* The default is only used in the production env
|
* The default is only used in the production env
|
||||||
* If you want to also use it in dev, you can pass ['production', 'development']
|
* If you want to also use it in dev, you can pass ['production', 'development']
|
||||||
*/
|
*/
|
||||||
errorLog: 'production'
|
errorLog: 'production',
|
||||||
|
copyRight: 'Copyright ©2022 izhaorui.cn All Rights Reserved.'
|
||||||
}
|
}
|
||||||
@ -45,10 +45,13 @@ const user = {
|
|||||||
setToken(res.data)
|
setToken(res.data)
|
||||||
//提交上面的mutaions方法
|
//提交上面的mutaions方法
|
||||||
commit('SET_TOKEN', res.data)
|
commit('SET_TOKEN', res.data)
|
||||||
resolve()//then处理
|
resolve() //then处理
|
||||||
} else {
|
} else {
|
||||||
reject(res)//catch处理
|
console.log('login error ' + res);
|
||||||
|
reject(res) //catch处理
|
||||||
}
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
reject(err);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -69,7 +72,7 @@ const user = {
|
|||||||
|
|
||||||
commit('SET_NAME', data.user.nickName)
|
commit('SET_NAME', data.user.nickName)
|
||||||
commit('SET_AVATAR', avatar)
|
commit('SET_AVATAR', avatar)
|
||||||
commit('SET_USERINFO', data.user)//新加
|
commit('SET_USERINFO', data.user) //新加
|
||||||
resolve(res)
|
resolve(res)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
@ -79,10 +82,10 @@ const user = {
|
|||||||
|
|
||||||
// 退出系统
|
// 退出系统
|
||||||
LogOut({ commit, state }) {
|
LogOut({ commit, state }) {
|
||||||
console.log('退出登录')
|
console.log('退出登录')
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
logout().then((res) => {
|
logout().then((res) => {
|
||||||
removeToken()// 必须先移除token
|
removeToken() // 必须先移除token
|
||||||
commit('SET_TOKEN', '')
|
commit('SET_TOKEN', '')
|
||||||
commit('SET_ROLES', [])
|
commit('SET_ROLES', [])
|
||||||
commit('SET_PERMISSIONS', [])
|
commit('SET_PERMISSIONS', [])
|
||||||
|
|||||||
@ -57,7 +57,7 @@ service.interceptors.response.use(res => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 403 || code == 500 || code == 429) {
|
} else if (code == 0 || code == 1 || code == 110 || code == 101 || code == 103 || code == 403 || code == 500 || code == 429) {
|
||||||
Message({
|
Message({
|
||||||
message: msg,
|
message: msg,
|
||||||
type: 'error'
|
type: 'error'
|
||||||
|
|||||||
@ -26,122 +26,126 @@
|
|||||||
<span v-if="!loading">登 录</span>
|
<span v-if="!loading">登 录</span>
|
||||||
<span v-else>登 录 中...</span>
|
<span v-else>登 录 中...</span>
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<div style="float: right;">
|
||||||
|
<router-link class="link-type" :to="'/register'">还没有账号?立即注册</router-link>
|
||||||
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<!-- 底部 -->
|
<!-- 底部 -->
|
||||||
<div class="el-login-footer">
|
<div class="el-login-footer">
|
||||||
<span>Copyright ©2021 izhaorui.cn All Rights Reserved.</span>
|
<span>{{copyRight}}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from "@/api/system/login";
|
import { getCodeImg } from '@/api/system/login'
|
||||||
import Cookies from "js-cookie";
|
import Cookies from 'js-cookie'
|
||||||
// import { encrypt, decrypt } from "@/utils/jsencrypt";
|
import defaultSettings from '@/settings'
|
||||||
import defaultSettings from "@/settings";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: 'Login',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
codeUrl: "",
|
codeUrl: '',
|
||||||
cookiePassword: "",
|
cookiePassword: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: "",
|
username: '',
|
||||||
password: "",
|
password: '',
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
code: "",
|
code: '',
|
||||||
uuid: "",
|
uuid: ''
|
||||||
},
|
},
|
||||||
title: defaultSettings.title,
|
title: defaultSettings.title,
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [
|
username: [
|
||||||
{ required: true, trigger: "blur", message: "用户名不能为空" },
|
{ required: true, trigger: 'blur', message: '用户名不能为空' }
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, trigger: "blur", message: "密码不能为空" },
|
{ required: true, trigger: 'blur', message: '密码不能为空' }
|
||||||
],
|
|
||||||
code: [
|
|
||||||
{ required: true, trigger: "change", message: "验证码不能为空" },
|
|
||||||
],
|
],
|
||||||
|
code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
|
||||||
},
|
},
|
||||||
showCaptcha: '',
|
showCaptcha: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
redirect: undefined,
|
redirect: undefined
|
||||||
};
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
copyRight: function() {
|
||||||
|
return defaultSettings.copyRight
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route: {
|
$route: {
|
||||||
handler: function (route) {
|
handler: function(route) {
|
||||||
this.redirect = route.query && route.query.redirect;
|
this.redirect = route.query && route.query.redirect
|
||||||
},
|
},
|
||||||
immediate: true,
|
immediate: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCode();
|
this.getCode()
|
||||||
this.getCookie();
|
this.getCookie()
|
||||||
this.getConfigKey("sys.account.captchaOnOff").then((response) => {
|
this.getConfigKey('sys.account.captchaOnOff').then((response) => {
|
||||||
this.showCaptcha = response.data;
|
this.showCaptcha = response.data
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
getCode() {
|
||||||
// this.loginForm.code = "";
|
// this.loginForm.code = "";
|
||||||
getCodeImg().then((res) => {
|
getCodeImg().then((res) => {
|
||||||
this.codeUrl = "data:image/gif;base64," + res.data.img;
|
this.codeUrl = 'data:image/gif;base64,' + res.data.img
|
||||||
this.loginForm.uuid = res.data.uuid;
|
this.loginForm.uuid = res.data.uuid
|
||||||
this.$forceUpdate();
|
this.$forceUpdate()
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
getCookie() {
|
getCookie() {
|
||||||
const username = Cookies.get("username");
|
const username = Cookies.get('username')
|
||||||
const password = Cookies.get("password");
|
const password = Cookies.get('password')
|
||||||
const rememberMe = Cookies.get("rememberMe");
|
const rememberMe = Cookies.get('rememberMe')
|
||||||
|
|
||||||
this.loginForm = {
|
this.loginForm = {
|
||||||
username: username === undefined ? this.loginForm.username : username,
|
username: username === undefined ? this.loginForm.username : username,
|
||||||
password: password === undefined ? this.loginForm.password : password,
|
password: password === undefined ? this.loginForm.password : password,
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
||||||
};
|
}
|
||||||
},
|
},
|
||||||
handleLogin() {
|
handleLogin() {
|
||||||
this.$refs.loginForm.validate((valid) => {
|
this.$refs.loginForm.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true;
|
this.loading = true
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
Cookies.set('username', this.loginForm.username, { expires: 30 })
|
||||||
Cookies.set("password", this.loginForm.password, {
|
Cookies.set('password', this.loginForm.password, {
|
||||||
expires: 30,
|
expires: 30
|
||||||
});
|
})
|
||||||
Cookies.set("rememberMe", this.loginForm.rememberMe, {
|
Cookies.set('rememberMe', this.loginForm.rememberMe, {
|
||||||
expires: 30,
|
expires: 30
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove("username");
|
Cookies.remove('username')
|
||||||
Cookies.remove("password");
|
Cookies.remove('password')
|
||||||
Cookies.remove("rememberMe");
|
Cookies.remove('rememberMe')
|
||||||
}
|
}
|
||||||
this.$store
|
this.$store
|
||||||
.dispatch("Login", this.loginForm)
|
.dispatch('Login', this.loginForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.msgSuccess("登录成功");
|
this.msgSuccess('登录成功')
|
||||||
this.$router.push({ path: this.redirect || "/" });
|
this.$router.push({ path: this.redirect || '/' })
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.loading = false
|
||||||
|
this.getCode()
|
||||||
|
this.$refs.codeTxt.focus()
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
|
||||||
this.$message(error.msg);
|
|
||||||
this.loading = false;
|
|
||||||
this.getCode();
|
|
||||||
this.$refs.codeTxt.focus();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
console.log("未完成");
|
console.log('未完成')
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
},
|
}
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped rel="stylesheet/scss" lang="scss">
|
<style scoped rel="stylesheet/scss" lang="scss">
|
||||||
|
|||||||
214
ZR.Vue/src/views/register.vue
Normal file
214
ZR.Vue/src/views/register.vue
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
<template>
|
||||||
|
<div class="register">
|
||||||
|
<el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form">
|
||||||
|
<h3 class="title">{{title}}</h3>
|
||||||
|
<el-form-item prop="username">
|
||||||
|
<el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号">
|
||||||
|
<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="password">
|
||||||
|
<el-input v-model="registerForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleRegister">
|
||||||
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="confirmPassword">
|
||||||
|
<el-input v-model="registerForm.confirmPassword" type="password" auto-complete="off" placeholder="确认密码" @keyup.enter.native="handleRegister">
|
||||||
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||||
|
</el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item prop="code" v-if="captchaOnOff">
|
||||||
|
<el-input v-model="registerForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleRegister">
|
||||||
|
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
||||||
|
</el-input>
|
||||||
|
<div class="register-code">
|
||||||
|
<img :src="codeUrl" @click="getCode" class="register-code-img" />
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item style="width:100%;">
|
||||||
|
<el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleRegister">
|
||||||
|
<span v-if="!loading">注 册</span>
|
||||||
|
<span v-else>注 册 中...</span>
|
||||||
|
</el-button>
|
||||||
|
<div style="float: right;">
|
||||||
|
<router-link class="link-type" :to="'/login'">使用已有账户登录</router-link>
|
||||||
|
</div>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<!-- 底部 -->
|
||||||
|
<div class="el-register-footer">
|
||||||
|
<span>{{copyRight}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getCodeImg, register } from '@/api/system/login'
|
||||||
|
import defaultSettings from '@/settings'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'Register',
|
||||||
|
data() {
|
||||||
|
const equalToPassword = (rule, value, callback) => {
|
||||||
|
if (this.registerForm.password !== value) {
|
||||||
|
callback(new Error('两次输入的密码不一致'))
|
||||||
|
} else {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
codeUrl: '',
|
||||||
|
registerForm: {
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
code: '',
|
||||||
|
uuid: ''
|
||||||
|
},
|
||||||
|
registerRules: {
|
||||||
|
username: [
|
||||||
|
{ required: true, trigger: 'blur', message: '请输入您的账号' },
|
||||||
|
{
|
||||||
|
min: 2,
|
||||||
|
max: 20,
|
||||||
|
message: '用户账号长度必须介于 2 和 20 之间',
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
password: [
|
||||||
|
{ required: true, trigger: 'blur', message: '请输入您的密码' },
|
||||||
|
{
|
||||||
|
min: 5,
|
||||||
|
max: 20,
|
||||||
|
message: '用户密码长度必须介于 6 和 20 之间',
|
||||||
|
trigger: 'blur'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
confirmPassword: [
|
||||||
|
{ required: true, trigger: 'blur', message: '请再次输入您的密码' },
|
||||||
|
{ required: true, validator: equalToPassword, trigger: 'blur' }
|
||||||
|
],
|
||||||
|
code: [{ required: true, trigger: 'change', message: '请输入验证码' }]
|
||||||
|
},
|
||||||
|
loading: false,
|
||||||
|
captchaOnOff: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
copyRight: function() {
|
||||||
|
return defaultSettings.copyRight
|
||||||
|
},
|
||||||
|
title: function() {
|
||||||
|
return defaultSettings.title
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getCode()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getCode() {
|
||||||
|
getCodeImg().then((res) => {
|
||||||
|
this.codeUrl = 'data:image/gif;base64,' + res.data.img
|
||||||
|
this.registerForm.uuid = res.data.uuid
|
||||||
|
this.$forceUpdate()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
handleRegister() {
|
||||||
|
this.$refs.registerForm.validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
this.loading = true
|
||||||
|
register(this.registerForm)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.code == 200) {
|
||||||
|
const username = this.registerForm.username
|
||||||
|
this.$alert(
|
||||||
|
"<font color='red'>恭喜你,您的账号 " +
|
||||||
|
username +
|
||||||
|
' 注册成功!</font>',
|
||||||
|
'系统提示',
|
||||||
|
{
|
||||||
|
dangerouslyUseHTMLString: true,
|
||||||
|
type: 'success'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
this.$router.push('/login')
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.loading = false
|
||||||
|
if (this.captchaOnOff) {
|
||||||
|
this.getCode()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style rel="stylesheet/scss" lang="scss">
|
||||||
|
.register {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
background-image: url("../assets/image/login-background.jpg");
|
||||||
|
background-size: cover;
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
margin: 0px auto 30px auto;
|
||||||
|
text-align: center;
|
||||||
|
color: #707070;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-form {
|
||||||
|
border-radius: 6px;
|
||||||
|
background: rgba(255, 255, 255, 0.3);
|
||||||
|
width: 310px;
|
||||||
|
padding: 25px 25px 5px 25px;
|
||||||
|
.el-input {
|
||||||
|
height: 38px;
|
||||||
|
input {
|
||||||
|
height: 38px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.input-icon {
|
||||||
|
height: 39px;
|
||||||
|
width: 14px;
|
||||||
|
margin-left: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.register-tip {
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: center;
|
||||||
|
color: #bfbfbf;
|
||||||
|
}
|
||||||
|
.register-code {
|
||||||
|
width: 33%;
|
||||||
|
height: 38px;
|
||||||
|
float: right;
|
||||||
|
img {
|
||||||
|
cursor: pointer;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.el-register-footer {
|
||||||
|
height: 40px;
|
||||||
|
line-height: 40px;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
color: #fff;
|
||||||
|
font-family: Arial;
|
||||||
|
font-size: 12px;
|
||||||
|
letter-spacing: 1px;
|
||||||
|
}
|
||||||
|
.register-code-img {
|
||||||
|
height: 38px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -680,6 +680,7 @@ insert into sys_config values(2, '用户管理-账号初始密码', 'sys
|
|||||||
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
||||||
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能(off、关闭,1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码)');
|
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能(off、关闭,1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码)');
|
||||||
INSERT INTO `sys_config`(`configId`, `configName`, `configKey`, `configValue`, `configType`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (5, '本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', '', '2022-04-10 10:11:27', '', NULL, NULL);
|
INSERT INTO `sys_config`(`configId`, `configName`, `configKey`, `configValue`, `configType`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (5, '本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', '', '2022-04-10 10:11:27', '', NULL, NULL);
|
||||||
|
INSERT INTO `sys_config`(`configId`, `configName`, `configKey`, `configValue`, `configType`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (6, '开启注册功能', 'sys.account.register', 'true', 'Y', 'admin', '2022-04-14 00:00:00', 'admin', NULL, NULL);
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- 18、代码生成业务表
|
-- 18、代码生成业务表
|
||||||
|
|||||||
@ -698,6 +698,7 @@ insert into sys_config values('用户管理-账号初始密码', 'sys.us
|
|||||||
insert into sys_config values('主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', GETDATE(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
insert into sys_config values('主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', GETDATE(), '', null, '深色主题theme-dark,浅色主题theme-light' );
|
||||||
insert into sys_config values('账号自助-验证码开关', 'sys.account.captchaOnOff', '1', 'Y', 'admin', GETDATE(), '', null, '开启验证码功能(off、关闭,1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码)');
|
insert into sys_config values('账号自助-验证码开关', 'sys.account.captchaOnOff', '1', 'Y', 'admin', GETDATE(), '', null, '开启验证码功能(off、关闭,1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码)');
|
||||||
INSERT INTO sys_config VALUES('本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', 'admin', GETDATE(), '', NULL, NULL);
|
INSERT INTO sys_config VALUES('本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', 'admin', GETDATE(), '', NULL, NULL);
|
||||||
|
INSERT INTO sys_config VALUES('开启注册功能', 'sys.account.register', 'true', 'Y', 'admin', GETDATE(), '', NULL, NULL);
|
||||||
|
|
||||||
GO
|
GO
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user