parent
b000f0c711
commit
4eb7a4d7c5
@ -1,6 +0,0 @@ |
||||
# |
||||
# https://help.github.com/articles/dealing-with-line-endings/ |
||||
# |
||||
# These are explicitly windows files and should use crlf |
||||
*.bat text eol=crlf |
||||
|
@ -1,7 +1,32 @@ |
||||
# Ignore Gradle project-specific cache directory |
||||
HELP.md |
||||
.gradle |
||||
build/ |
||||
!gradle/wrapper/gradle-wrapper.jar |
||||
!**/src/main/** |
||||
!**/src/test/** |
||||
|
||||
# Ignore Gradle build output directory |
||||
build |
||||
### STS ### |
||||
.apt_generated |
||||
.classpath |
||||
.factorypath |
||||
.project |
||||
.settings |
||||
.springBeans |
||||
.sts4-cache |
||||
|
||||
.idea |
||||
### IntelliJ IDEA ### |
||||
.idea |
||||
*.iws |
||||
*.iml |
||||
*.ipr |
||||
out/ |
||||
|
||||
### NetBeans ### |
||||
/nbproject/private/ |
||||
/nbbuild/ |
||||
/dist/ |
||||
/nbdist/ |
||||
/.nb-gradle/ |
||||
|
||||
### VS Code ### |
||||
.vscode/ |
||||
|
@ -0,0 +1,21 @@ |
||||
# Getting Started |
||||
|
||||
### Reference Documentation |
||||
For further reference, please consider the following sections: |
||||
|
||||
* [Official Gradle documentation](https://docs.gradle.org) |
||||
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/gradle-plugin/reference/html/) |
||||
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications) |
||||
|
||||
### Guides |
||||
The following guides illustrate how to use some features concretely: |
||||
|
||||
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) |
||||
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) |
||||
* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) |
||||
|
||||
### Additional Links |
||||
These additional references should also help you: |
||||
|
||||
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle) |
||||
|
@ -1,35 +1,33 @@ |
||||
/* |
||||
* This file was generated by the Gradle 'init' task. |
||||
* |
||||
* This generated file contains a sample Java project to get you started. |
||||
* For more details take a look at the Java Quickstart chapter in the Gradle |
||||
* User Manual available at https://docs.gradle.org/6.1.1/userguide/tutorial_java_projects.html |
||||
*/ |
||||
|
||||
|
||||
plugins { |
||||
// Apply the java plugin to add support for Java |
||||
id 'java' |
||||
|
||||
// Apply the application plugin to add support for building a CLI application. |
||||
id 'application' |
||||
id 'org.springframework.boot' version '2.2.4.RELEASE' |
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE' |
||||
id 'java' |
||||
} |
||||
|
||||
group = 'com.example' |
||||
version = '0.0.1-SNAPSHOT' |
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8 |
||||
targetCompatibility = JavaVersion.VERSION_1_8 |
||||
|
||||
repositories { |
||||
// Use jcenter for resolving dependencies. |
||||
// You can declare any Maven/Ivy/file repository here. |
||||
jcenter() |
||||
maven {url 'https://maven.aliyun.com/repository/public'} |
||||
maven {url 'https://maven.aliyun.com/repository/jcenter'} |
||||
mavenLocal() |
||||
mavenCentral() |
||||
} |
||||
|
||||
dependencies { |
||||
// This dependency is used by the application. |
||||
implementation 'com.google.guava:guava:28.1-jre' |
||||
|
||||
// Use JUnit test framework |
||||
testImplementation 'junit:junit:4.12' |
||||
dependencies { |
||||
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' |
||||
implementation 'org.springframework.boot:spring-boot-starter-data-rest' |
||||
implementation 'org.springframework.boot:spring-boot-starter-web' |
||||
testImplementation 'org.springframework.boot:spring-boot-devtools' |
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') { |
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' |
||||
} |
||||
} |
||||
|
||||
application { |
||||
// Define the main class for the application. |
||||
mainClassName = 'PocketCommunityServer.App' |
||||
test { |
||||
useJUnitPlatform() |
||||
} |
||||
|
Binary file not shown.
@ -1,10 +1 @@ |
||||
/* |
||||
* This file was generated by the Gradle 'init' task. |
||||
* |
||||
* The settings file is used to specify which projects to include in your build. |
||||
* |
||||
* Detailed information about configuring a multi-project build in Gradle can be found |
||||
* in the user manual at https://docs.gradle.org/6.1.1/userguide/multi_project_builds.html |
||||
*/ |
||||
|
||||
rootProject.name = 'PocketCommunityServer' |
||||
|
@ -0,0 +1,13 @@ |
||||
package com.community.pocket; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
||||
@SpringBootApplication |
||||
public class DemoApplication { |
||||
|
||||
public static void main(String[] args) { |
||||
SpringApplication.run(DemoApplication.class, args); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,6 @@ |
||||
package com.community.pocket; |
||||
|
||||
public enum Result { |
||||
OK, |
||||
FAIL |
||||
} |
@ -0,0 +1,78 @@ |
||||
package com.community.pocket.api; |
||||
|
||||
import com.community.pocket.Result; |
||||
import com.community.pocket.domain.Manager; |
||||
import com.community.pocket.domain.Res; |
||||
import com.community.pocket.domain.Token; |
||||
import com.community.pocket.domain.form.ManagerLogin; |
||||
import com.community.pocket.domain.form.ManagerRegister; |
||||
import com.community.pocket.repository.ManagerDao; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.util.DigestUtils; |
||||
import org.springframework.util.StringUtils; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.util.Calendar; |
||||
import java.util.Date; |
||||
|
||||
@RestController |
||||
@RequestMapping("/api/manager") |
||||
@CrossOrigin("http://localhost:4200") |
||||
public class ManagerController { |
||||
|
||||
@Autowired |
||||
private ManagerDao managerDao; |
||||
|
||||
// 登陆
|
||||
@PostMapping("login") |
||||
@ResponseBody |
||||
public Res<Token> login(@RequestBody ManagerLogin managerLogin){ |
||||
if(StringUtils.isEmpty(managerLogin.getManagerName())){ |
||||
return new Res<>(Result.FAIL,"管理员不能为空!",null); |
||||
}else if(StringUtils.isEmpty(managerLogin.getPassword())){ |
||||
return new Res<>(Result.FAIL,"密码不能为空!",null); |
||||
}else if(!managerDao.login(managerLogin)){ |
||||
return new Res<>(Result.FAIL,"账号或密码错误!",null); |
||||
} |
||||
else{ |
||||
Token token=new Token(); |
||||
Calendar c=Calendar.getInstance(); |
||||
c.setTime(new Date()); |
||||
token.setCreateTime(c.getTimeInMillis()); |
||||
c.add(Calendar.HOUR,1); |
||||
token.setUseTime(c.getTimeInMillis()); |
||||
token.setToken(DigestUtils.md5DigestAsHex((token.getCreateTime()+""+token.getUseTime()+"").getBytes())); |
||||
return new Res<>(Result.OK,"登陆成功",token); |
||||
} |
||||
} |
||||
|
||||
// 注册
|
||||
@PostMapping("register") |
||||
@ResponseBody |
||||
public Res<String> register(@RequestBody ManagerRegister manager){ |
||||
if(StringUtils.isEmpty(manager.getManagerName())){ |
||||
return new Res<>(Result.FAIL,"管理员不能为空",null); |
||||
}else if(StringUtils.isEmpty(manager.getPassword())){ |
||||
return new Res<>(Result.FAIL,"密码不能为空",null); |
||||
}else if(StringUtils.isEmpty(manager.getConfirmPassword())){ |
||||
return new Res<>(Result.FAIL,"确认密码不能为空",null); |
||||
}else if(!manager.getPassword().equals(manager.getConfirmPassword())){ |
||||
return new Res<>(Result.FAIL,"两次密码输入不一致",null); |
||||
}else if(StringUtils.isEmpty(manager.getMobie())){ |
||||
return new Res<>(Result.FAIL,"手机号不能为空",null); |
||||
}else if(StringUtils.isEmpty(manager.getEmail())){ |
||||
return new Res<>(Result.FAIL,"邮箱不能为空",null); |
||||
}else if(managerDao.hasUser(manager.getManagerName())){ |
||||
return new Res<>(Result.FAIL,"用户已存在",null); |
||||
}else{ |
||||
Manager m=new Manager(); |
||||
m.setManagerName(manager.getManagerName()); |
||||
m.setPassword(DigestUtils.md5DigestAsHex(manager.getPassword().getBytes())); |
||||
m.setMobie(manager.getMobie()); |
||||
m.setEmail(manager.getEmail()); |
||||
managerDao.save(m); |
||||
return new Res<>(Result.OK,"注册成功",null); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.community.pocket.domain; |
||||
|
||||
import org.springframework.data.annotation.Id; |
||||
|
||||
//论坛贴
|
||||
public class Forum { |
||||
@Id |
||||
private String id; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
} |
@ -0,0 +1,56 @@ |
||||
package com.community.pocket.domain; |
||||
|
||||
import org.springframework.data.annotation.Id; |
||||
|
||||
public class Manager { |
||||
@Id |
||||
private String id; |
||||
// 管理员
|
||||
private String managerName; |
||||
// 密码
|
||||
private String password; |
||||
// 手机号
|
||||
private Long mobie; |
||||
// 邮箱
|
||||
private String email; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getManagerName() { |
||||
return managerName; |
||||
} |
||||
|
||||
public void setManagerName(String managerName) { |
||||
this.managerName = managerName; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public Long getMobie() { |
||||
return mobie; |
||||
} |
||||
|
||||
public void setMobie(Long mobie) { |
||||
this.mobie = mobie; |
||||
} |
||||
|
||||
public String getEmail() { |
||||
return email; |
||||
} |
||||
|
||||
public void setEmail(String email) { |
||||
this.email = email; |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
package com.community.pocket.domain; |
||||
|
||||
import com.community.pocket.Result; |
||||
|
||||
public class Res<T> { |
||||
// 响应码
|
||||
private Result result; |
||||
private String message; |
||||
private T body; |
||||
|
||||
public Res() { |
||||
} |
||||
|
||||
public Res(Result result, String message, T body) { |
||||
this.result = result; |
||||
this.message = message; |
||||
this.body = body; |
||||
} |
||||
|
||||
public Result getResult() { |
||||
return result; |
||||
} |
||||
|
||||
public void setResult(Result result) { |
||||
this.result = result; |
||||
} |
||||
|
||||
public String getMessage() { |
||||
return message; |
||||
} |
||||
|
||||
public void setMessage(String message) { |
||||
this.message = message; |
||||
} |
||||
|
||||
public T getBody() { |
||||
return body; |
||||
} |
||||
|
||||
public void setBody(T body) { |
||||
this.body = body; |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
package com.community.pocket.domain; |
||||
|
||||
import org.springframework.data.annotation.Id; |
||||
|
||||
public class Token { |
||||
@Id |
||||
private String id; |
||||
private String token; |
||||
private Long createTime; |
||||
private Long useTime; |
||||
|
||||
public String getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(String id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getToken() { |
||||
return token; |
||||
} |
||||
|
||||
public void setToken(String token) { |
||||
this.token = token; |
||||
} |
||||
|
||||
public Long getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Long createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
public Long getUseTime() { |
||||
return useTime; |
||||
} |
||||
|
||||
public void setUseTime(Long useTime) { |
||||
this.useTime = useTime; |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package com.community.pocket.domain.form; |
||||
|
||||
public class ManagerLogin { |
||||
private String managerName; |
||||
private String password; |
||||
|
||||
public String getManagerName() { |
||||
return managerName; |
||||
} |
||||
|
||||
public void setManagerName(String managerName) { |
||||
this.managerName = managerName; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
} |
@ -0,0 +1,54 @@ |
||||
package com.community.pocket.domain.form; |
||||
|
||||
public class ManagerRegister { |
||||
// 管理员
|
||||
private String managerName; |
||||
// 密码
|
||||
private String password; |
||||
// 确认密码
|
||||
private String confirmPassword; |
||||
// 手机号
|
||||
private Long mobie; |
||||
// 邮箱
|
||||
private String email; |
||||
|
||||
public String getManagerName() { |
||||
return managerName; |
||||
} |
||||
|
||||
public void setManagerName(String managerName) { |
||||
this.managerName = managerName; |
||||
} |
||||
|
||||
public String getPassword() { |
||||
return password; |
||||
} |
||||
|
||||
public void setPassword(String password) { |
||||
this.password = password; |
||||
} |
||||
|
||||
public String getConfirmPassword() { |
||||
return confirmPassword; |
||||
} |
||||
|
||||
public void setConfirmPassword(String confirmPassword) { |
||||
this.confirmPassword = confirmPassword; |
||||
} |
||||
|
||||
public Long getMobie() { |
||||
return mobie; |
||||
} |
||||
|
||||
public void setMobie(Long mobie) { |
||||
this.mobie = mobie; |
||||
} |
||||
|
||||
public String getEmail() { |
||||
return email; |
||||
} |
||||
|
||||
public void setEmail(String email) { |
||||
this.email = email; |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
package com.community.pocket.repository; |
||||
|
||||
import com.community.pocket.domain.Forum; |
||||
import org.springframework.data.mongodb.repository.MongoRepository; |
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; |
||||
|
||||
@RepositoryRestResource |
||||
public interface ForumRepo extends MongoRepository<Forum,String> { |
||||
} |
@ -0,0 +1,47 @@ |
||||
package com.community.pocket.repository; |
||||
|
||||
import com.community.pocket.domain.Manager; |
||||
import com.community.pocket.domain.form.ManagerLogin; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.mongodb.core.MongoTemplate; |
||||
import org.springframework.data.mongodb.core.query.Criteria; |
||||
import org.springframework.data.mongodb.core.query.Query; |
||||
import org.springframework.stereotype.Repository; |
||||
import org.springframework.util.DigestUtils; |
||||
|
||||
@Repository |
||||
public class ManagerDao { |
||||
|
||||
@Autowired |
||||
private MongoTemplate mongoTemplate; |
||||
|
||||
public boolean login(ManagerLogin managerLogin){ |
||||
Criteria criteria=Criteria.where("managerName").is(managerLogin.getManagerName()); |
||||
try { |
||||
Manager manager= mongoTemplate.findOne(new Query(criteria), Manager.class); |
||||
return manager!=null&&manager.getManagerName().equals(managerLogin.getManagerName())&&manager.getPassword().equals(DigestUtils.md5DigestAsHex(managerLogin.getPassword().getBytes())); |
||||
} catch (Exception e) { |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
|
||||
// 查用户
|
||||
public boolean hasUser(String name){ |
||||
try { |
||||
Manager manager=mongoTemplate.findOne(new Query(Criteria.where("managerName").is(name)),Manager.class); |
||||
return manager!=null; |
||||
} catch (Exception e) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public boolean save(Manager manager){ |
||||
try { |
||||
mongoTemplate.save(manager); |
||||
return true; |
||||
} catch (Exception e) { |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
package com.community.pocket.repository; |
||||
|
||||
import com.community.pocket.domain.Manager; |
||||
import org.springframework.data.mongodb.repository.MongoRepository; |
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; |
||||
|
||||
@RepositoryRestResource |
||||
public interface ManagerRepo extends MongoRepository<Manager,String> { |
||||
} |
@ -0,0 +1,3 @@ |
||||
#spring.data.mongodb.uri=mongodb://localhost:27017/demo |
||||
#spring.datasource |
||||
#spring.datasource.url=mongodb://localhost:27017/demo |
@ -0,0 +1,4 @@ |
||||
spring: |
||||
data: |
||||
mongodb: |
||||
database: demo |
@ -0,0 +1,13 @@ |
||||
package com.community.pocket; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
||||
@SpringBootTest |
||||
class DemoApplicationTests { |
||||
|
||||
@Test |
||||
void contextLoads() { |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue