大量修改

This commit is contained in:
Saturneric 2020-01-31 16:59:12 +08:00
parent bec6fa41ad
commit 440c3da1a7
9 changed files with 248 additions and 28 deletions

View File

@ -0,0 +1,22 @@
package com.codesdream.ase.configure;
import org.springframework.context.annotation.Configuration;
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;
@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
/* .authorizeRequests().anyRequest().permitAll()*/
/* .antMatchers("/index", "/assets/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()*/;
}
}

View File

@ -0,0 +1,27 @@
package com.codesdream.ase.controller;
import com.codesdream.ase.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
@Controller
public class LoginController {
@RequestMapping(value = "/login")
String printLogin(Model model){
return "login";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
String checkLogin(Model model, HttpServletRequest request){
User user = new User();
user.setUsername(request.getParameter("username"));
user.setPassword(DigestUtils.md5DigestAsHex(request.getParameter("password").getBytes()));
return "login";
}
}

View File

@ -0,0 +1,13 @@
package com.codesdream.ase.model;
import javax.persistence.*;
@Entity
@Table(name = "user_tag")
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
private String description;
}

View File

@ -0,0 +1,63 @@
package com.codesdream.ase.model;
import javax.persistence.*;
import java.util.Objects;
@Entity
@Table(name = "user_login")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String username;
private String password;
public User(){
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return id == user.id &&
Objects.equals(username, user.username) &&
Objects.equals(password, user.password);
}
@Override
public int hashCode() {
return Objects.hash(id, username, password);
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}

View File

@ -0,0 +1,10 @@
package com.codesdream.ase.repository;
import com.codesdream.ase.model.User;
import org.springframework.data.repository.CrudRepository;
import java.util.Optional;
public interface UserRepository extends CrudRepository<User, Long> {
Optional<User> findByUsername(String username);
}

View File

@ -0,0 +1,14 @@
package com.codesdream.ase.service;
import com.codesdream.ase.model.User;
import java.util.List;
import java.util.Optional;
public interface IUserService {
List<User> findAll();
Optional<User> findUserById(long id);
Optional<User> findUserByUsername(String username);
User save(User user);
}

View File

@ -1,5 +1,35 @@
package com.codesdream.ase.service;
public interface UserService {
import com.codesdream.ase.model.User;
import com.codesdream.ase.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Optional;
public class UserService implements IUserService {
@Autowired
UserRepository userRepository;
@Override
public List<User> findAll() {
return (List<User>) userRepository.findAll();
}
@Override
public Optional<User> findUserById(long id) {
return userRepository.findById(id);
}
@Override
public Optional<User> findUserByUsername(String username) {
return userRepository.findByUsername(username);
}
@Override
public User save(User user) {
return userRepository.save(user);
}
}

View File

@ -13,7 +13,7 @@
<script>
WebFont.load({
google: {"families":["Lato:300,400,700,900"]},
custom: {"families":["Flaticon", "Font Awesome 5 Solid", "Font Awesome 5 Regular", "Font Awesome 5 Brands", "simple-line-icons"], urls: ['./assets/css/fonts.min.css']},
custom: {"families":["Flaticon", "Font Awesome 5 Solid", "Font Awesome 5 Regular", "Font Awesome 5 Brands", "simple-line-icons"], urls: ['/assets/css/fonts.min.css']},
active: function() {
sessionStorage.fonts = true;
}
@ -29,46 +29,46 @@
</div>
<div th:fragment="js">
<!-- Core JS Files -->
<script src="./assets/js/core/jquery.3.2.1.min.js"></script>
<script src="./assets/js/core/popper.min.js"></script>
<script src="./assets/js/core/bootstrap.min.js"></script>
<script th:src="@{/assets/js/core/jquery.3.2.1.min.js}"></script>
<script th:src="@{/assets/js/core/popper.min.js}"></script>
<script th:src="@{/assets/js/core/bootstrap.min.js}"></script>
<!-- jQuery UI -->
<script src="./assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script>
<script src="./assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js"></script>
<script th:src="@{/assets/js/plugin/jquery-ui-1.12.1.custom/jquery-ui.min.js}"></script>
<script th:src="@{/assets/js/plugin/jquery-ui-touch-punch/jquery.ui.touch-punch.min.js}"></script>
<!-- jQuery Scrollbar -->
<script src="./assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js"></script>
<script th:src="@{/assets/js/plugin/jquery-scrollbar/jquery.scrollbar.min.js}"></script>
<!-- Chart JS -->
<script src="./assets/js/plugin/chart.js/chart.min.js"></script>
<script th:src="@{/assets/js/plugin/chart.js/chart.min.js}"></script>
<!-- jQuery Sparkline -->
<script src="./assets/js/plugin/jquery.sparkline/jquery.sparkline.min.js"></script>
<script th:src="@{/assets/js/plugin/jquery.sparkline/jquery.sparkline.min.js}"></script>
<!-- Chart Circle -->
<script src="./assets/js/plugin/chart-circle/circles.min.js"></script>
<script th:src="@{/assets/js/plugin/chart-circle/circles.min.js}"></script>
<!-- Datatables -->
<script src="./assets/js/plugin/datatables/datatables.min.js"></script>
<script th:src="@{/assets/js/plugin/datatables/datatables.min.js}"></script>
<!-- Bootstrap Notify -->
<script src="./assets/js/plugin/bootstrap-notify/bootstrap-notify.min.js"></script>
<script th:src="@{/assets/js/plugin/bootstrap-notify/bootstrap-notify.min.js}"></script>
<!-- jQuery Vector Maps -->
<script src="./assets/js/plugin/jqvmap/jquery.vmap.min.js"></script>
<script src="./assets/js/plugin/jqvmap/maps/jquery.vmap.world.js"></script>
<script th:src="@{/assets/js/plugin/jqvmap/jquery.vmap.min.js}"></script>
<script th:src="@{/assets/js/plugin/jqvmap/maps/jquery.vmap.world.js}"></script>
<!-- Sweet Alert -->
<script src="./assets/js/plugin/sweetalert/sweetalert.min.js"></script>
<script th:src="@{/assets/js/plugin/sweetalert/sweetalert.min.js}"></script>
<!-- Atlantis JS -->
<script src="./assets/js/atlantis.min.js"></script>
<script th:src="@{/assets/js/atlantis.min.js}"></script>
<!-- Atlantis DEMO methods, don't include it in your project! -->
<script src="./assets/js/setting-demo.js"></script>
<script src="./assets/js/demo.js"></script>
<script th:src="@{/assets/js/setting-demo.js}"></script>
<script th:src="@{/assets/js/demo.js}"></script>
<script>
Circles.create({
id:'circles-1',
@ -170,7 +170,7 @@
<div class="logo-header" data-background-color="blue">
<a href="index.html" class="logo">
<img src="./assets/img/logo.svg" alt="navbar brand" class="navbar-brand">
<img th:src="@{/assets/img/logo.svg}" alt="navbar brand" class="navbar-brand">
</a>
<button class="navbar-toggler sidenav-toggler ml-auto" type="button" data-toggle="collapse" data-target="collapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon">
@ -224,7 +224,7 @@
<div class="notif-center">
<a href="#">
<div class="notif-img">
<img src="./assets/img/jm_denis.jpg" alt="Img Profile">
<img th:src="@{/assets/img/jm_denis.jpg}" alt="Img Profile">
</div>
<div class="notif-content">
<span class="subject">Jimmy Denis</span>
@ -236,7 +236,7 @@
</a>
<a href="#">
<div class="notif-img">
<img src="./assets/img/chadengle.jpg" alt="Img Profile">
<img th:src="@{/assets/img/chadengle.jpg}" alt="Img Profile">
</div>
<div class="notif-content">
<span class="subject">Chad</span>
@ -248,7 +248,7 @@
</a>
<a href="#">
<div class="notif-img">
<img src="./assets/img/mlane.jpg" alt="Img Profile">
<img th:src="@{/assets/img/mlane.jpg}" alt="Img Profile">
</div>
<div class="notif-content">
<span class="subject">Jhon Doe</span>
@ -260,7 +260,7 @@
</a>
<a href="#">
<div class="notif-img">
<img src="./assets/img/talha.jpg" alt="Img Profile">
<img th:src="@{/assets/img/talha.jpg}" alt="Img Profile">
</div>
<div class="notif-content">
<span class="subject">Talha</span>
@ -310,7 +310,7 @@
</a>
<a href="#">
<div class="notif-img">
<img src="./assets/img/profile2.jpg" alt="Img Profile">
<img th:src="@{/assets/img/profile2.jpg}" alt="Img Profile">
</div>
<div class="notif-content">
<span class="block">
@ -392,14 +392,14 @@
<li class="nav-item dropdown hidden-caret">
<a class="dropdown-toggle profile-pic" data-toggle="dropdown" href="#" aria-expanded="false">
<div class="avatar-sm">
<img src="./assets/img/profile.jpg" alt="..." class="avatar-img rounded-circle">
<img th:src="@{/assets/img/profile.jpg}" alt="..." class="avatar-img rounded-circle">
</div>
</a>
<ul class="dropdown-menu dropdown-user animated fadeIn">
<div class="dropdown-user-scroll scrollbar-outer">
<li>
<div class="user-box">
<div class="avatar-lg"><img src="./assets/img/profile.jpg" alt="image profile" class="avatar-img rounded"></div>
<div class="avatar-lg"><img th:src="@{/assets/img/profile.jpg}" alt="image profile" class="avatar-img rounded"></div>
<div class="u-text">
<h4>Hizrian</h4>
<p class="text-muted">hello@example.com</p><a href="profile.html" class="btn btn-xs btn-secondary btn-sm">View Profile</a>
@ -432,7 +432,7 @@
<div class="sidebar-content">
<div class="user">
<div class="avatar-sm float-left mr-2">
<img src="./assets/img/profile.jpg" alt="..." class="avatar-img rounded-circle">
<img th:src="@{/assets/img/profile.jpg}" alt="..." class="avatar-img rounded-circle">
</div>
<div class="info">
<a data-toggle="collapse" href="#collapseExample" aria-expanded="true">

View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org">
<head>
<div th:include="layout::head"></div>
</head>
<body>
<div th:fragment="content">
<div class="wrapper">
<div class="row" style="height: 15%"></div>
<div class="row" style="height: 70%">
<div class="col-md-3 ml-auto mr-auto">
<div class="card">
<div class="card-header">
<h4 class="card-title">登录</h4>
</div>
<form action="/login" method="post">
<div class="card-body">
<div class="form-group">
<label for="username">用户名</label>
<input type="text" class="form-control" id="username" placeholder="这里输入用户名">
</div>
<div class="form-group">
<label for="password">密码</label>
<input type="password" class="form-control" id="password" placeholder="这里输入密码">
</div>
</div>
<div class="card-action">
<button type="submit" class="btn btn-primary btn-block"><b>登录</b></button>
</div>
</form>
</div>
</div>
</div>
<div class="row" style="height: 15%"></div>
<div th:include="layout::custom-template"></div>
</div>
</div>
<div th:include="layout::js"></div>
</body>
</html>