正在显示
16 个修改的文件
包含
451 行增加
和
16 行删除
| 1 | +package com.ruoyi.web.controller.system; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.util.StringUtils; | ||
| 5 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 6 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 7 | +import org.springframework.web.bind.annotation.RestController; | ||
| 8 | +import com.ruoyi.common.core.controller.BaseController; | ||
| 9 | +import com.ruoyi.common.core.domain.AjaxResult; | ||
| 10 | +import com.ruoyi.common.core.domain.model.RegisterBody; | ||
| 11 | +import com.ruoyi.framework.web.service.SysRegisterService; | ||
| 12 | +import com.ruoyi.system.service.ISysConfigService; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * 注册验证 | ||
| 16 | + * | ||
| 17 | + * @author ruoyi | ||
| 18 | + */ | ||
| 19 | +@RestController | ||
| 20 | +public class SysRegisterController extends BaseController | ||
| 21 | +{ | ||
| 22 | + @Autowired | ||
| 23 | + private SysRegisterService registerService; | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + private ISysConfigService configService; | ||
| 27 | + | ||
| 28 | + @PostMapping("/register") | ||
| 29 | + public AjaxResult register(@RequestBody RegisterBody user) | ||
| 30 | + { | ||
| 31 | + if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) | ||
| 32 | + { | ||
| 33 | + return error("当前系统没有开启注册功能!"); | ||
| 34 | + } | ||
| 35 | + String msg = registerService.register(user); | ||
| 36 | + return StringUtils.isEmpty(msg) ? success() : error(msg); | ||
| 37 | + } | ||
| 38 | +} |
| @@ -19,6 +19,7 @@ user.password.not.valid=* 5-50个字符 | @@ -19,6 +19,7 @@ user.password.not.valid=* 5-50个字符 | ||
| 19 | user.email.not.valid=邮箱格式错误 | 19 | user.email.not.valid=邮箱格式错误 |
| 20 | user.mobile.phone.number.not.valid=手机号格式错误 | 20 | user.mobile.phone.number.not.valid=手机号格式错误 |
| 21 | user.login.success=登录成功 | 21 | user.login.success=登录成功 |
| 22 | +user.register.success=注册成功 | ||
| 22 | user.notfound=请重新登录 | 23 | user.notfound=请重新登录 |
| 23 | user.forcelogout=管理员强制退出,请重新登录 | 24 | user.forcelogout=管理员强制退出,请重新登录 |
| 24 | user.unknown.error=未知错误,请重新登录 | 25 | user.unknown.error=未知错误,请重新登录 |
| 1 | package com.ruoyi.common.constant; | 1 | package com.ruoyi.common.constant; |
| 2 | 2 | ||
| 3 | +import io.jsonwebtoken.Claims; | ||
| 4 | + | ||
| 3 | /** | 5 | /** |
| 4 | * 通用常量信息 | 6 | * 通用常量信息 |
| 5 | * | 7 | * |
| @@ -48,6 +50,11 @@ public class Constants | @@ -48,6 +50,11 @@ public class Constants | ||
| 48 | public static final String LOGOUT = "Logout"; | 50 | public static final String LOGOUT = "Logout"; |
| 49 | 51 | ||
| 50 | /** | 52 | /** |
| 53 | + * 注册 | ||
| 54 | + */ | ||
| 55 | + public static final String REGISTER = "Register"; | ||
| 56 | + | ||
| 57 | + /** | ||
| 51 | * 登录失败 | 58 | * 登录失败 |
| 52 | */ | 59 | */ |
| 53 | public static final String LOGIN_FAIL = "Error"; | 60 | public static final String LOGIN_FAIL = "Error"; |
| @@ -95,7 +102,7 @@ public class Constants | @@ -95,7 +102,7 @@ public class Constants | ||
| 95 | /** | 102 | /** |
| 96 | * 用户名称 | 103 | * 用户名称 |
| 97 | */ | 104 | */ |
| 98 | - public static final String JWT_USERNAME = "sub"; | 105 | + public static final String JWT_USERNAME = Claims.SUBJECT; |
| 99 | 106 | ||
| 100 | /** | 107 | /** |
| 101 | * 用户头像 | 108 | * 用户头像 |
| @@ -53,7 +53,7 @@ public class UserConstants | @@ -53,7 +53,7 @@ public class UserConstants | ||
| 53 | 53 | ||
| 54 | /** Layout组件标识 */ | 54 | /** Layout组件标识 */ |
| 55 | public final static String LAYOUT = "Layout"; | 55 | public final static String LAYOUT = "Layout"; |
| 56 | - | 56 | + |
| 57 | /** ParentView组件标识 */ | 57 | /** ParentView组件标识 */ |
| 58 | public final static String PARENT_VIEW = "ParentView"; | 58 | public final static String PARENT_VIEW = "ParentView"; |
| 59 | 59 | ||
| @@ -63,4 +63,16 @@ public class UserConstants | @@ -63,4 +63,16 @@ public class UserConstants | ||
| 63 | /** 校验返回结果码 */ | 63 | /** 校验返回结果码 */ |
| 64 | public final static String UNIQUE = "0"; | 64 | public final static String UNIQUE = "0"; |
| 65 | public final static String NOT_UNIQUE = "1"; | 65 | public final static String NOT_UNIQUE = "1"; |
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 用户名长度限制 | ||
| 69 | + */ | ||
| 70 | + public static final int USERNAME_MIN_LENGTH = 2; | ||
| 71 | + public static final int USERNAME_MAX_LENGTH = 20; | ||
| 72 | + | ||
| 73 | + /** | ||
| 74 | + * 密码长度限制 | ||
| 75 | + */ | ||
| 76 | + public static final int PASSWORD_MIN_LENGTH = 5; | ||
| 77 | + public static final int PASSWORD_MAX_LENGTH = 20; | ||
| 66 | } | 78 | } |
| @@ -49,7 +49,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -49,7 +49,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 49 | */ | 49 | */ |
| 50 | @Autowired | 50 | @Autowired |
| 51 | private JwtAuthenticationTokenFilter authenticationTokenFilter; | 51 | private JwtAuthenticationTokenFilter authenticationTokenFilter; |
| 52 | - | 52 | + |
| 53 | /** | 53 | /** |
| 54 | * 跨域过滤器 | 54 | * 跨域过滤器 |
| 55 | */ | 55 | */ |
| @@ -96,8 +96,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -96,8 +96,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 96 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() | 96 | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() |
| 97 | // 过滤请求 | 97 | // 过滤请求 |
| 98 | .authorizeRequests() | 98 | .authorizeRequests() |
| 99 | - // 对于登录login 验证码captchaImage 允许匿名访问 | ||
| 100 | - .antMatchers("/login", "/captchaImage").anonymous() | 99 | + // 对于登录login 注册register 验证码captchaImage 允许匿名访问 |
| 100 | + .antMatchers("/login", "/register", "/captchaImage").anonymous() | ||
| 101 | .antMatchers( | 101 | .antMatchers( |
| 102 | HttpMethod.GET, | 102 | HttpMethod.GET, |
| 103 | "/", | 103 | "/", |
| @@ -126,7 +126,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | @@ -126,7 +126,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter | ||
| 126 | httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); | 126 | httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | - | ||
| 130 | /** | 129 | /** |
| 131 | * 强散列哈希加密实现 | 130 | * 强散列哈希加密实现 |
| 132 | */ | 131 | */ |
| @@ -65,7 +65,7 @@ public class AsyncFactory | @@ -65,7 +65,7 @@ public class AsyncFactory | ||
| 65 | logininfor.setOs(os); | 65 | logininfor.setOs(os); |
| 66 | logininfor.setMsg(message); | 66 | logininfor.setMsg(message); |
| 67 | // 日志状态 | 67 | // 日志状态 |
| 68 | - if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status)) | 68 | + if (StringUtils.equalsAny(status, Constants.LOGIN_SUCCESS, Constants.LOGOUT, Constants.REGISTER)) |
| 69 | { | 69 | { |
| 70 | logininfor.setStatus(Constants.SUCCESS); | 70 | logininfor.setStatus(Constants.SUCCESS); |
| 71 | } | 71 | } |
| 1 | +package com.ruoyi.framework.web.service; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.stereotype.Component; | ||
| 5 | +import org.springframework.util.StringUtils; | ||
| 6 | +import com.ruoyi.common.constant.Constants; | ||
| 7 | +import com.ruoyi.common.constant.UserConstants; | ||
| 8 | +import com.ruoyi.common.core.domain.entity.SysUser; | ||
| 9 | +import com.ruoyi.common.core.domain.model.RegisterBody; | ||
| 10 | +import com.ruoyi.common.core.redis.RedisCache; | ||
| 11 | +import com.ruoyi.common.exception.user.CaptchaException; | ||
| 12 | +import com.ruoyi.common.exception.user.CaptchaExpireException; | ||
| 13 | +import com.ruoyi.common.utils.MessageUtils; | ||
| 14 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 15 | +import com.ruoyi.framework.manager.AsyncManager; | ||
| 16 | +import com.ruoyi.framework.manager.factory.AsyncFactory; | ||
| 17 | +import com.ruoyi.system.service.ISysConfigService; | ||
| 18 | +import com.ruoyi.system.service.ISysUserService; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 注册校验方法 | ||
| 22 | + * | ||
| 23 | + * @author ruoyi | ||
| 24 | + */ | ||
| 25 | +@Component | ||
| 26 | +public class SysRegisterService | ||
| 27 | +{ | ||
| 28 | + @Autowired | ||
| 29 | + private ISysUserService userService; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private ISysConfigService configService; | ||
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + private RedisCache redisCache; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 注册 | ||
| 39 | + */ | ||
| 40 | + public String register(RegisterBody registerBody) | ||
| 41 | + { | ||
| 42 | + String msg = "", username = registerBody.getUsername(), password = registerBody.getPassword(); | ||
| 43 | + | ||
| 44 | + boolean captchaOnOff = configService.selectCaptchaOnOff(); | ||
| 45 | + // 验证码开关 | ||
| 46 | + if (captchaOnOff) | ||
| 47 | + { | ||
| 48 | + validateCaptcha(username, registerBody.getCode(), registerBody.getUuid()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + if (StringUtils.isEmpty(username)) | ||
| 52 | + { | ||
| 53 | + msg = "用户名不能为空"; | ||
| 54 | + } | ||
| 55 | + else if (StringUtils.isEmpty(password)) | ||
| 56 | + { | ||
| 57 | + msg = "用户密码不能为空"; | ||
| 58 | + } | ||
| 59 | + else if (username.length() < UserConstants.USERNAME_MIN_LENGTH | ||
| 60 | + || username.length() > UserConstants.USERNAME_MAX_LENGTH) | ||
| 61 | + { | ||
| 62 | + msg = "账户长度必须在2到20个字符之间"; | ||
| 63 | + } | ||
| 64 | + else if (password.length() < UserConstants.PASSWORD_MIN_LENGTH | ||
| 65 | + || password.length() > UserConstants.PASSWORD_MAX_LENGTH) | ||
| 66 | + { | ||
| 67 | + msg = "密码长度必须在5到20个字符之间"; | ||
| 68 | + } | ||
| 69 | + else if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) | ||
| 70 | + { | ||
| 71 | + msg = "保存用户'" + username + "'失败,注册账号已存在"; | ||
| 72 | + } | ||
| 73 | + else | ||
| 74 | + { | ||
| 75 | + SysUser sysUser = new SysUser(); | ||
| 76 | + sysUser.setUserName(username); | ||
| 77 | + sysUser.setNickName(username); | ||
| 78 | + sysUser.setPassword(SecurityUtils.encryptPassword(registerBody.getPassword())); | ||
| 79 | + boolean regFlag = userService.registerUser(sysUser); | ||
| 80 | + if (!regFlag) | ||
| 81 | + { | ||
| 82 | + msg = "注册失败,请联系系统管理人员"; | ||
| 83 | + } | ||
| 84 | + else | ||
| 85 | + { | ||
| 86 | + AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.REGISTER, | ||
| 87 | + MessageUtils.message("user.register.success"))); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + return msg; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 校验验证码 | ||
| 95 | + * | ||
| 96 | + * @param username 用户名 | ||
| 97 | + * @param code 验证码 | ||
| 98 | + * @param uuid 唯一标识 | ||
| 99 | + * @return 结果 | ||
| 100 | + */ | ||
| 101 | + public void validateCaptcha(String username, String code, String uuid) | ||
| 102 | + { | ||
| 103 | + String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; | ||
| 104 | + String captcha = redisCache.getCacheObject(verifyKey); | ||
| 105 | + redisCache.deleteObject(verifyKey); | ||
| 106 | + if (captcha == null) | ||
| 107 | + { | ||
| 108 | + throw new CaptchaExpireException(); | ||
| 109 | + } | ||
| 110 | + if (!code.equalsIgnoreCase(captcha)) | ||
| 111 | + { | ||
| 112 | + throw new CaptchaException(); | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | +} |
| @@ -106,13 +106,21 @@ public interface ISysUserService | @@ -106,13 +106,21 @@ public interface ISysUserService | ||
| 106 | public int insertUser(SysUser user); | 106 | public int insertUser(SysUser user); |
| 107 | 107 | ||
| 108 | /** | 108 | /** |
| 109 | + * 注册用户信息 | ||
| 110 | + * | ||
| 111 | + * @param user 用户信息 | ||
| 112 | + * @return 结果 | ||
| 113 | + */ | ||
| 114 | + public boolean registerUser(SysUser user); | ||
| 115 | + | ||
| 116 | + /** | ||
| 109 | * 修改用户信息 | 117 | * 修改用户信息 |
| 110 | * | 118 | * |
| 111 | * @param user 用户信息 | 119 | * @param user 用户信息 |
| 112 | * @return 结果 | 120 | * @return 结果 |
| 113 | */ | 121 | */ |
| 114 | public int updateUser(SysUser user); | 122 | public int updateUser(SysUser user); |
| 115 | - | 123 | + |
| 116 | /** | 124 | /** |
| 117 | * 用户授权角色 | 125 | * 用户授权角色 |
| 118 | * | 126 | * |
| @@ -247,6 +247,17 @@ public class SysUserServiceImpl implements ISysUserService | @@ -247,6 +247,17 @@ public class SysUserServiceImpl implements ISysUserService | ||
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | /** | 249 | /** |
| 250 | + * 注册用户信息 | ||
| 251 | + * | ||
| 252 | + * @param user 用户信息 | ||
| 253 | + * @return 结果 | ||
| 254 | + */ | ||
| 255 | + public boolean registerUser(SysUser user) | ||
| 256 | + { | ||
| 257 | + return userMapper.insertUser(user) > 0; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /** | ||
| 250 | * 修改保存用户信息 | 261 | * 修改保存用户信息 |
| 251 | * | 262 | * |
| 252 | * @param user 用户信息 | 263 | * @param user 用户信息 |
| @@ -15,6 +15,18 @@ export function login(username, password, code, uuid) { | @@ -15,6 +15,18 @@ export function login(username, password, code, uuid) { | ||
| 15 | }) | 15 | }) |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | +// 注册方法 | ||
| 19 | +export function register(data) { | ||
| 20 | + return request({ | ||
| 21 | + url: '/register', | ||
| 22 | + headers: { | ||
| 23 | + isToken: false | ||
| 24 | + }, | ||
| 25 | + method: 'post', | ||
| 26 | + data: data | ||
| 27 | + }) | ||
| 28 | +} | ||
| 29 | + | ||
| 18 | // 获取用户详细信息 | 30 | // 获取用户详细信息 |
| 19 | export function getInfo() { | 31 | export function getInfo() { |
| 20 | return request({ | 32 | return request({ |
| @@ -44,6 +44,11 @@ export const constantRoutes = [ | @@ -44,6 +44,11 @@ export const constantRoutes = [ | ||
| 44 | hidden: true | 44 | hidden: true |
| 45 | }, | 45 | }, |
| 46 | { | 46 | { |
| 47 | + path: '/register', | ||
| 48 | + component: (resolve) => require(['@/views/register'], resolve), | ||
| 49 | + hidden: true | ||
| 50 | + }, | ||
| 51 | + { | ||
| 47 | path: '/404', | 52 | path: '/404', |
| 48 | component: (resolve) => require(['@/views/error/404'], resolve), | 53 | component: (resolve) => require(['@/views/error/404'], resolve), |
| 49 | hidden: true | 54 | hidden: true |
| @@ -44,6 +44,9 @@ | @@ -44,6 +44,9 @@ | ||
| 44 | <span v-if="!loading">登 录</span> | 44 | <span v-if="!loading">登 录</span> |
| 45 | <span v-else>登 录 中...</span> | 45 | <span v-else>登 录 中...</span> |
| 46 | </el-button> | 46 | </el-button> |
| 47 | + <div style="float: right;" v-if="register"> | ||
| 48 | + <router-link class="link-type" :to="'/register'">立即注册</router-link> | ||
| 49 | + </div> | ||
| 47 | </el-form-item> | 50 | </el-form-item> |
| 48 | </el-form> | 51 | </el-form> |
| 49 | <!-- 底部 --> | 52 | <!-- 底部 --> |
| @@ -73,15 +76,18 @@ export default { | @@ -73,15 +76,18 @@ export default { | ||
| 73 | }, | 76 | }, |
| 74 | loginRules: { | 77 | loginRules: { |
| 75 | username: [ | 78 | username: [ |
| 76 | - { required: true, trigger: "blur", message: "用户名不能为空" } | 79 | + { required: true, trigger: "blur", message: "请输入您的账号" } |
| 77 | ], | 80 | ], |
| 78 | password: [ | 81 | password: [ |
| 79 | - { required: true, trigger: "blur", message: "密码不能为空" } | 82 | + { required: true, trigger: "blur", message: "请输入您的密码" } |
| 80 | ], | 83 | ], |
| 81 | - code: [{ required: true, trigger: "change", message: "验证码不能为空" }] | 84 | + code: [{ required: true, trigger: "change", message: "请输入验证码" }] |
| 82 | }, | 85 | }, |
| 83 | loading: false, | 86 | loading: false, |
| 87 | + // 验证码开关 | ||
| 84 | captchaOnOff: true, | 88 | captchaOnOff: true, |
| 89 | + // 注册开关 | ||
| 90 | + register: false, | ||
| 85 | redirect: undefined | 91 | redirect: undefined |
| 86 | }; | 92 | }; |
| 87 | }, | 93 | }, |
ruoyi-ui/src/views/register.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="register"> | ||
| 3 | + <el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form"> | ||
| 4 | + <h3 class="title">若依后台管理系统</h3> | ||
| 5 | + <el-form-item prop="username"> | ||
| 6 | + <el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号"> | ||
| 7 | + <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> | ||
| 8 | + </el-input> | ||
| 9 | + </el-form-item> | ||
| 10 | + <el-form-item prop="password"> | ||
| 11 | + <el-input | ||
| 12 | + v-model="registerForm.password" | ||
| 13 | + type="password" | ||
| 14 | + auto-complete="off" | ||
| 15 | + placeholder="密码" | ||
| 16 | + @keyup.enter.native="handleRegister" | ||
| 17 | + > | ||
| 18 | + <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | ||
| 19 | + </el-input> | ||
| 20 | + </el-form-item> | ||
| 21 | + <el-form-item prop="confirmPassword"> | ||
| 22 | + <el-input | ||
| 23 | + v-model="registerForm.confirmPassword" | ||
| 24 | + type="password" | ||
| 25 | + auto-complete="off" | ||
| 26 | + placeholder="确认密码" | ||
| 27 | + @keyup.enter.native="handleRegister" | ||
| 28 | + > | ||
| 29 | + <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | ||
| 30 | + </el-input> | ||
| 31 | + </el-form-item> | ||
| 32 | + <el-form-item prop="code" v-if="captchaOnOff"> | ||
| 33 | + <el-input | ||
| 34 | + v-model="registerForm.code" | ||
| 35 | + auto-complete="off" | ||
| 36 | + placeholder="验证码" | ||
| 37 | + style="width: 63%" | ||
| 38 | + @keyup.enter.native="handleRegister" | ||
| 39 | + > | ||
| 40 | + <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> | ||
| 41 | + </el-input> | ||
| 42 | + <div class="register-code"> | ||
| 43 | + <img :src="codeUrl" @click="getCode" class="register-code-img"/> | ||
| 44 | + </div> | ||
| 45 | + </el-form-item> | ||
| 46 | + <el-form-item style="width:100%;"> | ||
| 47 | + <el-button | ||
| 48 | + :loading="loading" | ||
| 49 | + size="medium" | ||
| 50 | + type="primary" | ||
| 51 | + style="width:100%;" | ||
| 52 | + @click.native.prevent="handleRegister" | ||
| 53 | + > | ||
| 54 | + <span v-if="!loading">注 册</span> | ||
| 55 | + <span v-else>注 册 中...</span> | ||
| 56 | + </el-button> | ||
| 57 | + <div style="float: right;"> | ||
| 58 | + <router-link class="link-type" :to="'/login'">使用已有账户登录</router-link> | ||
| 59 | + </div> | ||
| 60 | + </el-form-item> | ||
| 61 | + </el-form> | ||
| 62 | + <!-- 底部 --> | ||
| 63 | + <div class="el-register-footer"> | ||
| 64 | + <span>Copyright © 2018-2021 ruoyi.vip All Rights Reserved.</span> | ||
| 65 | + </div> | ||
| 66 | + </div> | ||
| 67 | +</template> | ||
| 68 | + | ||
| 69 | +<script> | ||
| 70 | +import { getCodeImg, register } from "@/api/login"; | ||
| 71 | + | ||
| 72 | +export default { | ||
| 73 | + name: "Register", | ||
| 74 | + data() { | ||
| 75 | + const equalToPassword = (rule, value, callback) => { | ||
| 76 | + if (this.registerForm.password !== value) { | ||
| 77 | + callback(new Error("两次输入的密码不一致")); | ||
| 78 | + } else { | ||
| 79 | + callback(); | ||
| 80 | + } | ||
| 81 | + }; | ||
| 82 | + return { | ||
| 83 | + codeUrl: "", | ||
| 84 | + registerForm: { | ||
| 85 | + username: "", | ||
| 86 | + password: "", | ||
| 87 | + confirmPassword: "", | ||
| 88 | + code: "", | ||
| 89 | + uuid: "" | ||
| 90 | + }, | ||
| 91 | + registerRules: { | ||
| 92 | + username: [ | ||
| 93 | + { required: true, trigger: "blur", message: "请输入您的账号" }, | ||
| 94 | + { min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur' } | ||
| 95 | + ], | ||
| 96 | + password: [ | ||
| 97 | + { required: true, trigger: "blur", message: "请输入您的密码" }, | ||
| 98 | + { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' } | ||
| 99 | + ], | ||
| 100 | + confirmPassword: [ | ||
| 101 | + { required: true, trigger: "blur", message: "请再次输入您的密码" }, | ||
| 102 | + { required: true, validator: equalToPassword, trigger: "blur" } | ||
| 103 | + ], | ||
| 104 | + code: [{ required: true, trigger: "change", message: "请输入验证码" }] | ||
| 105 | + }, | ||
| 106 | + loading: false, | ||
| 107 | + captchaOnOff: true | ||
| 108 | + }; | ||
| 109 | + }, | ||
| 110 | + created() { | ||
| 111 | + this.getCode(); | ||
| 112 | + }, | ||
| 113 | + methods: { | ||
| 114 | + getCode() { | ||
| 115 | + getCodeImg().then(res => { | ||
| 116 | + this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff; | ||
| 117 | + if (this.captchaOnOff) { | ||
| 118 | + this.codeUrl = "data:image/gif;base64," + res.img; | ||
| 119 | + this.registerForm.uuid = res.uuid; | ||
| 120 | + } | ||
| 121 | + }); | ||
| 122 | + }, | ||
| 123 | + handleRegister() { | ||
| 124 | + this.$refs.registerForm.validate(valid => { | ||
| 125 | + if (valid) { | ||
| 126 | + this.loading = true; | ||
| 127 | + register(this.registerForm).then(res => { | ||
| 128 | + const username = this.registerForm.username; | ||
| 129 | + this.$alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", '系统提示', { | ||
| 130 | + dangerouslyUseHTMLString: true | ||
| 131 | + }).then(() => { | ||
| 132 | + this.$router.push("/login"); | ||
| 133 | + }).catch(() => {}); | ||
| 134 | + }).catch(() => { | ||
| 135 | + this.loading = false; | ||
| 136 | + if (this.captchaOnOff) { | ||
| 137 | + this.getCode(); | ||
| 138 | + } | ||
| 139 | + }) | ||
| 140 | + } | ||
| 141 | + }); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | +}; | ||
| 145 | +</script> | ||
| 146 | + | ||
| 147 | +<style rel="stylesheet/scss" lang="scss"> | ||
| 148 | +.register { | ||
| 149 | + display: flex; | ||
| 150 | + justify-content: center; | ||
| 151 | + align-items: center; | ||
| 152 | + height: 100%; | ||
| 153 | + background-image: url("../assets/images/login-background.jpg"); | ||
| 154 | + background-size: cover; | ||
| 155 | +} | ||
| 156 | +.title { | ||
| 157 | + margin: 0px auto 30px auto; | ||
| 158 | + text-align: center; | ||
| 159 | + color: #707070; | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +.register-form { | ||
| 163 | + border-radius: 6px; | ||
| 164 | + background: #ffffff; | ||
| 165 | + width: 400px; | ||
| 166 | + padding: 25px 25px 5px 25px; | ||
| 167 | + .el-input { | ||
| 168 | + height: 38px; | ||
| 169 | + input { | ||
| 170 | + height: 38px; | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + .input-icon { | ||
| 174 | + height: 39px; | ||
| 175 | + width: 14px; | ||
| 176 | + margin-left: 2px; | ||
| 177 | + } | ||
| 178 | +} | ||
| 179 | +.register-tip { | ||
| 180 | + font-size: 13px; | ||
| 181 | + text-align: center; | ||
| 182 | + color: #bfbfbf; | ||
| 183 | +} | ||
| 184 | +.register-code { | ||
| 185 | + width: 33%; | ||
| 186 | + height: 38px; | ||
| 187 | + float: right; | ||
| 188 | + img { | ||
| 189 | + cursor: pointer; | ||
| 190 | + vertical-align: middle; | ||
| 191 | + } | ||
| 192 | +} | ||
| 193 | +.el-register-footer { | ||
| 194 | + height: 40px; | ||
| 195 | + line-height: 40px; | ||
| 196 | + position: fixed; | ||
| 197 | + bottom: 0; | ||
| 198 | + width: 100%; | ||
| 199 | + text-align: center; | ||
| 200 | + color: #fff; | ||
| 201 | + font-family: Arial; | ||
| 202 | + font-size: 12px; | ||
| 203 | + letter-spacing: 1px; | ||
| 204 | +} | ||
| 205 | +.register-code-img { | ||
| 206 | + height: 38px; | ||
| 207 | +} | ||
| 208 | +</style> |
| @@ -436,7 +436,8 @@ export default { | @@ -436,7 +436,8 @@ export default { | ||
| 436 | // 表单校验 | 436 | // 表单校验 |
| 437 | rules: { | 437 | rules: { |
| 438 | userName: [ | 438 | userName: [ |
| 439 | - { required: true, message: "用户名称不能为空", trigger: "blur" } | 439 | + { required: true, message: "用户名称不能为空", trigger: "blur" }, |
| 440 | + { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' } | ||
| 440 | ], | 441 | ], |
| 441 | nickName: [ | 442 | nickName: [ |
| 442 | { required: true, message: "用户昵称不能为空", trigger: "blur" } | 443 | { required: true, message: "用户昵称不能为空", trigger: "blur" } |
| @@ -534,10 +534,11 @@ create table sys_config ( | @@ -534,10 +534,11 @@ create table sys_config ( | ||
| 534 | primary key (config_id) | 534 | primary key (config_id) |
| 535 | ) engine=innodb auto_increment=100 comment = '参数配置表'; | 535 | ) engine=innodb auto_increment=100 comment = '参数配置表'; |
| 536 | 536 | ||
| 537 | -insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' ); | ||
| 538 | -insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' ); | ||
| 539 | -insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' ); | ||
| 540 | -insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启登录验证码功能(true开启,false关闭)'); | 537 | +insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' ); |
| 538 | +insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' ); | ||
| 539 | +insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark,浅色主题theme-light' ); | ||
| 540 | +insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能(true开启,false关闭)'); | ||
| 541 | +insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 'admin', sysdate(), '', null, '是否开启注册用户功能(true开启,false关闭)'); | ||
| 541 | 542 | ||
| 542 | 543 | ||
| 543 | -- ---------------------------- | 544 | -- ---------------------------- |
-
请 注册 或 登录 后发表评论