This article mainly introduces Spring shiro + bootstrap + jquery.validate to implement login and registration functions. Friends who need it can refer to it. I hope it can help everyone.
In the previous article, we have already built the framework and designed the database.
Now we start to implement the login function, which can be said to be the most common function of Web applications.
Let’s talk about our login logic first:
Enter user name and password (validate for front-end verification) - ajax calls the background action method - calls the business layer to the data layer according to the user name Query database information - compare the queried password with the password entered by the user - shiro login authentication - store user information in session - respond to the front end - front end jump
This is what I want to tell you poses, and there are many, many more poses. Let's look at the specific code below.
First, front-end verification, jquery.validate is used here for verification. The use of jquery.validate is very simple. Here we talk about the way to save js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
html page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
In the $("#login_form").validate({...}) method, login_form is The id of the form you want to verify; rules are the fields to be verified; messages are the content to be prompted. If not filled in, the default message will be prompted; submitHandler is the callback method after clicking the submit button, and the final return here false is to prevent the submission of the form, because I want to submit it here using ajax; there is an attribute remote in the loginAccount field in the registration. This is for ajax verification. Before submitting the form, we verify the user entered by the user. Whether the name already exists in the system.
When we are programming, we find that there are always several methods used in the same code layer, such as obtaining user session in the control layer, or outputting response information, etc.; in the dao layer Call Hibernate's save method, update method, delete method, etc. Therefore, we should establish some common tool classes or Base methods in the early stages of framework construction. Next, we will create a new BaseController method and let subsequent controllers inherit it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
User's controller SysUserController:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
At this point, log in and register OK!
jquery-confirm.js is also used, which is a pop-up box plug-in: click to view
related recommendations :
vue realizes that the page jumps to the previous page after login. Example sharing
AJAX method to realize the non-refresh login function
Judge whether the user is logged in when vue route jumps
The above is the detailed content of Spring shiro bootstrap jquery.validate implementation method of login and registration functions. For more information, please follow other related articles on the PHP Chinese website!