登陆/注册

master
panqihua 5 years ago
parent b000f0c711
commit 4eb7a4d7c5
  1. 6
      .gitattributes
  2. 31
      .gitignore
  3. 21
      HELP.md
  4. 48
      build.gradle
  5. BIN
      gradle/wrapper/gradle-wrapper.jar
  6. 4
      gradle/wrapper/gradle-wrapper.properties
  7. 51
      gradlew
  8. 18
      gradlew.bat
  9. 9
      settings.gradle
  10. 13
      src/main/java/com/community/pocket/DemoApplication.java
  11. 6
      src/main/java/com/community/pocket/Result.java
  12. 78
      src/main/java/com/community/pocket/api/ManagerController.java
  13. 17
      src/main/java/com/community/pocket/domain/Forum.java
  14. 56
      src/main/java/com/community/pocket/domain/Manager.java
  15. 43
      src/main/java/com/community/pocket/domain/Res.java
  16. 43
      src/main/java/com/community/pocket/domain/Token.java
  17. 22
      src/main/java/com/community/pocket/domain/form/ManagerLogin.java
  18. 54
      src/main/java/com/community/pocket/domain/form/ManagerRegister.java
  19. 9
      src/main/java/com/community/pocket/repository/ForumRepo.java
  20. 47
      src/main/java/com/community/pocket/repository/ManagerDao.java
  21. 9
      src/main/java/com/community/pocket/repository/ManagerRepo.java
  22. 3
      src/main/resources/application.properties
  23. 4
      src/main/resources/application.yaml
  24. 13
      src/test/java/com/community/pocket/DemoApplicationTests.java

6
.gitattributes vendored

@ -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

31
.gitignore vendored

@ -1,7 +1,32 @@
# Ignore Gradle project-specific cache directory HELP.md
.gradle .gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**
# Ignore Gradle build output directory ### STS ###
build .apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.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 { plugins {
// Apply the java plugin to add support for Java id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'java' id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
// Apply the application plugin to add support for building a CLI application.
id 'application'
} }
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories { repositories {
// Use jcenter for resolving dependencies. maven {url 'https://maven.aliyun.com/repository/public'}
// You can declare any Maven/Ivy/file repository here. maven {url 'https://maven.aliyun.com/repository/jcenter'}
jcenter() mavenLocal()
mavenCentral()
} }
dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:28.1-jre'
// Use JUnit test framework dependencies {
testImplementation 'junit:junit:4.12' 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 { test {
// Define the main class for the application. useJUnitPlatform()
mainClassName = 'PocketCommunityServer.App'
} }

Binary file not shown.

@ -1,5 +1,5 @@
#Thu Feb 20 14:24:39 CST 2020 #Fri Feb 21 06:30:36 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

51
gradlew vendored

@ -1,21 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################## ##############################################################################
## ##
## Gradle start up script for UN*X ## Gradle start up script for UN*X
@ -44,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD="maximum"
@ -125,8 +109,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin or MSYS, switch paths to Windows format before running java # For Cygwin, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
@ -154,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=`expr $i + 1` i=$((i+1))
done done
case $i in case $i in
0) set -- ;; (0) set -- ;;
1) set -- "$args0" ;; (1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;; (2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;; (3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
@ -175,9 +159,14 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " " echo " "
} }
APP_ARGS=`save "$@"` APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules # Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@" exec "$JAVACMD" "$@"

18
gradlew.bat vendored

@ -1,19 +1,3 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -30,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS=
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome

@ -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' 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…
Cancel
Save