diff --git a/src/main/java/com/quinn/common/ExceptionCode.java b/src/main/java/com/quinn/common/ExceptionCode.java new file mode 100644 index 0000000..ab56ee4 --- /dev/null +++ b/src/main/java/com/quinn/common/ExceptionCode.java @@ -0,0 +1,17 @@ +package com.quinn.common; + +import java.io.Serializable; + +public class ExceptionCode implements Serializable { + public Integer code; + public String msg; + + public ExceptionCode(Integer code, String message) { + this.code = code; + this.msg = message; + } + + public static ExceptionCode init(Integer code, String message) { + return new ExceptionCode(code, message); + } +} diff --git a/src/main/java/com/quinn/config/SecurityConfig.java b/src/main/java/com/quinn/config/SecurityConfig.java index 023c4e2..1bdc159 100644 --- a/src/main/java/com/quinn/config/SecurityConfig.java +++ b/src/main/java/com/quinn/config/SecurityConfig.java @@ -8,8 +8,18 @@ import org.springframework.security.config.annotation.method.configuration.Enabl import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.AuthenticationException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.AuthenticationEntryPoint; +import org.springframework.security.web.authentication.AuthenticationEntryPointFailureHandler; +import org.springframework.security.web.authentication.AuthenticationFailureHandler; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) @@ -29,9 +39,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { http.authorizeRequests() .antMatchers("/","/index").permitAll() .antMatchers("/register","/login","/toLogin").permitAll() + .antMatchers("/source","/source/view/*").permitAll() + .antMatchers("/blog","/blog/read/*").permitAll() + .antMatchers("/hotspot").permitAll() .antMatchers("/blog/**").authenticated() .antMatchers("/source/**").authenticated() .antMatchers("/user/**").authenticated() + .antMatchers("/wx/**").authenticated() .antMatchers("/*").authenticated(); // 登录配置 @@ -40,6 +54,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .passwordParameter("password") .loginPage("/toLogin") .loginProcessingUrl("/login") // 登陆表单提交请求 + .failureForwardUrl("/loginError") .defaultSuccessUrl("/index"); // 设置默认登录成功后跳转的页面 // 注销配置 diff --git a/src/main/java/com/quinn/controller/LoginController.java b/src/main/java/com/quinn/controller/LoginController.java index c0afe4e..4e3e679 100644 --- a/src/main/java/com/quinn/controller/LoginController.java +++ b/src/main/java/com/quinn/controller/LoginController.java @@ -3,6 +3,7 @@ package com.quinn.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.quinn.common.RoleType; import com.quinn.intergration.AttrIcon; +import com.quinn.intergration.SendBMail; import com.quinn.pojo.Invite; import com.quinn.pojo.User; import com.quinn.pojo.UserInfo; @@ -18,6 +19,10 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + @Controller public class LoginController { @@ -35,9 +40,10 @@ public class LoginController { return "index"; } - @GetMapping("/error/check") - public String error(){ - return "error/check"; + @PostMapping("/loginError") + public String error(Model model){ + model.addAttribute("loginMsg","错误的用户名或者密码!"); + return "forget"; } @GetMapping("/toLogin") @@ -52,55 +58,57 @@ public class LoginController { // 注册业务 @PostMapping("/register") - public String register(RegisterForm registerForm,Model model){ + public String register(HttpServletResponse response,RegisterForm registerForm, Model model) throws IOException { + response.setCharacterEncoding("UTF-8"); + PrintWriter writer = response.getWriter(); // 表单密码重复判断 if (!registerForm.getPassword().equals(registerForm.getRepassword())){ - model.addAttribute("registerMsg","密码输入有误"); - return "register"; + return toResult(writer,"两次输入密码不一致!"); } // 用户名已存在 User hasUser = userService.getOne(new QueryWrapper().eq("username", registerForm.getUsername())); if (hasUser!=null){ - model.addAttribute("registerMsg","用户名已存在"); - return "register"; + return toResult(writer,"用户名太热门了,请更换用户名"); } // 验证邀请码 Invite invite = inviteService.getOne(new QueryWrapper().eq("code", registerForm.getCode())); if (invite==null){ - model.addAttribute("registerMsg","邀请码不存在"); - return "register"; - }else { - // 邀请码存在,判断邀请码是否有效 - if (invite.getStatus()==1){ - model.addAttribute("registerMsg","邀请码已被使用"); - return "register"; - }else { - // 构建用户对象 - User user = new User(); - user.setUid(QuinnUtils.getUuid()); // 用户唯一id - user.setRole(RoleType.NORMAL.name()); - user.setUsername(registerForm.getUsername()); - // 密码加密 - String bCryptPassword = new BCryptPasswordEncoder().encode(registerForm.getPassword()); - user.setAvatar(AttrIcon.INSTANCE.generateImgUrl(registerForm.getUsername())); - user.setPassword(bCryptPassword); - user.setGmtCreate(QuinnUtils.getTime()); - user.setLoginDate(QuinnUtils.getTime()); - // 保存对象! - userService.save(user); - // 激活邀请码 - invite.setActiveTime(QuinnUtils.getTime()); - invite.setStatus(1); - invite.setUid(user.getUid()); - inviteService.updateById(invite); - - userInfoService.save(new UserInfo().setUid(user.getUid())); - - // 注册成功,重定向到登录页面 - return "redirect:/toLogin"; - } + return toResult(writer,"注册码不存在!"); } + if (invite.getApplyEmail().equals(registerForm.getEmail())){ + return toResult(writer,"请使用申请注册码邮箱注册用户!"); + } + // 构建用户对象 + User user = new User(); + user.setUid(QuinnUtils.getUuid()); // 用户唯一id + user.setRole(RoleType.NORMAL.name()); + user.setUsername(registerForm.getUsername()); + // 密码加密 + String bCryptPassword = new BCryptPasswordEncoder().encode(registerForm.getPassword()); + user.setAvatar(AttrIcon.INSTANCE.generateImgUrl(registerForm.getUsername())); + user.setPassword(bCryptPassword); + user.setGmtCreate(QuinnUtils.getTime()); + user.setLoginDate(QuinnUtils.getTime()); + // 保存对象! + userService.save(user); + // 激活邀请码 + invite.setActiveTime(QuinnUtils.getTime()); + invite.setStatus(1); + invite.setUid(user.getUid()); + inviteService.updateById(invite); + userInfoService.save(new UserInfo().setUid(user.getUid()).setEmail(registerForm.getEmail())); + // 发送注册成功通知邮件 + SendBMail.INSTANCE.sendWelcome(registerForm.getUsername(),registerForm.getEmail()); + // 注册成功,重定向到登录页面 + return "redirect:/toLogin"; + } + + private String toResult(PrintWriter writer, String msg) { + writer.write(msg); + writer.flush(); + writer.close(); + return "register"; } } diff --git a/src/main/java/com/quinn/controller/SourceController.java b/src/main/java/com/quinn/controller/SourceController.java index ac1dc6d..6b94c7c 100644 --- a/src/main/java/com/quinn/controller/SourceController.java +++ b/src/main/java/com/quinn/controller/SourceController.java @@ -11,6 +11,7 @@ import com.quinn.service.CommentService; import com.quinn.service.SourceCategoryService; import com.quinn.service.SourceService; import com.quinn.service.StarService; +import com.quinn.utils.QuinnUtils; import com.quinn.vo.*; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -151,4 +152,16 @@ public class SourceController extends BaseModelController { } } + // 评论 + @PostMapping("/source/comment/{sid}") + public String comment(@PathVariable("sid") String sid, Comment comment){ + // 存储评论 + comment.setCommentId(QuinnUtils.getUuid()); + comment.setTopicCategory(Category.SOURCE.name()); + comment.setGmtCreate(QuinnUtils.getTime()); + commentService.save(comment); + // 重定向到列表页面 + return "redirect:/source/view/"+sid; + } + } diff --git a/src/main/java/com/quinn/controller/WxController.java b/src/main/java/com/quinn/controller/WxController.java new file mode 100644 index 0000000..f036df8 --- /dev/null +++ b/src/main/java/com/quinn/controller/WxController.java @@ -0,0 +1,94 @@ +package com.quinn.controller; + + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.quinn.dto.req.SearchPage; +import com.quinn.dto.req.SendCode; +import com.quinn.dto.res.AboutDTO; +import com.quinn.dto.res.ResponseDTO; +import com.quinn.intergration.SendBMail; +import com.quinn.pojo.About; +import com.quinn.pojo.Invite; +import com.quinn.pojo.UserInfo; +import com.quinn.service.AboutService; +import com.quinn.service.InviteService; +import com.quinn.service.UserInfoService; +import com.quinn.service.UserService; +import com.quinn.utils.QuinnUtils; +import com.quinn.vo.MyPageParam; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author limqsh + * @since 2022-05-01 + */ +@RestController("/wx") +public class WxController extends BaseModelController { + + @Resource + AboutService aboutService; + @Resource + UserInfoService userInfoService; + @Resource + InviteService inviteService; + + @PostMapping("about/us") + public ResponseDTO userIndexBlog(SearchPage searchPage){ + Page pageParam = new Page<>(searchPage.getPage(), searchPage.getPageSize()); + aboutService.page(pageParam,new QueryWrapper().orderByDesc("gmt_create")); + // 结果 + List sayList = pageParam.getRecords(); + List aboutDTOS = new ArrayList<>(); + if (!CollectionUtils.isEmpty(sayList)){ + sayList.forEach(x->{ + AboutDTO aboutDTO = new AboutDTO(); + aboutDTO.setId(x.getId()); + aboutDTO.setTitle(x.getTitle()); + aboutDTO.setContent(x.getContent()); + aboutDTO.setGmtCreate(QuinnUtils.getViewStrFromDate(x.getGmtCreate())); + aboutDTOS.add(aboutDTO); + }); + } + MyPageParam myPageParam = new MyPageParam(searchPage.getPage(),searchPage.getPageSize()); + myPageParam.setTotal((int) pageParam.getTotal()); + return ResponseDTO.ok().setPage(myPageParam).setData(aboutDTOS); + } + + @PostMapping("send/register/code") + public ResponseDTO sendCode(SendCode sendCode){ + Invite email = inviteService.getOne(new QueryWrapper().eq("apply_email", sendCode.getEmail())); + if (email != null){ + return ResponseDTO.ok().setData("该邮箱已经获取过注册码"); + } + String code = inviteService.getCode(); + Invite invite = new Invite(); + invite.setUid(QuinnUtils.getUuid()); + invite.setApplyEmail(sendCode.getEmail()); + invite.setCode(code); + invite.setGmtCreate(QuinnUtils.getTime()); + inviteService.save(invite); + boolean sendFlag = SendBMail.INSTANCE.sendRegisterMail(code, sendCode.getEmail()); + if (!sendFlag){ + return ResponseDTO.ok().setData("发送识别,请确认邮箱是否正确!"); + } + return ResponseDTO.ok().setData("success"); + } + +} + diff --git a/src/main/java/com/quinn/dto/req/SearchPage.java b/src/main/java/com/quinn/dto/req/SearchPage.java new file mode 100644 index 0000000..0f9e4a4 --- /dev/null +++ b/src/main/java/com/quinn/dto/req/SearchPage.java @@ -0,0 +1,13 @@ +package com.quinn.dto.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SearchPage implements Serializable { + + int page; + int pageSize; + +} diff --git a/src/main/java/com/quinn/dto/req/SendCode.java b/src/main/java/com/quinn/dto/req/SendCode.java new file mode 100644 index 0000000..59bfaf0 --- /dev/null +++ b/src/main/java/com/quinn/dto/req/SendCode.java @@ -0,0 +1,12 @@ +package com.quinn.dto.req; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SendCode implements Serializable { + + String email; + +} diff --git a/src/main/java/com/quinn/dto/res/AboutDTO.java b/src/main/java/com/quinn/dto/res/AboutDTO.java new file mode 100644 index 0000000..2e2d2f5 --- /dev/null +++ b/src/main/java/com/quinn/dto/res/AboutDTO.java @@ -0,0 +1,35 @@ +package com.quinn.dto.res; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * + *

+ * + * @author limqsh + * @since 2022-05-01 + */ +@Data +public class AboutDTO implements Serializable { + + private String id; + + private String title; + + private String content; + + private String gmtCreate; + + +} diff --git a/src/main/java/com/quinn/dto/res/ResponseDTO.java b/src/main/java/com/quinn/dto/res/ResponseDTO.java new file mode 100644 index 0000000..c80b126 --- /dev/null +++ b/src/main/java/com/quinn/dto/res/ResponseDTO.java @@ -0,0 +1,74 @@ +package com.quinn.dto.res; + +import java.util.LinkedHashMap; + +import com.quinn.common.ExceptionCode; +import com.quinn.vo.MyPageParam; +import org.springframework.util.Assert; + +public class ResponseDTO extends LinkedHashMap { + public static final String ERR_CODE = "err_code"; + public static final String ERR_MSG = "err_msg"; + + public ResponseDTO() { + this(0, "OK"); + } + + public ResponseDTO(Integer errCode, String errMsg) { + this(errCode, errMsg, System.currentTimeMillis() / 1000L); + } + + public ResponseDTO(Integer errCode, String errMsg, Long timestamp) { + this.addAttribute(ERR_CODE, errCode); + this.addAttribute(ERR_MSG, errMsg); + this.addAttribute("timestamp", timestamp); + } + + public ResponseDTO(ExceptionCode exceptionCode) { + this(exceptionCode.code, exceptionCode.msg); + } + + public ResponseDTO(Integer errCode, String errMsg, String attrName, Object attrValue) { + this(errCode, errMsg); + this.addAttribute(attrName, attrValue); + } + + public static ResponseDTO ok() { + return new ResponseDTO(); + } + + public static ResponseDTO ok(String msg) { + ResponseDTO ret = ok(); + ret.setErrorMsg(msg); + return ret; + } + + public ResponseDTO addAttribute(String attrName, Object attrValue) { + Assert.notNull(attrName, "属性名称不能为空"); + this.put(attrName, attrValue); + return this; + } + + public ResponseDTO setPage(MyPageParam pagination) { + this.addAttribute("page", pagination); + return this; + } + + public ResponseDTO setData(Object obj){ + this.addAttribute("data",obj); + return this; + } + + public void setExceptionCode(ExceptionCode exceptionCode) { + this.addAttribute("err_code", exceptionCode.code); + this.addAttribute("err_msg", exceptionCode.msg); + } + + public void setErrorCode(Integer errCode) { + this.addAttribute("err_code", errCode); + } + + public void setErrorMsg(String errMsg) { + this.addAttribute("err_msg", errMsg); + } +} diff --git a/src/main/java/com/quinn/intergration/SendBMail.java b/src/main/java/com/quinn/intergration/SendBMail.java index 1f90fc3..f1d9b32 100644 --- a/src/main/java/com/quinn/intergration/SendBMail.java +++ b/src/main/java/com/quinn/intergration/SendBMail.java @@ -27,7 +27,17 @@ public enum SendBMail { boolean isAuth = true; String from = "quinn.admin@88.com"; - public boolean sendMail(String registerCode,String toEmail){ + public boolean sendRegisterMail(String registerCode,String email){ + return sendMail("QUINN注册码", + "您好,您的注册码是【" + registerCode + "】",email); + } + + public boolean sendWelcome(String username,String email){ + return sendMail("QUINN-注册成功", + username + "您好,欢迎使用!",email); + } + + private boolean sendMail(String subject,String content,String toEmail){ Properties props = new Properties(); props.put("mail.smtp.ssl.enable", isSSL); props.put("mail.smtp.host", host); @@ -42,8 +52,8 @@ public enum SendBMail { try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); - message.setSubject(""); - message.setContent("","text/html;charset=UTF-8"); + message.setSubject(subject); + message.setContent(content,"text/html;charset=UTF-8"); message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail)); Transport.send(message); } catch (Exception e) { diff --git a/src/main/java/com/quinn/pojo/Invite.java b/src/main/java/com/quinn/pojo/Invite.java index 1640708..aa833e2 100644 --- a/src/main/java/com/quinn/pojo/Invite.java +++ b/src/main/java/com/quinn/pojo/Invite.java @@ -34,6 +34,9 @@ public class Invite implements Serializable { @ApiModelProperty(value = "用户id") private String uid; + @ApiModelProperty(value = "申请邮箱") + private String applyEmail; + @ApiModelProperty(value = "状态 0 未使用 1 使用") private Integer status; diff --git a/src/main/java/com/quinn/service/InviteService.java b/src/main/java/com/quinn/service/InviteService.java index 223ec02..60fe60d 100644 --- a/src/main/java/com/quinn/service/InviteService.java +++ b/src/main/java/com/quinn/service/InviteService.java @@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface InviteService extends IService { + String getCode(); } diff --git a/src/main/java/com/quinn/service/impl/InviteServiceImpl.java b/src/main/java/com/quinn/service/impl/InviteServiceImpl.java index a60d090..1c20839 100644 --- a/src/main/java/com/quinn/service/impl/InviteServiceImpl.java +++ b/src/main/java/com/quinn/service/impl/InviteServiceImpl.java @@ -1,9 +1,11 @@ package com.quinn.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.quinn.pojo.Invite; import com.quinn.mapper.InviteMapper; import com.quinn.service.InviteService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.quinn.utils.QuinnUtils; import org.springframework.stereotype.Service; /** @@ -17,4 +19,17 @@ import org.springframework.stereotype.Service; @Service public class InviteServiceImpl extends ServiceImpl implements InviteService { + + @Override + public String getCode() { + String code = ""; + while (true){ + code = QuinnUtils.getCode(); + int count = count(new QueryWrapper().eq("apply_email", code).eq("status",'0')); + if (count <= 0){ + break; + } + } + return code; + } } diff --git a/src/main/java/com/quinn/utils/QuinnUtils.java b/src/main/java/com/quinn/utils/QuinnUtils.java index cb9c363..b0677ec 100644 --- a/src/main/java/com/quinn/utils/QuinnUtils.java +++ b/src/main/java/com/quinn/utils/QuinnUtils.java @@ -3,11 +3,14 @@ package com.quinn.utils; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Random; import java.util.UUID; public class QuinnUtils { + private static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd"); + private final static SimpleDateFormat sdfv = new SimpleDateFormat( "yyyy-MM-dd"); public static String getUuid(){ return UUID.randomUUID().toString().replaceAll("-",""); @@ -21,4 +24,19 @@ public class QuinnUtils { return sdf.format(date); } + public static String getViewStrFromDate(Date date){ + return sdfv.format(date); + } + + public static String getCode(){ + int length = 6; + //随机数 + StringBuffer sb = new StringBuffer(); + Random random = new Random(); + for (int i = 0; i < length; i++) { + sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length()))); + } + return sb.toString(); + } + } diff --git a/src/main/java/com/quinn/vo/RegisterForm.java b/src/main/java/com/quinn/vo/RegisterForm.java index d1b425d..7b28749 100644 --- a/src/main/java/com/quinn/vo/RegisterForm.java +++ b/src/main/java/com/quinn/vo/RegisterForm.java @@ -19,6 +19,9 @@ public class RegisterForm { @ApiModelProperty(value = "确认密码") private String repassword; + @ApiModelProperty(value = "申请邮箱") + private String email; + @ApiModelProperty(value = "邀请码") private String code; diff --git a/src/main/resources/static/bootstrap/css/bootstrapValidator.css b/src/main/resources/static/bootstrap/css/bootstrapValidator.css deleted file mode 100755 index 4347416..0000000 --- a/src/main/resources/static/bootstrap/css/bootstrapValidator.css +++ /dev/null @@ -1,31 +0,0 @@ -/** - * BootstrapValidator (http://bootstrapvalidator.com) - * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3 - * - * @author http://twitter.com/nghuuphuoc - * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc - * @license Commercial: http://bootstrapvalidator.com/license/ - * Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/ - */ - -.bv-form .help-block { - margin-bottom: 0; -} -.bv-form .tooltip-inner { - text-align: left; -} -.nav-tabs li.bv-tab-success > a { - color: #3c763d; -} -.nav-tabs li.bv-tab-error > a { - color: #a94442; -} - -.bv-form .bv-icon-no-label { - top: 0; -} - -.bv-form .bv-icon-input-group { - top: 0; - z-index: 100; -} \ No newline at end of file diff --git a/src/main/resources/static/bootstrap/js/bootstrapValidator.js b/src/main/resources/static/bootstrap/js/bootstrapValidator.js deleted file mode 100755 index 4760b16..0000000 --- a/src/main/resources/static/bootstrap/js/bootstrapValidator.js +++ /dev/null @@ -1,2003 +0,0 @@ -/** - * BootstrapValidator (http://bootstrapvalidator.com) - * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3 - * - * @author https://twitter.com/nghuuphuoc - * @copyright (c) 2013 - 2014 Nguyen Huu Phuoc - * @license Commercial: http://bootstrapvalidator.com/license/ - * Non-commercial: http://creativecommons.org/licenses/by-nc-nd/3.0/ - */ - -if (typeof jQuery === 'undefined') { - throw new Error('BootstrapValidator requires jQuery'); -} - -(function($) { - var version = $.fn.jquery.split(' ')[0].split('.'); - if ((+version[0] < 2 && +version[1] < 9) || (+version[0] === 1 && +version[1] === 9 && +version[2] < 1)) { - throw new Error('BootstrapValidator requires jQuery version 1.9.1 or higher'); - } -}(window.jQuery)); - -(function($) { - var BootstrapValidator = function(form, options) { - this.$form = $(form); - this.options = $.extend({}, $.fn.bootstrapValidator.DEFAULT_OPTIONS, options); - - this.$invalidFields = $([]); // Array of invalid fields - this.$submitButton = null; // The submit button which is clicked to submit form - this.$hiddenButton = null; - - // Validating status - this.STATUS_NOT_VALIDATED = 'NOT_VALIDATED'; - this.STATUS_VALIDATING = 'VALIDATING'; - this.STATUS_INVALID = 'INVALID'; - this.STATUS_VALID = 'VALID'; - - // Determine the event that is fired when user change the field value - // Most modern browsers supports input event except IE 7, 8. - // IE 9 supports input event but the event is still not fired if I press the backspace key. - // Get IE version - // https://gist.github.com/padolsey/527683/#comment-7595 - var ieVersion = (function() { - var v = 3, div = document.createElement('div'), a = div.all || []; - while (div.innerHTML = '', a[0]) {} - return v > 4 ? v : !v; - }()); - - var el = document.createElement('div'); - this._changeEvent = (ieVersion === 9 || !('oninput' in el)) ? 'keyup' : 'input'; - - // The flag to indicate that the form is ready to submit when a remote/callback validator returns - this._submitIfValid = null; - - // Field elements - this._cacheFields = {}; - - this._init(); - }; - - BootstrapValidator.prototype = { - constructor: BootstrapValidator, - - /** - * Init form - */ - _init: function() { - var that = this, - options = { - autoFocus: this.$form.attr('data-bv-autofocus'), - container: this.$form.attr('data-bv-container'), - events: { - formInit: this.$form.attr('data-bv-events-form-init'), - formError: this.$form.attr('data-bv-events-form-error'), - formSuccess: this.$form.attr('data-bv-events-form-success'), - fieldAdded: this.$form.attr('data-bv-events-field-added'), - fieldRemoved: this.$form.attr('data-bv-events-field-removed'), - fieldInit: this.$form.attr('data-bv-events-field-init'), - fieldError: this.$form.attr('data-bv-events-field-error'), - fieldSuccess: this.$form.attr('data-bv-events-field-success'), - fieldStatus: this.$form.attr('data-bv-events-field-status'), - validatorError: this.$form.attr('data-bv-events-validator-error'), - validatorSuccess: this.$form.attr('data-bv-events-validator-success') - }, - excluded: this.$form.attr('data-bv-excluded'), - feedbackIcons: { - valid: this.$form.attr('data-bv-feedbackicons-valid'), - invalid: this.$form.attr('data-bv-feedbackicons-invalid'), - validating: this.$form.attr('data-bv-feedbackicons-validating') - }, - group: this.$form.attr('data-bv-group'), - live: this.$form.attr('data-bv-live'), - message: this.$form.attr('data-bv-message'), - onError: this.$form.attr('data-bv-onerror'), - onSuccess: this.$form.attr('data-bv-onsuccess'), - submitButtons: this.$form.attr('data-bv-submitbuttons'), - threshold: this.$form.attr('data-bv-threshold'), - trigger: this.$form.attr('data-bv-trigger'), - verbose: this.$form.attr('data-bv-verbose'), - fields: {} - }; - - this.$form - // Disable client side validation in HTML 5 - .attr('novalidate', 'novalidate') - .addClass(this.options.elementClass) - // Disable the default submission first - .on('submit.bv', function(e) { - e.preventDefault(); - that.validate(); - }) - .on('click.bv', this.options.submitButtons, function() { - that.$submitButton = $(this); - // The user just click the submit button - that._submitIfValid = true; - }) - // Find all fields which have either "name" or "data-bv-field" attribute - .find('[name], [data-bv-field]') - .each(function() { - var $field = $(this), - field = $field.attr('name') || $field.attr('data-bv-field'), - opts = that._parseOptions($field); - if (opts) { - $field.attr('data-bv-field', field); - options.fields[field] = $.extend({}, opts, options.fields[field]); - } - }); - - this.options = $.extend(true, this.options, options); - - // When pressing Enter on any field in the form, the first submit button will do its job. - // The form then will be submitted. - // I create a first hidden submit button - this.$hiddenButton = $(' + @@ -76,7 +76,32 @@ - + + diff --git a/src/main/resources/templates/blog/read.html b/src/main/resources/templates/blog/read.html index 4b3ea29..c96d7c2 100644 --- a/src/main/resources/templates/blog/read.html +++ b/src/main/resources/templates/blog/read.html @@ -38,7 +38,7 @@ [[${blog.getViews()}]] - @@ -49,7 +49,7 @@ 删除 - @@ -58,7 +58,7 @@ 编辑 - + @@ -76,7 +76,7 @@
-
+
@@ -87,14 +87,13 @@
- - - + +
- +
- +
@@ -132,6 +131,7 @@ + diff --git a/src/main/resources/templates/blog/write.html b/src/main/resources/templates/blog/write.html index 16931c4..2da9006 100644 --- a/src/main/resources/templates/blog/write.html +++ b/src/main/resources/templates/blog/write.html @@ -31,17 +31,15 @@ - -
- - + +
- - @@ -52,7 +50,7 @@

文章内容

-
+
@@ -60,7 +58,7 @@
- +
@@ -77,8 +75,31 @@ - - - + + diff --git a/src/main/resources/templates/common/header.html b/src/main/resources/templates/common/header.html index f40c79e..3c49000 100644 --- a/src/main/resources/templates/common/header.html +++ b/src/main/resources/templates/common/header.html @@ -40,9 +40,9 @@
-