22 次程式碼提交

作者 SHA1 備註 提交日期
  JaseG256 b5b0e84d4c fixed merge conflicts 6 年之前
  JaseG256 c12c32699b Before merge 6 年之前
  JaseG256 f330628bee Cleaned up SecurityConfig 6 年之前
  JaseG256 8628192275 Test failed. Still trying to work out secured endpoints 6 年之前
  JaseG256 cec5ef165d Adding a few methods to userRepo 6 年之前
  JaseG256 ae7398b270 Working out the Chat and Message entities 6 年之前
  JaseG256 2aa92da478 Roles being assigned successsfully 6 年之前
  JaseG256 8371758f57 Merge branch 'lost' of https://git.zipcode.rocks/hallinanc/ZipTeam into lost 6 年之前
  JaseG256 c2c537ee32 Roles not being set upon signup 6 年之前
  JaseG256 36c94a8069 Udated Message Class 6 年之前
  JaseG256 c928a5e936 Updated Chat class 6 年之前
  JaseG256 d87e3ecf3f About to change the Chat class 6 年之前
  JaseG256 0febee3706 Config for user auditing added 6 年之前
  JaseG256 f67ba31b24 User authentication working but role not being set upon signup 6 年之前
  JaseG256 61722ac635 AuthController for user login added 6 年之前
  JaseG256 f8b4d4a179 Custom Runtime Exception classes added 6 年之前
  JaseG256 797d1950fc Request and response payloads added 6 年之前
  JaseG256 c0beff4c37 Data.sql file loads roles into DB 6 年之前
  JaseG256 9d50f731f1 DateAudit class added 6 年之前
  JaseG256 1524d4c5a0 User model working fine 6 年之前
  JaseG256 647eee84b5 Merge branch 'dev' of https://git.zipcode.rocks/hallinanc/ZipTeam into dev 6 年之前
  JaseG256 f696e9614b Merge branch 'dev' of https://git.zipcode.rocks/hallinanc/ZipTeam into dev 6 年之前
共有 61 個文件被更改,包括 4929 次插入153 次删除
  1. 二進制
      .DS_Store
  2. 5
    1
      ZipTeamOrange-ionic-UI/.sourcemaps/main.js.map
  3. 41
    0
      ZipTeamOrange-ionic-UI/.vscode/typings/cordova-ionic/plugins/keyboard.d.ts
  4. 3208
    0
      ZipTeamOrange-ionic-UI/.vscode/typings/jquery/jquery.d.ts
  5. 1
    1
      ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html
  6. 1
    1
      ZipTeamOrange-ionic-UI/src/pages/firstPage/first.ts
  7. 1
    1
      ZipTeamOrange-ionic-UI/src/providers/auth-service/auth-service.ts
  8. 3
    0
      ZipTeamOrange-ionic-UI/typings/cordova-typings.d.ts
  9. 35
    5
      ZipTeamOrange-ionic-UI/www/build/main.js
  10. 5
    1
      ZipTeamOrange-ionic-UI/www/build/main.js.map
  11. 5
    1
      ZipTeamOrange-ionic-UI/www/build/vendor.js.map
  12. 17
    1
      ZipTeamOrange-server/pom.xml
  13. 二進制
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/.DS_Store
  14. 42
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/AuditingConfig.java
  15. 97
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/SecurityConfig.java
  16. 17
    4
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/ChatController.java
  17. 8
    1
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/MessageController.java
  18. 15
    7
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/UserController.java
  19. 45
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Audit/DateAudit.java
  20. 112
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Chat.java
  21. 80
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java
  22. 49
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Role.java
  23. 6
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/RoleName.java
  24. 102
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java
  25. 27
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/ChatRepository.java
  26. 34
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/MessageRepository.java
  27. 15
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/RoleRepository.java
  28. 24
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/UserRepository.java
  29. 13
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CurrentUser.java
  30. 41
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CustomUserDetailsService.java
  31. 26
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationEntryPoint.java
  32. 58
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationFilter.java
  33. 64
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtTokenProvider.java
  34. 107
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/UserPrincipal.java
  35. 14
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/ZipTeamOrangeApplication.java
  36. 0
    52
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/Chat.java
  37. 0
    6
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/ChatRepository.java
  38. 29
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/RoleLoader.java
  39. 31
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/UserLoader.java
  40. 19
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/WebMvcConfig.java
  41. 97
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/controller/AuthController.java
  42. 15
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/AppException.java
  43. 16
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/BadRequestException.java
  44. 30
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/ResourceNotFoundException.java
  45. 0
    54
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/message/Message.java
  46. 0
    8
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/message/MessageRepository.java
  47. 38
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/model/Audit/UserDateAudit.java
  48. 17
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserIdentityAvailability.java
  49. 50
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserProfile.java
  50. 28
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserSummary.java
  51. 49
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/ChatRequest.java
  52. 27
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/LoginRequest.java
  53. 31
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/MessageRequest.java
  54. 45
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/SignUpRequest.java
  55. 27
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ApiResponse.java
  56. 4
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ChatResonse.java
  57. 6
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ChatResponse.java
  58. 26
    0
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/JwtAuthenticationResponse.java
  59. 0
    8
      ZipTeamOrange-server/src/main/java/ZipTeamOrange/user/UserRepository.java
  60. 23
    1
      ZipTeamOrange-server/src/main/resources/application.properties
  61. 3
    0
      ZipTeamOrange-server/src/main/resources/data.sql

二進制
.DS_Store 查看文件


+ 5
- 1
ZipTeamOrange-ionic-UI/.sourcemaps/main.js.map
文件差異過大導致無法顯示
查看文件


+ 41
- 0
ZipTeamOrange-ionic-UI/.vscode/typings/cordova-ionic/plugins/keyboard.d.ts 查看文件

@@ -0,0 +1,41 @@
1
+// Type definitions for Cordova Keyboard plugin
2
+// Project: https://github.com/driftyco/ionic-plugins-keyboard
3
+// Definitions by: Hendrik Maus <https://github.com/hendrikmaus>
4
+// Definitions: https://github.com/borisyankov/DefinitelyTyped
5
+
6
+declare module Ionic {
7
+  interface Keyboard {
8
+
9
+    /**
10
+     * Hide the keyboard accessory bar with the next, previous and done buttons.
11
+     *
12
+     * @param hide
13
+     */
14
+    hideKeyboardAccessoryBar(hide:boolean): void;
15
+
16
+    /**
17
+     * Close the keyboard if it is open.
18
+     */
19
+    close(): void;
20
+    
21
+    /**
22
+     * Force keyboard to be shown on Android.
23
+     * This typically helps if autofocus on a text element does not pop up the keyboard automatically
24
+     * 
25
+     * Supported Platforms: Android, Blackberry 10
26
+     */
27
+    show(): void;
28
+
29
+    /**
30
+     * Disable native scrolling, useful if you are using JavaScript to scroll
31
+     *
32
+     * @param disbale
33
+     */
34
+    disableScroll(disbale:boolean): void;
35
+
36
+    /**
37
+     * Whether or not the keyboard is currently visible.
38
+     */
39
+    isVisible: boolean;
40
+  }
41
+}

+ 3208
- 0
ZipTeamOrange-ionic-UI/.vscode/typings/jquery/jquery.d.ts
文件差異過大導致無法顯示
查看文件


+ 1
- 1
ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html 查看文件

@@ -39,7 +39,7 @@
39 39
     </form>
40 40
     <ion-row>
41 41
       <ion-col color="secondary">
42
-        <button ion-button class="register-btn" block clear (click)="createAccount()">Create Account</button>
42
+        <button ion-button class="register-btn" block clear (click)="createAccount(registerForm)">Create Account</button>
43 43
       </ion-col>
44 44
     </ion-row>
45 45
   </div>

+ 1
- 1
ZipTeamOrange-ionic-UI/src/pages/firstPage/first.ts 查看文件

@@ -33,7 +33,7 @@ export class FirstPage {
33 33
     this.authService.postData(createAccountInfo).then((result) => {
34 34
       this.responseData = result;
35 35
       console.log(createAccountInfo);
36
-      if(!this.responseData.createAccountInfo){
36
+      if(this.responseData.createAccountInfo){
37 37
         this.navCtrl.push(ChatPage);
38 38
       }else{
39 39
         console.log("check your info");

+ 1
- 1
ZipTeamOrange-ionic-UI/src/providers/auth-service/auth-service.ts 查看文件

@@ -19,7 +19,7 @@ export class AuthServiceProvider {
19 19
   postData(createAccountInfo: any){
20 20
     return new Promise((resolve, reject) => {
21 21
 
22
-      this.http.post(`https://arcane-ridge.herokuapp.com/user/add`, createAccountInfo, {responseType: 'text'}).subscribe((res: any) => {
22
+      this.http.post(`https://arcane-ridge.herokuapp.com/api/auth/signup`, createAccountInfo, {responseType: 'text'}).subscribe((res: any) => {
23 23
       console.log(JSON.parse(res))
24 24
       resolve(JSON.parse(res));
25 25
       }, (err) => {

+ 3
- 0
ZipTeamOrange-ionic-UI/typings/cordova-typings.d.ts 查看文件

@@ -0,0 +1,3 @@
1
+
2
+/// <reference path="../.vscode/typings/cordova-ionic/plugins/keyboard.d.ts"/>
3
+/// <reference path="../.vscode/typings/jquery/jquery.d.ts"/>

+ 35
- 5
ZipTeamOrange-ionic-UI/www/build/main.js 查看文件

@@ -59,7 +59,11 @@ var ChatPage = /** @class */ (function () {
59 59
     ], ChatPage.prototype, "messages", void 0);
60 60
     ChatPage = __decorate([
61 61
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
62
+<<<<<<< HEAD
63
+            selector: 'page-chat',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/chat/chat.html"*/'<!--\n  Generated template for the ChatPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n  <ion-navbar>\n    <ion-title>chatPage</ion-title>\n  </ion-navbar>\n\n</ion-header>\n<!-- *ngFor="let m of msg">{{ m }} -->\n\n<ion-content padding >\n  <div *ngFor="let m of msg">\n    {{ m.message }}\n  </div>\n\n  <form  #test1="ngForm" ng-submit="send(test1.value)">\n    <ion-textarea  type="text" name="message" [(ngModel)]="test" ></ion-textarea>\n    <button ion-button (click)="send(test1.value)"(click)="getMessages()">send</button>\n  </form>\n</ion-content>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/chat/chat.html"*/,
64
+=======
62 65
             selector: 'page-chat',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/chat/chat.html"*/'<!--\n  Generated template for the ChatPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n  <ion-navbar>\n    <ion-title>chatPage</ion-title>\n  </ion-navbar>\n\n</ion-header>\n<!-- *ngFor="let m of msg">{{ m }} -->\n\n<ion-content padding >\n  <div *ngFor="let m of msg" class="message-wrapper">\n    <div class="name">\n      <b>{{m.username}}Nhu</b> <span class="timestamp"><small>{{m.timestamp}}8:40</small></span> <div class="message">{{m.message}}</div>  \n      <p></p>    \n    </div>\n  </div>\n\n  <form  #test1="ngForm" ng-submit="send(test1.value)">\n    <ion-textarea  type="text" name="message" [(ngModel)]="test" class="user-message"></ion-textarea>\n    <button ion-button (click)="send(test1.value)" >send</button>\n  </form>\n</ion-content>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/chat/chat.html"*/,
66
+>>>>>>> e9af7a6a8011fcb914952fcfb97bc9d9550b2637
63 67
         }),
64 68
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */], __WEBPACK_IMPORTED_MODULE_2__providers_message_service_message_service__["a" /* MessageServiceProvider */]])
65 69
     ], ChatPage);
@@ -105,6 +109,23 @@ var SignUpPage = /** @class */ (function () {
105 109
         this.toastCtrl = toastCtrl;
106 110
         this.user = {};
107 111
     }
112
+<<<<<<< HEAD
113
+    FirstPage.prototype.ionViewDidLoad = function () {
114
+        console.log('ionViewDidLoad FirstPage');
115
+    };
116
+    FirstPage.prototype.loginButton = function (createAccountInfo) {
117
+        var _this = this;
118
+        this.authService.postData(createAccountInfo).then(function (result) {
119
+            _this.responseData = result;
120
+            console.log(createAccountInfo);
121
+            if (_this.responseData.createAccountInfo) {
122
+                _this.navCtrl.push(__WEBPACK_IMPORTED_MODULE_4__chat_chat__["a" /* ChatPage */]);
123
+            }
124
+            else {
125
+                console.log("check your info");
126
+            }
127
+        }).catch(console.log);
128
+=======
108 129
     // ngOnInit(){
109 130
     //   this.loadUsers();
110 131
     // }
@@ -116,6 +137,7 @@ var SignUpPage = /** @class */ (function () {
116 137
     // }
117 138
     SignUpPage.prototype.ionViewDidLoad = function () {
118 139
         console.log('ionViewDidLoad SignUpPage');
140
+>>>>>>> e9af7a6a8011fcb914952fcfb97bc9d9550b2637
119 141
     };
120 142
     SignUpPage.prototype.save = function (createAccountInfo) {
121 143
         //  console.log(createAccountInfo)
@@ -123,7 +145,11 @@ var SignUpPage = /** @class */ (function () {
123 145
     };
124 146
     SignUpPage = __decorate([
125 147
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
148
+<<<<<<< HEAD
149
+            selector: 'page-first',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html"*/'<!--\n  Generated template for the FirstPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n  <ion-navbar color="primary">\n    <button menuToggle ion- button icon-only>\n      <ion-icon name ="menu"></ion-icon>\n    </button>\n    <ion-title text-center>ZipTeamOrange</ion-title>\n  </ion-navbar>\n\n</ion-header>\n\n\n<ion-content padding>\n  <h4>Welcome to this page</h4>\n  <div class="login-box">\n    <form #registerForm="ngForm" ng-submit="loginButton(registerForm.value)" >\n      <ion-row>\n        <ion-col>\n          <ion-list inset>\n            <ion-item>\n              <ion-input type="text" placeholder="Username" name="userName" required [(ngModel)]="Username" ></ion-input>\n            </ion-item>\n            <ion-item>\n              <ion-input type="password" placeholder="Password" name="password" required [(ngModel)]="password"></ion-input>\n            </ion-item>\n          </ion-list>\n        </ion-col>\n      </ion-row>\n      <ion-row>\n        <ion-col class="signup-col">\n          <button ion-button class="submit-btn" full type="submit" [disabled]="!registerForm.form.valid" (click)="loginButton(registerForm.value)">Login</button>\n        </ion-col>\n      </ion-row>\n    </form>\n    <ion-row>\n      <ion-col color="secondary">\n        <button ion-button class="register-btn" block clear (click)="createAccount()">Create Account</button>\n      </ion-col>\n    </ion-row>\n  </div>\n  \n</ion-content>'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html"*/,
150
+=======
126 151
             selector: 'page-sign-up',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/sign-up/sign-up.html"*/'<!--\n  Generated template for the SignUpPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n    <ion-navbar color="primary">\n      <ion-title>sign-up</ion-title>\n    </ion-navbar>\n  \n  </ion-header>\n  \n  \n  <ion-content padding>\n      <div class="signUp-box">\n      <form #registerForm="ngForm" ng-submit="save(registerForm.value)">\n        <ion-row>\n          <ion-col>\n            <ion-list inset>\n              <ion-item>\n                <ion-input type="text" placeholder="Username" name="userName" required [(ngModel)]="Username" ></ion-input>\n              </ion-item>\n              <ion-item>\n                  <ion-input type="text" placeholder="Email" name="email" required [(ngModel)]="Email" ></ion-input>\n                </ion-item>\n              <ion-item>\n                <ion-input type="password" placeholder="Password" name="password" required [(ngModel)]="password"></ion-input>\n              </ion-item>\n            </ion-list>\n          </ion-col>\n        </ion-row>\n        <ion-row>\n          <ion-col class="signup-col">\n            <button ion-button class="submit-btn" full type="submit" (click)="save(registerForm.value)" [disabled]="!registerForm.form.valid">Create Account</button>\n          </ion-col>\n        </ion-row>\n      </form>\n    \n    </div>\n  \n  </ion-content>\n  \n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/sign-up/sign-up.html"*/,
152
+>>>>>>> e9af7a6a8011fcb914952fcfb97bc9d9550b2637
127 153
         }),
128 154
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */], __WEBPACK_IMPORTED_MODULE_2__providers_api_service_api_service__["a" /* ApiServiceProvider */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["h" /* ToastController */]])
129 155
     ], SignUpPage);
@@ -192,7 +218,11 @@ var FirstPage = /** @class */ (function () {
192 218
     };
193 219
     FirstPage = __decorate([
194 220
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
221
+<<<<<<< HEAD
222
+            selector: 'page-sign-up',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/sign-up/sign-up.html"*/'<!--\n  Generated template for the SignUpPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n\n    <ion-navbar color="primary">\n      <ion-title>sign-up</ion-title>\n    </ion-navbar>\n  \n  </ion-header>\n  \n  \n  <ion-content padding>\n      <div class="signUp-box">\n      <form #registerForm="ngForm" ng-submit="save(registerForm.value)">\n        <ion-row>\n          <ion-col>\n            <ion-list inset>\n              <ion-item>\n                <ion-input type="text" placeholder="Username" name="userName" required [(ngModel)]="Username" ></ion-input>\n              </ion-item>\n              <ion-item>\n                  <ion-input type="text" placeholder="Email" name="email" required [(ngModel)]="Email" ></ion-input>\n                </ion-item>\n              <ion-item>\n                <ion-input type="password" placeholder="Password" name="password" required [(ngModel)]="password"></ion-input>\n              </ion-item>\n            </ion-list>\n          </ion-col>\n        </ion-row>\n        <ion-row>\n          <ion-col class="signup-col">\n            <button ion-button class="submit-btn" full type="submit" (click)="save(registerForm.value)" [disabled]="!registerForm.form.valid">Create Account</button>\n          </ion-col>\n        </ion-row>\n      </form>\n    \n    </div>\n  \n  </ion-content>\n  \n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/sign-up/sign-up.html"*/,
223
+=======
195 224
             selector: 'page-first',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html"*/'<!--\n  Generated template for the FirstPage page.\n\n  See http://ionicframework.com/docs/components/#navigation for more info on\n  Ionic pages and navigation.\n-->\n<ion-header>\n  <ion-navbar color="primary">\n    <button menuToggle ion- button icon-only>\n      <ion-icon name ="menu"></ion-icon>\n    </button>\n    <ion-title text-center>ZipTeamOrange</ion-title>\n  </ion-navbar>\n\n</ion-header>\n\n\n<ion-content padding>\n  <h4>Welcome to this page</h4>\n  <div class="login-box">\n    <form #registerForm="ngForm" ng-submit="loginButton(registerForm.value)" >\n      <ion-row>\n        <ion-col>\n          <ion-list inset>\n            <ion-item>\n              <ion-input type="text" placeholder="Username" name="userName" required [(ngModel)]="Username" ></ion-input>\n            </ion-item>\n            <ion-item>\n              <ion-input type="password" placeholder="Password" name="password" required [(ngModel)]="password"></ion-input>\n            </ion-item>\n          </ion-list>\n        </ion-col>\n      </ion-row>\n      <ion-row>\n        <ion-col class="signup-col">\n          <button ion-button class="submit-btn" full type="submit" [disabled]="!registerForm.form.valid" (click)="loginButton(registerForm.value)">Login</button>\n        </ion-col>\n      </ion-row>\n    </form>\n    <ion-row>\n      <ion-col color="secondary">\n        <button ion-button class="register-btn" block clear (click)="createAccount()">Create Account</button>\n      </ion-col>\n    </ion-row>\n  </div>\n  \n</ion-content>'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/firstPage/first.html"*/,
225
+>>>>>>> e9af7a6a8011fcb914952fcfb97bc9d9550b2637
196 226
         }),
197 227
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */], __WEBPACK_IMPORTED_MODULE_1_ionic_angular__["f" /* NavParams */], __WEBPACK_IMPORTED_MODULE_3__providers_auth_service_auth_service__["a" /* AuthServiceProvider */]])
198 228
     ], FirstPage);
@@ -436,7 +466,7 @@ var TabsPage = /** @class */ (function () {
436 466
         this.tab4Root = __WEBPACK_IMPORTED_MODULE_2__contact_contact__["a" /* ContactPage */];
437 467
     }
438 468
     TabsPage = __decorate([
439
-        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/tabs/tabs.html"*/'<ion-tabs>\n  <ion-tab [root]="tab1Root" tabTitle="Log"  tabIcon="sign-in"></ion-tab>\n  <ion-tab [root]="tab2Root" tabTitle="Home" tabIcon="home"></ion-tab>\n  <ion-tab [root]="tab3Root" tabTitle="About" tabIcon="information-circle"></ion-tab>\n  <ion-tab [root]="tab4Root" tabTitle="Contact" tabIcon="contacts"></ion-tab>\n</ion-tabs>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/tabs/tabs.html"*/
469
+        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/tabs/tabs.html"*/'<ion-tabs>\n  <ion-tab [root]="tab1Root" tabTitle="Log"  tabIcon="sign-in"></ion-tab>\n  <ion-tab [root]="tab2Root" tabTitle="Home" tabIcon="home"></ion-tab>\n  <ion-tab [root]="tab3Root" tabTitle="About" tabIcon="information-circle"></ion-tab>\n  <ion-tab [root]="tab4Root" tabTitle="Contact" tabIcon="contacts"></ion-tab>\n</ion-tabs>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/tabs/tabs.html"*/
440 470
         }),
441 471
         __metadata("design:paramtypes", [])
442 472
     ], TabsPage);
@@ -471,7 +501,7 @@ var AboutPage = /** @class */ (function () {
471 501
     }
472 502
     AboutPage = __decorate([
473 503
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
474
-            selector: 'page-about',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/about/about.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>\n      About\n    </ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content padding>\n\n</ion-content>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/about/about.html"*/
504
+            selector: 'page-about',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/about/about.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>\n      About\n    </ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content padding>\n\n</ion-content>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/about/about.html"*/
475 505
         }),
476 506
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */]])
477 507
     ], AboutPage);
@@ -506,7 +536,7 @@ var ContactPage = /** @class */ (function () {
506 536
     }
507 537
     ContactPage = __decorate([
508 538
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
509
-            selector: 'page-contact',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/contact/contact.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>\n      Contact\n    </ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content>\n  <ion-list>\n    <ion-list-header>Follow us on Twitter</ion-list-header>\n    <ion-item>\n      <ion-icon name="ionic" item-start></ion-icon>\n      @ionicframework\n    </ion-item>\n  </ion-list>\n</ion-content>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/contact/contact.html"*/
539
+            selector: 'page-contact',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/contact/contact.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>\n      Contact\n    </ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content>\n  <ion-list>\n    <ion-list-header>Follow us on Twitter</ion-list-header>\n    <ion-item>\n      <ion-icon name="ionic" item-start></ion-icon>\n      @ionicframework\n    </ion-item>\n  </ion-list>\n</ion-content>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/contact/contact.html"*/
510 540
         }),
511 541
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */]])
512 542
     ], ContactPage);
@@ -541,7 +571,7 @@ var HomePage = /** @class */ (function () {
541 571
     }
542 572
     HomePage = __decorate([
543 573
         Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({
544
-            selector: 'page-home',template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/home/home.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>Home</ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content padding>\n  <h2>Welcome to Ionic!</h2>\n  <p>\n    This starter project comes with simple tabs-based layout for apps\n    that are going to primarily use a Tabbed UI.\n  </p>\n  <p>\n    Take a look at the <code>src/pages/</code> directory to add or change tabs,\n    update any existing page or create new pages.\n  </p>\n</ion-content>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/home/home.html"*/
574
+            selector: 'page-home',template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/home/home.html"*/'<ion-header>\n  <ion-navbar>\n    <ion-title>Home</ion-title>\n  </ion-navbar>\n</ion-header>\n\n<ion-content padding>\n  <h2>Welcome to Ionic!</h2>\n  <p>\n    This starter project comes with simple tabs-based layout for apps\n    that are going to primarily use a Tabbed UI.\n  </p>\n  <p>\n    Take a look at the <code>src/pages/</code> directory to add or change tabs,\n    update any existing page or create new pages.\n  </p>\n</ion-content>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/pages/home/home.html"*/
545 575
         }),
546 576
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["e" /* NavController */]])
547 577
     ], HomePage);
@@ -700,7 +730,7 @@ var MyApp = /** @class */ (function () {
700 730
         });
701 731
     }
702 732
     MyApp = __decorate([
703
-        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({template:/*ion-inline-start:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/app/app.html"*/'<ion-nav [root]="rootPage"></ion-nav>\n'/*ion-inline-end:"/Users/alizalang/Desktop/ZipTeam/ZipTeamOrange-ionic-UI/src/app/app.html"*/
733
+        Object(__WEBPACK_IMPORTED_MODULE_0__angular_core__["m" /* Component */])({template:/*ion-inline-start:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/app/app.html"*/'<ion-nav [root]="rootPage"></ion-nav>\n'/*ion-inline-end:"/Users/jasong/Labs/ZipTeam/ZipTeamOrange-ionic-UI/src/app/app.html"*/
704 734
         }),
705 735
         __metadata("design:paramtypes", [__WEBPACK_IMPORTED_MODULE_1_ionic_angular__["g" /* Platform */], __WEBPACK_IMPORTED_MODULE_2__ionic_native_status_bar__["a" /* StatusBar */], __WEBPACK_IMPORTED_MODULE_3__ionic_native_splash_screen__["a" /* SplashScreen */]])
706 736
     ], MyApp);

+ 5
- 1
ZipTeamOrange-ionic-UI/www/build/main.js.map
文件差異過大導致無法顯示
查看文件


+ 5
- 1
ZipTeamOrange-ionic-UI/www/build/vendor.js.map
文件差異過大導致無法顯示
查看文件


+ 17
- 1
ZipTeamOrange-server/pom.xml 查看文件

@@ -30,10 +30,26 @@
30 30
 			<artifactId>spring-boot-starter-data-jpa</artifactId>
31 31
 		</dependency>
32 32
 		<dependency>
33
+			<groupId>io.jsonwebtoken</groupId>
34
+			<artifactId>jjwt</artifactId>
35
+			<version>0.9.0</version>
36
+		</dependency>
37
+		<dependency>
38
+			<groupId>com.fasterxml.jackson.datatype</groupId>
39
+			<artifactId>jackson-datatype-jsr310</artifactId>
40
+		</dependency>
41
+		<dependency>
33 42
 			<groupId>org.springframework.boot</groupId>
34 43
 			<artifactId>spring-boot-starter-web</artifactId>
35 44
 		</dependency>
36
-
45
+		<dependency>
46
+			<groupId>org.springframework.boot</groupId>
47
+			<artifactId>spring-boot-starter-security</artifactId>
48
+		</dependency>
49
+		<dependency>
50
+			<groupId>org.springframework.boot</groupId>
51
+			<artifactId>spring-boot-starter-jdbc</artifactId>
52
+		</dependency>
37 53
 		<dependency>
38 54
 			<groupId>org.springframework.boot</groupId>
39 55
 			<artifactId>spring-boot-starter-data-rest</artifactId>

二進制
ZipTeamOrange-server/src/main/java/ZipTeamOrange/.DS_Store 查看文件


+ 42
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/AuditingConfig.java 查看文件

@@ -0,0 +1,42 @@
1
+package ZipTeamOrange.config;
2
+
3
+
4
+import ZipTeamOrange.security.UserPrincipal;
5
+import org.springframework.context.annotation.Bean;
6
+import org.springframework.context.annotation.Configuration;
7
+import org.springframework.data.domain.AuditorAware;
8
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
9
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
10
+import org.springframework.security.core.Authentication;
11
+import org.springframework.security.core.context.SecurityContextHolder;
12
+
13
+import java.util.Optional;
14
+
15
+@Configuration
16
+@EnableJpaAuditing
17
+public class AuditingConfig {
18
+
19
+    @Bean
20
+    public AuditorAware<Long> auditorProvider() {
21
+        return new SpringSecurityAuditAwareImpl();
22
+    }
23
+}
24
+
25
+    class SpringSecurityAuditAwareImpl implements AuditorAware<Long> {
26
+
27
+        @Override
28
+        public Optional<Long> getCurrentAuditor() {
29
+            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
30
+
31
+            if (authentication == null ||
32
+                    !authentication.isAuthenticated() ||
33
+                    authentication instanceof AnonymousAuthenticationToken) {
34
+                return Optional.empty();
35
+            }
36
+
37
+            UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
38
+
39
+            return Optional.ofNullable(userPrincipal.getId());
40
+        }
41
+    }
42
+

+ 97
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Config/SecurityConfig.java 查看文件

@@ -0,0 +1,97 @@
1
+package ZipTeamOrange.config;
2
+
3
+import ZipTeamOrange.security.CustomUserDetailsService;
4
+import ZipTeamOrange.security.JwtAuthenticationEntryPoint;
5
+import ZipTeamOrange.security.JwtAuthenticationFilter;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.context.annotation.Bean;
8
+import org.springframework.context.annotation.Configuration;
9
+import org.springframework.http.HttpMethod;
10
+import org.springframework.security.authentication.AuthenticationManager;
11
+import org.springframework.security.config.BeanIds;
12
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
13
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
14
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
15
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
16
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
17
+import org.springframework.security.config.http.SessionCreationPolicy;
18
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
19
+import org.springframework.security.crypto.password.PasswordEncoder;
20
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
21
+
22
+@Configuration
23
+@EnableWebSecurity
24
+@EnableGlobalMethodSecurity(
25
+        securedEnabled = true,
26
+        jsr250Enabled = true,
27
+        prePostEnabled = true
28
+)
29
+public class SecurityConfig extends WebSecurityConfigurerAdapter {
30
+
31
+    @Autowired
32
+    CustomUserDetailsService customUserDetailsService;
33
+
34
+    @Autowired
35
+    private JwtAuthenticationEntryPoint unauthorizedHandler;
36
+
37
+    @Bean
38
+    public JwtAuthenticationFilter jwtAuthenticationFilter() {
39
+        return new JwtAuthenticationFilter();
40
+    }
41
+
42
+    @Override
43
+    public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
44
+        authenticationManagerBuilder
45
+                .userDetailsService(customUserDetailsService)
46
+                .passwordEncoder(passwordEncoder());
47
+    }
48
+
49
+    @Bean(BeanIds.AUTHENTICATION_MANAGER)
50
+    @Override
51
+    public AuthenticationManager authenticationManagerBean() throws Exception {
52
+        return super.authenticationManagerBean();
53
+    }
54
+
55
+    @Bean
56
+    public PasswordEncoder passwordEncoder() {
57
+        return new BCryptPasswordEncoder();
58
+    }
59
+
60
+    @Override
61
+    protected void configure(HttpSecurity http) throws Exception {
62
+        http
63
+                .cors()
64
+                .and()
65
+                .csrf()
66
+                .disable()
67
+                .exceptionHandling()
68
+                .authenticationEntryPoint(unauthorizedHandler)
69
+                .and()
70
+                .sessionManagement()
71
+                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
72
+                .and()
73
+                .authorizeRequests()
74
+                .antMatchers("/",
75
+                        "/favicon.ico",
76
+                        "/**/*.png",
77
+                        "/**/*.gif",
78
+                        "/**/*.svg",
79
+                        "/**/*.jpg",
80
+                        "/**/*.html",
81
+                        "/**/*.css",
82
+                        "/**/*.js")
83
+                .permitAll()
84
+                .antMatchers("/api/auth/**")
85
+                .permitAll()
86
+                .antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")
87
+                .permitAll()
88
+                .antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
89
+                .permitAll()
90
+                .anyRequest()
91
+                .authenticated();
92
+
93
+        // Add our custom JWT security filter
94
+        http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
95
+
96
+    }
97
+}

ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/ChatController.java → ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/ChatController.java 查看文件

@@ -1,17 +1,30 @@
1
-package ZipTeamOrange.chat;
1
+package ZipTeamOrange.controller;
2 2
 
3
+import ZipTeamOrange.model.Chat;
4
+import ZipTeamOrange.repository.ChatRepository;
5
+import ZipTeamOrange.repository.MessageRepository;
6
+import ZipTeamOrange.repository.UserRepository;
7
+import org.slf4j.Logger;
8
+import org.slf4j.LoggerFactory;
3 9
 import org.springframework.beans.factory.annotation.Autowired;
4
-import org.springframework.stereotype.Controller;
5 10
 import org.springframework.web.bind.annotation.*;
6 11
 
7
-@Controller
8
-@RequestMapping(path = "/chat")
12
+@RestController
13
+@RequestMapping("/api/chat")
9 14
 @CrossOrigin(origins = {"http://localhost:8103"})
10 15
 public class ChatController {
11 16
 
12 17
     @Autowired
13 18
     private ChatRepository chatRepository;
14 19
 
20
+    @Autowired
21
+    private MessageRepository messageRepository;
22
+
23
+    @Autowired
24
+    private UserRepository userRepository;
25
+
26
+    private static final Logger logger = LoggerFactory.getLogger(ChatController.class);
27
+
15 28
     @PostMapping(path="/add")
16 29
     public @ResponseBody
17 30
     Chat addNewChat(@RequestBody Chat chat){

ZipTeamOrange-server/src/main/java/ZipTeamOrange/message/MessageController.java → ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/MessageController.java 查看文件

@@ -1,10 +1,15 @@
1
-package ZipTeamOrange.message;
1
+package ZipTeamOrange.controller;
2 2
 
3
+import ZipTeamOrange.model.Message;
4
+import ZipTeamOrange.repository.MessageRepository;
3 5
 import com.fasterxml.jackson.core.JsonProcessingException;
4 6
 import com.fasterxml.jackson.databind.ObjectMapper;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.security.access.prepost.PreAuthorize;
6 9
 import org.springframework.web.bind.annotation.*;
7 10
 
11
+import javax.annotation.security.RolesAllowed;
12
+
8 13
 @RestController
9 14
 @RequestMapping(path = "/message")
10 15
 @CrossOrigin
@@ -13,7 +18,9 @@ public class MessageController {
13 18
 
14 19
     @Autowired
15 20
     private MessageRepository messageRepository;
21
+
16 22
     @PostMapping(path = "/add")
23
+    @RolesAllowed("ROLE_USER")
17 24
     public String postMessage(@RequestBody Message message) throws JsonProcessingException {
18 25
 
19 26
         messageRepository.save(message);

ZipTeamOrange-server/src/main/java/ZipTeamOrange/user/UserController.java → ZipTeamOrange-server/src/main/java/ZipTeamOrange/Controller/UserController.java 查看文件

@@ -1,12 +1,16 @@
1
-package ZipTeamOrange.user;
1
+package ZipTeamOrange.controller;
2 2
 
3
+import ZipTeamOrange.model.User;
4
+import ZipTeamOrange.repository.UserRepository;
3 5
 import com.fasterxml.jackson.core.JsonProcessingException;
4 6
 import com.fasterxml.jackson.databind.ObjectMapper;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.stereotype.Controller;
7 8
 import org.springframework.web.bind.annotation.*;
8 9
 
9
-@Controller
10
+import java.util.Optional;
11
+
12
+@RestController
13
+@CrossOrigin("http://localhost:8100")
10 14
 @RequestMapping(path = "/user")
11 15
 public class UserController {
12 16
 
@@ -22,10 +26,14 @@ public class UserController {
22 26
         return ob.writeValueAsString(user);
23 27
     }
24 28
 
25
-    @GetMapping(path="/all")
26
-    public @ResponseBody Iterable<User> getAllUser(){
27
-        //this returns a JSON or XML with users
28
-        return userRepository.findAll();
29
+    @GetMapping(path="/userName")
30
+    public Optional<User> findByUserName(@RequestParam("name") String userName) {
31
+        return userRepository.findByUsername(userName);
32
+    }
33
+
34
+    @GetMapping(path="/email")
35
+    public Optional<User> findByEmail(@RequestParam("email") String email) {
36
+        return userRepository.findByEmail(email);
29 37
     }
30 38
 
31 39
 }

+ 45
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Audit/DateAudit.java 查看文件

@@ -0,0 +1,45 @@
1
+package ZipTeamOrange.model.Audit;
2
+
3
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4
+import org.springframework.data.annotation.CreatedDate;
5
+import org.springframework.data.annotation.LastModifiedDate;
6
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
7
+
8
+import javax.persistence.Column;
9
+import javax.persistence.EntityListeners;
10
+import javax.persistence.MappedSuperclass;
11
+import java.io.Serializable;
12
+import java.time.Instant;
13
+
14
+@MappedSuperclass
15
+@EntityListeners(AuditingEntityListener.class)
16
+@JsonIgnoreProperties(
17
+        value = {"createdAt", "updatedAt"},
18
+        allowGetters = true
19
+)
20
+public abstract class DateAudit implements Serializable {
21
+
22
+    @CreatedDate
23
+    @Column(nullable = false, updatable = false)
24
+    private Instant createdAt;
25
+
26
+    @LastModifiedDate
27
+    @Column(nullable = false)
28
+    private Instant updatedAt;
29
+
30
+    public Instant getCreatedAt() {
31
+        return createdAt;
32
+    }
33
+
34
+    public void setCreatedAt(Instant createdAt) {
35
+        this.createdAt = createdAt;
36
+    }
37
+
38
+    public Instant getUpdatedAt() {
39
+        return updatedAt;
40
+    }
41
+
42
+    public void setUpdatedAt(Instant updatedAt) {
43
+        this.updatedAt = updatedAt;
44
+    }
45
+}

+ 112
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Chat.java 查看文件

@@ -0,0 +1,112 @@
1
+package ZipTeamOrange.model;
2
+
3
+import ZipTeamOrange.model.Audit.UserDateAudit;
4
+import ZipTeamOrange.model.Message;
5
+import ZipTeamOrange.model.User;
6
+import org.springframework.data.annotation.CreatedBy;
7
+import org.springframework.data.annotation.CreatedDate;
8
+import org.springframework.data.annotation.LastModifiedBy;
9
+import org.springframework.data.annotation.LastModifiedDate;
10
+
11
+import javax.persistence.*;
12
+import javax.validation.constraints.NotBlank;
13
+import java.util.Set;
14
+
15
+@Entity
16
+@Table(name = "chats")
17
+public class Chat extends UserDateAudit {
18
+
19
+    @Id
20
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
21
+    private Long id;
22
+
23
+    @NotBlank
24
+    private String topic;
25
+
26
+    @OneToMany(mappedBy = "chat",
27
+    cascade = CascadeType.ALL,
28
+    fetch = FetchType.EAGER,
29
+    orphanRemoval = true)
30
+    private Set<Message> messages;
31
+
32
+    @ManyToMany(fetch = FetchType.EAGER,
33
+    cascade = CascadeType.ALL)
34
+    @JoinTable(name = "chat_users",
35
+            joinColumns = @JoinColumn(name = "chat_id"),
36
+            inverseJoinColumns = @JoinColumn(name = "user_id"))
37
+    private Set<User> users;
38
+
39
+    @Column(name = "created_date", nullable = false, updatable = false)
40
+    @CreatedDate
41
+    private long createdDate;
42
+
43
+    @Column(name = "modified_date")
44
+    @LastModifiedDate
45
+    private long modifiedDate;
46
+
47
+    @Column(name = "created_by")
48
+    @CreatedBy
49
+    private String createdBy;
50
+
51
+    @Column(name = "modified_by")
52
+    @LastModifiedBy
53
+    private String modifiedBy;
54
+
55
+    public Chat(String topic, Set<Message> messages, Set<User> user) {
56
+        this.topic = topic;
57
+        this.messages = messages;
58
+        this.users = user;
59
+    }
60
+
61
+    public Chat() { }
62
+
63
+    public Long getId() {
64
+        return id;
65
+    }
66
+
67
+    public void setId(Long id) {
68
+        this.id = id;
69
+    }
70
+
71
+    public String getTopic() {
72
+        return topic;
73
+    }
74
+
75
+    public void setTopic(String topic) {
76
+        this.topic = topic;
77
+    }
78
+
79
+    public Set<Message> getMessages() {
80
+        return messages;
81
+    }
82
+
83
+    public void setMessages(Set<Message> messages) {
84
+        this.messages = messages;
85
+    }
86
+
87
+        public Set<User> getUsers() {
88
+        return users;
89
+    }
90
+
91
+    public void setUsers(Set<User> users) {
92
+        this.users = users;
93
+    }
94
+
95
+    public void addMessage(Message message) {
96
+        messages.add(message);
97
+        message.setChat(this);
98
+    }
99
+
100
+    public void removeMessage(Message message) {
101
+        messages.remove(message);
102
+        message.setChat(null);
103
+    }
104
+
105
+    public void addUser(User user) {
106
+        users.add(user);
107
+    }
108
+
109
+    public void removeUser(User user) {
110
+        users.remove(user);
111
+    }
112
+}

+ 80
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Message.java 查看文件

@@ -0,0 +1,80 @@
1
+package ZipTeamOrange.model;
2
+
3
+import ZipTeamOrange.model.Audit.DateAudit;
4
+import ZipTeamOrange.model.Audit.UserDateAudit;
5
+import org.springframework.data.annotation.CreatedBy;
6
+import org.springframework.data.annotation.CreatedDate;
7
+import org.springframework.data.annotation.LastModifiedBy;
8
+import org.springframework.data.annotation.LastModifiedDate;
9
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
10
+
11
+import javax.persistence.*;
12
+
13
+@Entity
14
+public class Message extends UserDateAudit {
15
+
16
+    @Id
17
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
18
+    private long id;
19
+
20
+    String text;
21
+
22
+    @ManyToOne(fetch = FetchType.LAZY, optional = false)
23
+    @JoinColumn(name = "chat_id", nullable = false)
24
+    private Chat chat;
25
+
26
+    @ManyToOne(fetch = FetchType.LAZY, optional = false)
27
+    @JoinColumn(name = "user_id", nullable = false)
28
+    private User user;
29
+
30
+    @Column(name = "created_date", nullable = false, updatable = false)
31
+    @CreatedDate
32
+    private long createdDate;
33
+
34
+    @Column(name = "modified_date")
35
+    @LastModifiedDate
36
+    private long modifiedDate;
37
+
38
+    @Column(name = "created_by")
39
+    @CreatedBy
40
+    private String createdBy;
41
+
42
+    @Column(name = "modified_by")
43
+    @LastModifiedBy
44
+    private String modifiedBy;
45
+
46
+    public Message() { }
47
+
48
+    public Message(String text) {
49
+        this.text = text;
50
+    }
51
+
52
+    public long getId() {
53
+        return id;
54
+    }
55
+
56
+    public void setId(long id) {
57
+        this.id = id;
58
+    }
59
+
60
+    public String getText() {
61
+        return text;
62
+    }
63
+
64
+    public void setText(String text) {
65
+        this.text = text;
66
+    }
67
+
68
+    public Chat getChat() {
69
+        return chat;
70
+    }
71
+
72
+    public void setChat(Chat chat) {
73
+        this.chat = chat;
74
+    }
75
+
76
+    @Override
77
+    public String toString() {
78
+        return createdDate + " " + createdBy + " " + text;
79
+    }
80
+}

+ 49
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/Role.java 查看文件

@@ -0,0 +1,49 @@
1
+package ZipTeamOrange.model;
2
+
3
+import org.hibernate.annotations.NaturalId;
4
+
5
+import javax.persistence.*;
6
+
7
+@Entity
8
+@Table(name = "roles")
9
+public class Role {
10
+    @Id
11
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
12
+    private Long id;
13
+
14
+    @Enumerated(EnumType.STRING)
15
+    @NaturalId
16
+    @Column(length = 60)
17
+    private RoleName name;
18
+
19
+//    ManyToMany()
20
+
21
+    public Role() {
22
+
23
+    }
24
+
25
+    public Role(RoleName name) {
26
+        this.name = name;
27
+    }
28
+
29
+    public Long getId() {
30
+        return id;
31
+    }
32
+
33
+    public void setId(Long id) {
34
+        this.id = id;
35
+    }
36
+
37
+    public RoleName getName() {
38
+        return name;
39
+    }
40
+
41
+    public void setName(RoleName name) {
42
+        this.name = name;
43
+    }
44
+
45
+    @Override
46
+    public String toString() {
47
+        return name.toString();
48
+    }
49
+}

+ 6
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/RoleName.java 查看文件

@@ -0,0 +1,6 @@
1
+package ZipTeamOrange.model;
2
+
3
+public enum  RoleName {
4
+    ROLE_USER,
5
+    ROLE_ADMIN
6
+}

+ 102
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Model/User.java 查看文件

@@ -0,0 +1,102 @@
1
+package ZipTeamOrange.model;
2
+
3
+import org.hibernate.annotations.NaturalId;
4
+
5
+import javax.persistence.*;
6
+import javax.validation.constraints.Email;
7
+import javax.validation.constraints.NotBlank;
8
+import java.util.HashSet;
9
+import java.util.Set;
10
+
11
+
12
+@Entity
13
+@Table(name = "users", uniqueConstraints = {
14
+        @UniqueConstraint(columnNames = {
15
+                "username"
16
+        }),
17
+        @UniqueConstraint(columnNames = {
18
+                "email"
19
+        })
20
+})
21
+public class User {
22
+
23
+    @Id
24
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
25
+    private Long id;
26
+
27
+    @NotBlank
28
+    private String username;
29
+
30
+    @NotBlank
31
+    @NaturalId
32
+    @Email
33
+    private String email;
34
+
35
+    @NotBlank
36
+    private String password;
37
+
38
+    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
39
+    private Set<Role> roles = new HashSet<>();
40
+
41
+
42
+//    @OneToMany(mappedBy = "user")
43
+//    private Set<Message> messages;
44
+//
45
+//    @ManyToMany
46
+//    @JoinTable(
47
+//            name = "USER_CHAT",
48
+//            joinColumns = { @JoinColumn(name = "user_id") },
49
+//            inverseJoinColumns = { @JoinColumn(name = "chat_id") }
50
+//    )
51
+//    private Set<Chat> chat;
52
+
53
+
54
+    public User() {
55
+    }
56
+
57
+    public User(String username, String email, String password) {
58
+        this.username = username;
59
+        this.email = email;
60
+        this.password = password;
61
+    }
62
+
63
+    public Long getId() {
64
+        return id;
65
+    }
66
+
67
+    public void setId(Long id) {
68
+        this.id = id;
69
+    }
70
+
71
+    public String getUsername() {
72
+        return username;
73
+    }
74
+
75
+    public void setUsername(String userName) {
76
+        this.username = userName;
77
+    }
78
+
79
+    public String getEmail() {
80
+        return email;
81
+    }
82
+
83
+    public void setEmail(String email) {
84
+        this.email = email;
85
+    }
86
+
87
+    public String getPassword() {
88
+        return password;
89
+    }
90
+
91
+    public void setPassword(String password) {
92
+        this.password = password;
93
+    }
94
+
95
+    public Set<Role> getRoles() {
96
+        return roles;
97
+    }
98
+
99
+    public void setRoles(Set<Role> roles) {
100
+        this.roles = roles;
101
+    }
102
+}

+ 27
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/ChatRepository.java 查看文件

@@ -0,0 +1,27 @@
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.Chat;
4
+import org.springframework.data.domain.Page;
5
+import org.springframework.data.domain.Pageable;
6
+import org.springframework.data.domain.Sort;
7
+import org.springframework.data.jpa.repository.JpaRepository;
8
+import org.springframework.stereotype.Repository;
9
+
10
+import java.util.List;
11
+import java.util.Optional;
12
+
13
+@Repository
14
+public interface ChatRepository extends JpaRepository<Chat, Long> {
15
+
16
+    Optional<Chat> findById(Long chatId);
17
+
18
+    Page<Chat> findByCreatedBy(Long userId, Pageable pageable);
19
+
20
+    long countByCreatedBy(Long userId);
21
+
22
+    List<Chat> findByIdIn(List<Long> chatIds);
23
+
24
+    List<Chat> findByIdIn(List<Long> chatIds, Sort sort);
25
+
26
+}
27
+

+ 34
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/MessageRepository.java 查看文件

@@ -0,0 +1,34 @@
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.Chat;
4
+import ZipTeamOrange.model.Message;
5
+import org.springframework.data.domain.Page;
6
+import org.springframework.data.domain.Pageable;
7
+import org.springframework.data.domain.Sort;
8
+import org.springframework.data.jpa.repository.JpaRepository;
9
+import org.springframework.data.jpa.repository.Query;
10
+import org.springframework.data.repository.query.Param;
11
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
12
+import org.springframework.stereotype.Repository;
13
+
14
+import java.util.List;
15
+import java.util.Optional;
16
+
17
+@Repository
18
+@RepositoryRestResource(collectionResourceRel = "message", path = "message")
19
+public interface MessageRepository extends JpaRepository<Message, Long> {
20
+
21
+    Optional<Message> findById(Long messageId);
22
+
23
+    Page<Message> findByCreatedBy(Long userId, Pageable pageable);
24
+
25
+    long countByCreatedBy(Long userId);
26
+
27
+//    @Query("SELECT COUNT(m.id) from Message v where v.user.id = :userId")
28
+//    long countByUserId(@Param("userId") Long userId);
29
+
30
+    List<Message> findByIdIn(List<Long> messageIds);
31
+
32
+    List<Message> findByIdIn(List<Long> messageIds, Sort sort);
33
+
34
+}

+ 15
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/RoleRepository.java 查看文件

@@ -0,0 +1,15 @@
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.Role;
4
+import ZipTeamOrange.model.RoleName;
5
+import org.springframework.data.jpa.repository.JpaRepository;
6
+import org.springframework.data.rest.core.annotation.RepositoryRestResource;
7
+import org.springframework.stereotype.Repository;
8
+
9
+import java.util.Optional;
10
+
11
+@Repository
12
+@RepositoryRestResource(collectionResourceRel = "roles", path = "roles")
13
+public interface RoleRepository extends JpaRepository<Role, Long> {
14
+    Role findByName(RoleName roleName);
15
+}

+ 24
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Repository/UserRepository.java 查看文件

@@ -0,0 +1,24 @@
1
+package ZipTeamOrange.repository;
2
+
3
+import ZipTeamOrange.model.User;
4
+import org.springframework.data.jpa.repository.JpaRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+import java.util.List;
8
+import java.util.Optional;
9
+
10
+
11
+@Repository
12
+public interface UserRepository extends JpaRepository<User, Long> {
13
+
14
+    Optional<User> findByEmail(String email);
15
+
16
+    Optional<User> findByUsernameOrEmail(String username, String email);
17
+
18
+    List<User> findByIdIn(List<Long> userIds);
19
+
20
+    Optional<User> findByUsername(String username);
21
+
22
+    Boolean existsByUsername(String username);
23
+
24
+    Boolean existsByEmail(String email);}

+ 13
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CurrentUser.java 查看文件

@@ -0,0 +1,13 @@
1
+package ZipTeamOrange.security;
2
+
3
+import org.springframework.security.core.annotation.AuthenticationPrincipal;
4
+
5
+import java.lang.annotation.*;
6
+
7
+@Target({ElementType.PARAMETER, ElementType.TYPE})
8
+@Retention(RetentionPolicy.RUNTIME)
9
+@Documented
10
+@AuthenticationPrincipal
11
+public @interface CurrentUser {
12
+
13
+}

+ 41
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/CustomUserDetailsService.java 查看文件

@@ -0,0 +1,41 @@
1
+package ZipTeamOrange.security;
2
+
3
+import ZipTeamOrange.model.User;
4
+import ZipTeamOrange.repository.UserRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.security.core.userdetails.UserDetails;
7
+import org.springframework.security.core.userdetails.UserDetailsService;
8
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
9
+import org.springframework.stereotype.Service;
10
+import org.springframework.transaction.annotation.Transactional;
11
+
12
+@Service
13
+public class CustomUserDetailsService implements UserDetailsService {
14
+
15
+    @Autowired
16
+    UserRepository userRepository;
17
+
18
+    @Override
19
+    @Transactional
20
+    public UserDetails loadUserByUsername(String usernameOrEmail)
21
+            throws UsernameNotFoundException {
22
+        // Let people login with either username or email
23
+        User user = userRepository.findByUsernameOrEmail(usernameOrEmail, usernameOrEmail)
24
+                .orElseThrow(() ->
25
+                        new UsernameNotFoundException("User not found with username or email : " + usernameOrEmail)
26
+                );
27
+
28
+        return UserPrincipal.create(user);
29
+    }
30
+
31
+    // This method is used by JWTAuthenticationFilter
32
+    @Transactional
33
+    public UserDetails loadUserById(Long id) {
34
+        User user = userRepository.findById(id).orElseThrow(
35
+                () -> new UsernameNotFoundException("User not found with id : " + id)
36
+        );
37
+
38
+        return UserPrincipal.create(user);
39
+    }
40
+}
41
+

+ 26
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationEntryPoint.java 查看文件

@@ -0,0 +1,26 @@
1
+package ZipTeamOrange.security;
2
+
3
+import org.slf4j.Logger;
4
+import org.slf4j.LoggerFactory;
5
+import org.springframework.security.core.AuthenticationException;
6
+import org.springframework.security.web.AuthenticationEntryPoint;
7
+import org.springframework.stereotype.Component;
8
+
9
+import javax.servlet.ServletException;
10
+import javax.servlet.http.HttpServletRequest;
11
+import javax.servlet.http.HttpServletResponse;
12
+import java.io.IOException;
13
+
14
+@Component
15
+public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
16
+
17
+    private static final Logger logger = LoggerFactory.getLogger(JwtAuthenticationEntryPoint.class);
18
+    @Override
19
+    public void commence(HttpServletRequest httpServletRequest,
20
+                         HttpServletResponse httpServletResponse,
21
+                         AuthenticationException e) throws IOException, ServletException {
22
+        logger.error("Responding with unauthorized error. Message - {}", e.getMessage());
23
+        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED,
24
+                "Sorry, You're not authorized to access this resource.");
25
+    }
26
+}

+ 58
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtAuthenticationFilter.java 查看文件

@@ -0,0 +1,58 @@
1
+package ZipTeamOrange.security;
2
+
3
+import org.slf4j.Logger;
4
+import org.slf4j.LoggerFactory;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
7
+import org.springframework.security.core.context.SecurityContextHolder;
8
+import org.springframework.security.core.userdetails.UserDetails;
9
+import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
10
+import org.springframework.util.StringUtils;
11
+import org.springframework.web.filter.OncePerRequestFilter;
12
+
13
+import javax.servlet.FilterChain;
14
+import javax.servlet.ServletException;
15
+import javax.servlet.http.HttpServletRequest;
16
+import javax.servlet.http.HttpServletResponse;
17
+import java.io.IOException;
18
+
19
+public class JwtAuthenticationFilter extends OncePerRequestFilter {
20
+
21
+    @Autowired
22
+    private JwtTokenProvider tokenProvider;
23
+
24
+    @Autowired
25
+    private CustomUserDetailsService customUserDetailsService;
26
+
27
+    private static final Logger logger = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
28
+
29
+    @Override
30
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
31
+        try {
32
+            String jwt = getJwtFromRequest(request);
33
+
34
+            if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) {
35
+                Long userId = tokenProvider.getUserIdFromJWT(jwt);
36
+
37
+                UserDetails userDetails = customUserDetailsService.loadUserById(userId);
38
+                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
39
+                authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
40
+
41
+                SecurityContextHolder.getContext().setAuthentication(authentication);
42
+            }
43
+        } catch (Exception ex) {
44
+            logger.error("Could not set user authentication in security context", ex);
45
+        }
46
+
47
+        filterChain.doFilter(request, response);
48
+    }
49
+
50
+    private String getJwtFromRequest(HttpServletRequest request) {
51
+        String bearerToken = request.getHeader("Authorization");
52
+        if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
53
+            return bearerToken.substring(7, bearerToken.length());
54
+        }
55
+        return null;
56
+    }
57
+}
58
+

+ 64
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/JwtTokenProvider.java 查看文件

@@ -0,0 +1,64 @@
1
+package ZipTeamOrange.security;
2
+
3
+import io.jsonwebtoken.*;
4
+import org.slf4j.Logger;
5
+import org.slf4j.LoggerFactory;
6
+import org.springframework.beans.factory.annotation.Value;
7
+import org.springframework.security.core.Authentication;
8
+import org.springframework.stereotype.Component;
9
+
10
+import java.util.Date;
11
+
12
+@Component
13
+public class JwtTokenProvider {
14
+
15
+    private static final Logger logger = LoggerFactory.getLogger(JwtTokenProvider.class);
16
+
17
+    @Value("${app.jwtSecret}")
18
+    private String jwtSecret;
19
+
20
+    @Value("${app.jwtExpirationInMs}")
21
+    private int jwtExpirationInMs;
22
+
23
+    public String generateToken(Authentication authentication) {
24
+
25
+        UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
26
+
27
+        Date now = new Date();
28
+        Date expiryDate = new Date(now.getTime() + jwtExpirationInMs);
29
+
30
+        return Jwts.builder()
31
+                .setSubject(Long.toString(userPrincipal.getId()))
32
+                .setIssuedAt(new Date())
33
+                .setExpiration(expiryDate)
34
+                .signWith(SignatureAlgorithm.HS512, jwtSecret)
35
+                .compact();
36
+    }
37
+
38
+    public Long getUserIdFromJWT(String token) {
39
+        Claims claims = Jwts.parser()
40
+                .setSigningKey(jwtSecret)
41
+                .parseClaimsJws(token)
42
+                .getBody();
43
+
44
+        return Long.parseLong(claims.getSubject());
45
+    }
46
+
47
+    public boolean validateToken(String authToken) {
48
+        try {
49
+            Jwts.parser().setSigningKey(jwtSecret).parseClaimsJws(authToken);
50
+            return true;
51
+        } catch (SignatureException ex) {
52
+            logger.error("Invalid JWT signature");
53
+        } catch (MalformedJwtException ex) {
54
+            logger.error("Invalid JWT token");
55
+        } catch (ExpiredJwtException ex) {
56
+            logger.error("Expired JWT token");
57
+        } catch (UnsupportedJwtException ex) {
58
+            logger.error("Unsupported JWT token");
59
+        } catch (IllegalArgumentException ex) {
60
+            logger.error("JWT claims string is empty.");
61
+        }
62
+        return false;
63
+    }
64
+}

+ 107
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/Security/UserPrincipal.java 查看文件

@@ -0,0 +1,107 @@
1
+package ZipTeamOrange.security;
2
+
3
+import ZipTeamOrange.model.User;
4
+import com.fasterxml.jackson.annotation.JsonIgnore;
5
+import org.springframework.security.core.GrantedAuthority;
6
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
7
+import org.springframework.security.core.userdetails.UserDetails;
8
+
9
+import java.util.Collection;
10
+import java.util.List;
11
+import java.util.Objects;
12
+import java.util.stream.Collectors;
13
+
14
+public class UserPrincipal implements UserDetails {
15
+    private Long id;
16
+
17
+    private String name;
18
+
19
+    private String username;
20
+
21
+    @JsonIgnore
22
+    private String email;
23
+
24
+    @JsonIgnore
25
+    private String password;
26
+
27
+    private Collection<? extends GrantedAuthority> authorities;
28
+
29
+    public UserPrincipal(Long id, String username, String email, String password, Collection<? extends GrantedAuthority> authorities) {
30
+        this.id = id;
31
+        this.username = username;
32
+        this.email = email;
33
+        this.password = password;
34
+        this.authorities = authorities;
35
+    }
36
+
37
+    public static UserPrincipal create(User user) {
38
+        List<GrantedAuthority> authorities = user.getRoles().stream().map(role ->
39
+                new SimpleGrantedAuthority(role.getName().name())
40
+        ).collect(Collectors.toList());
41
+
42
+        return new UserPrincipal(
43
+                user.getId(),
44
+                user.getUsername(),
45
+                user.getEmail(),
46
+                user.getPassword(),
47
+                authorities
48
+        );
49
+    }
50
+
51
+    public Long getId() {
52
+        return id;
53
+    }
54
+
55
+    public String getEmail() {
56
+        return email;
57
+    }
58
+
59
+    @Override
60
+    public String getUsername() {
61
+        return username;
62
+    }
63
+
64
+    @Override
65
+    public String getPassword() {
66
+        return password;
67
+    }
68
+
69
+    @Override
70
+    public Collection<? extends GrantedAuthority> getAuthorities() {
71
+        return authorities;
72
+    }
73
+
74
+    @Override
75
+    public boolean isAccountNonExpired() {
76
+        return true;
77
+    }
78
+
79
+    @Override
80
+    public boolean isAccountNonLocked() {
81
+        return true;
82
+    }
83
+
84
+    @Override
85
+    public boolean isCredentialsNonExpired() {
86
+        return true;
87
+    }
88
+
89
+    @Override
90
+    public boolean isEnabled() {
91
+        return true;
92
+    }
93
+
94
+    @Override
95
+    public boolean equals(Object o) {
96
+        if (this == o) return true;
97
+        if (o == null || getClass() != o.getClass()) return false;
98
+        UserPrincipal that = (UserPrincipal) o;
99
+        return Objects.equals(id, that.id);
100
+    }
101
+
102
+    @Override
103
+    public int hashCode() {
104
+
105
+        return Objects.hash(id);
106
+    }
107
+}

+ 14
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/ZipTeamOrangeApplication.java 查看文件

@@ -2,10 +2,24 @@ package ZipTeamOrange;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.boot.autoconfigure.domain.EntityScan;
6
+import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters;
7
+
8
+import javax.annotation.PostConstruct;
9
+import java.util.TimeZone;
5 10
 
6 11
 @SpringBootApplication
12
+@EntityScan(basePackageClasses = {
13
+
14
+		ZipTeamOrangeApplication.class,
15
+		Jsr310JpaConverters.class
16
+})
7 17
 public class ZipTeamOrangeApplication {
8 18
 
19
+	@PostConstruct
20
+	void init() {
21
+		TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
22
+	}
9 23
 
10 24
 	public static void main(String[] args) {
11 25
 		SpringApplication.run(ZipTeamOrangeApplication.class, args);

+ 0
- 52
ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/Chat.java 查看文件

@@ -1,52 +0,0 @@
1
-package ZipTeamOrange.chat;
2
-
3
-import ZipTeamOrange.message.Message;
4
-import ZipTeamOrange.user.User;
5
-import javax.persistence.*;
6
-import java.util.Set;
7
-
8
-@Entity
9
-public class Chat {
10
-
11
-    @Id
12
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
13
-    private Long id;
14
-    private String name;
15
-
16
-    @OneToMany(mappedBy = "chat")
17
-    private Set<Message> messages;
18
-
19
-    @ManyToMany(mappedBy = "chat")
20
-    private Set<User> users;
21
-
22
-    public Chat(String name, Set<User> users) {
23
-        this.name = name;
24
-        this.users = users;
25
-    }
26
-
27
-    public Chat(){}
28
-
29
-    public Long getId() {
30
-        return id;
31
-    }
32
-
33
-    public void setId(Long id) {
34
-        this.id = id;
35
-    }
36
-
37
-    public String getName() {
38
-        return name;
39
-    }
40
-
41
-    public void setName(String name) {
42
-        this.name = name;
43
-    }
44
-
45
-    public Set<User> getUsers() {
46
-        return users;
47
-    }
48
-
49
-    public void setUsers(Set<User> users) {
50
-        this.users = users;
51
-    }
52
-}

+ 0
- 6
ZipTeamOrange-server/src/main/java/ZipTeamOrange/chat/ChatRepository.java 查看文件

@@ -1,6 +0,0 @@
1
-package ZipTeamOrange.chat;
2
-
3
-import org.springframework.data.jpa.repository.JpaRepository;
4
-
5
-public interface ChatRepository extends JpaRepository<Chat, Long> {
6
-}

+ 29
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/RoleLoader.java 查看文件

@@ -0,0 +1,29 @@
1
+package ZipTeamOrange.config;
2
+
3
+import ZipTeamOrange.model.Role;
4
+import ZipTeamOrange.model.RoleName;
5
+import ZipTeamOrange.repository.RoleRepository;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.boot.ApplicationArguments;
8
+import org.springframework.boot.ApplicationRunner;
9
+import org.springframework.stereotype.Component;
10
+
11
+@Component
12
+public class RoleLoader implements ApplicationRunner {
13
+
14
+    private RoleRepository role;
15
+
16
+    @Autowired
17
+    public RoleLoader(RoleRepository role){
18
+        this.role = role;
19
+
20
+    }
21
+    public void run(ApplicationArguments args) {
22
+        Role foo = new Role(RoleName.ROLE_USER);
23
+        this.role.save(foo);
24
+
25
+        foo = new Role(RoleName.ROLE_ADMIN);
26
+        this.role.save(foo);
27
+
28
+    }
29
+}

+ 31
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/UserLoader.java 查看文件

@@ -0,0 +1,31 @@
1
+//package ZipTeamOrange.config;
2
+//
3
+//import ZipTeamOrange.model.Role;
4
+//import ZipTeamOrange.model.User;
5
+//import ZipTeamOrange.model.RoleName;
6
+//import ZipTeamOrange.repository.RoleRepository;
7
+//import ZipTeamOrange.repository.UserRepository;
8
+//import org.springframework.beans.factory.annotation.Autowired;
9
+//import org.springframework.boot.ApplicationArguments;
10
+//import org.springframework.boot.ApplicationRunner;
11
+//
12
+//public class UserLoader  implements ApplicationRunner {
13
+//
14
+//        private UserRepository userrepo;
15
+//        private RoleRepository rolerepo;
16
+//
17
+//        @Autowired
18
+//        public UserLoader(UserRepository userr){
19
+//            this.userrepo = userr;
20
+//
21
+//        }
22
+//        public void run(ApplicationArguments args) {
23
+//            User foo = new User("jason", "jason@foo.com", "password");
24
+//            Role r = rolerepo.getOne(1L);
25
+//            foo.getRoles().add(r);
26
+//
27
+//            this.userrepo.save(foo);
28
+//        }
29
+//    }
30
+//
31
+//

+ 19
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/config/WebMvcConfig.java 查看文件

@@ -0,0 +1,19 @@
1
+package ZipTeamOrange.config;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
6
+
7
+@Configuration
8
+public class WebMvcConfig implements WebMvcConfigurer {
9
+
10
+    private final long MAX_AGE_SECS = 3600;
11
+
12
+    @Override
13
+    public void addCorsMappings(CorsRegistry registry) {
14
+        registry.addMapping("/**")
15
+                .allowedOrigins("*", "")
16
+                .allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
17
+                .maxAge(MAX_AGE_SECS);
18
+    }
19
+}

+ 97
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/controller/AuthController.java 查看文件

@@ -0,0 +1,97 @@
1
+package ZipTeamOrange.controller;
2
+
3
+import ZipTeamOrange.model.Role;
4
+import ZipTeamOrange.model.RoleName;
5
+import ZipTeamOrange.model.User;
6
+import ZipTeamOrange.payload.response.ApiResponse;
7
+import ZipTeamOrange.payload.response.JwtAuthenticationResponse;
8
+import ZipTeamOrange.payload.request.LoginRequest;
9
+import ZipTeamOrange.payload.request.SignUpRequest;
10
+import ZipTeamOrange.repository.RoleRepository;
11
+import ZipTeamOrange.repository.UserRepository;
12
+import ZipTeamOrange.security.JwtTokenProvider;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.http.HttpStatus;
15
+import org.springframework.http.ResponseEntity;
16
+import org.springframework.security.authentication.AuthenticationManager;
17
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
18
+import org.springframework.security.core.Authentication;
19
+import org.springframework.security.core.context.SecurityContextHolder;
20
+import org.springframework.security.crypto.password.PasswordEncoder;
21
+import org.springframework.web.bind.annotation.PostMapping;
22
+import org.springframework.web.bind.annotation.RequestBody;
23
+import org.springframework.web.bind.annotation.RequestMapping;
24
+import org.springframework.web.bind.annotation.RestController;
25
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
26
+
27
+import javax.validation.Valid;
28
+import java.net.URI;
29
+import java.util.Collections;
30
+
31
+@RestController
32
+@RequestMapping("/api/auth")
33
+public class AuthController {
34
+
35
+    @Autowired
36
+    AuthenticationManager authenticationManager;
37
+
38
+    @Autowired
39
+    UserRepository userRepository;
40
+
41
+    @Autowired
42
+    RoleRepository roleRepository;
43
+
44
+    @Autowired
45
+    PasswordEncoder passwordEncoder;
46
+
47
+    @Autowired
48
+    JwtTokenProvider tokenProvider;
49
+
50
+    @PostMapping("/signin")
51
+    public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {
52
+
53
+        Authentication authentication = authenticationManager.authenticate(
54
+                new UsernamePasswordAuthenticationToken(
55
+                        loginRequest.getUsernameOrEmail(),
56
+                        loginRequest.getPassword()
57
+                )
58
+        );
59
+
60
+        SecurityContextHolder.getContext().setAuthentication(authentication);
61
+
62
+        String jwt = tokenProvider.generateToken(authentication);
63
+        return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
64
+    }
65
+
66
+    @PostMapping("/signup")
67
+    public ResponseEntity<?> registerUser(@Valid @RequestBody SignUpRequest signUpRequest) {
68
+        if(userRepository.existsByUsername(signUpRequest.getUsername())) {
69
+            return new ResponseEntity(new ApiResponse(false, "Username is already taken!"),
70
+                    HttpStatus.BAD_REQUEST);
71
+        }
72
+
73
+        if(userRepository.existsByEmail(signUpRequest.getEmail())) {
74
+            return new ResponseEntity(new ApiResponse(false, "Email Address already in use!"),
75
+                    HttpStatus.BAD_REQUEST);
76
+        }
77
+
78
+        // Creating user's account
79
+        User user = new User(signUpRequest.getUsername(),
80
+                signUpRequest.getEmail(), signUpRequest.getPassword());
81
+
82
+        user.setPassword(passwordEncoder.encode(user.getPassword()));
83
+
84
+        Role userRole = roleRepository.findByName(RoleName.ROLE_USER);
85
+               // .orElseThrow(() -> new AppException("User Role not set."));
86
+
87
+        user.setRoles(Collections.singleton(userRole));
88
+
89
+        User result = userRepository.save(user);
90
+
91
+        URI location = ServletUriComponentsBuilder
92
+                .fromCurrentContextPath().path("/api/users/{username}")
93
+                .buildAndExpand(result.getUsername()).toUri();
94
+
95
+        return ResponseEntity.created(location).body(new ApiResponse(true, "User registered successfully: " + user.getRoles() ));
96
+    }
97
+}

+ 15
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/AppException.java 查看文件

@@ -0,0 +1,15 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
7
+public class AppException extends RuntimeException {
8
+    public AppException(String message) {
9
+        super(message);
10
+    }
11
+
12
+    public AppException(String message, Throwable cause) {
13
+        super(message, cause);
14
+    }
15
+}

+ 16
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/BadRequestException.java 查看文件

@@ -0,0 +1,16 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.BAD_REQUEST)
7
+public class BadRequestException extends RuntimeException {
8
+
9
+    public BadRequestException(String message) {
10
+        super(message);
11
+    }
12
+
13
+    public BadRequestException(String message, Throwable cause) {
14
+        super(message, cause);
15
+    }
16
+}

+ 30
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/exception/ResourceNotFoundException.java 查看文件

@@ -0,0 +1,30 @@
1
+package ZipTeamOrange.exception;
2
+
3
+import org.springframework.http.HttpStatus;
4
+import org.springframework.web.bind.annotation.ResponseStatus;
5
+
6
+@ResponseStatus(HttpStatus.NOT_FOUND)
7
+public class ResourceNotFoundException extends RuntimeException {
8
+    private String resourceName;
9
+    private String fieldName;
10
+    private Object fieldValue;
11
+
12
+    public ResourceNotFoundException( String resourceName, String fieldName, Object fieldValue) {
13
+        super(String.format("%s not found with %s : '%s'", resourceName, fieldName, fieldValue));
14
+        this.resourceName = resourceName;
15
+        this.fieldName = fieldName;
16
+        this.fieldValue = fieldValue;
17
+    }
18
+
19
+    public String getResourceName() {
20
+        return resourceName;
21
+    }
22
+
23
+    public String getFieldName() {
24
+        return fieldName;
25
+    }
26
+
27
+    public Object getFieldValue() {
28
+        return fieldValue;
29
+    }
30
+}

+ 0
- 54
ZipTeamOrange-server/src/main/java/ZipTeamOrange/message/Message.java 查看文件

@@ -1,54 +0,0 @@
1
-package ZipTeamOrange.message;
2
-
3
-import ZipTeamOrange.chat.Chat;
4
-import ZipTeamOrange.user.User;
5
-import javax.persistence.*;
6
-
7
-@Entity
8
-public class Message {
9
-
10
-    @Id
11
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
12
-    private long id;
13
-    String message;
14
-    @ManyToOne
15
-    @JoinColumn(name="user_id")
16
-    User user;
17
-
18
-    @ManyToOne
19
-    @JoinColumn(name = "chat_id")
20
-    private Chat chat;
21
-
22
-
23
-    public Message(String message) {
24
-        this.message = message;
25
-        //this.user = user;
26
-    }
27
-
28
-
29
-    public Message(){}
30
-
31
-    public long getId() {
32
-        return id;
33
-    }
34
-
35
-    public void setId(long id) {
36
-        this.id = id;
37
-    }
38
-
39
-    public String getMessage() {
40
-        return message;
41
-    }
42
-
43
-    public void setMessage(String message) {
44
-        this.message = message;
45
-    }
46
-
47
-    public User getUser() {
48
-        return user;
49
-    }
50
-
51
-    public void setUser(User user) {
52
-        this.user = user;
53
-    }
54
-}

+ 0
- 8
ZipTeamOrange-server/src/main/java/ZipTeamOrange/message/MessageRepository.java 查看文件

@@ -1,8 +0,0 @@
1
-package ZipTeamOrange.message;
2
-
3
-import org.springframework.data.jpa.repository.JpaRepository;
4
-
5
-public interface MessageRepository extends JpaRepository<Message, Long> {
6
-
7
-
8
-}

+ 38
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/model/Audit/UserDateAudit.java 查看文件

@@ -0,0 +1,38 @@
1
+package ZipTeamOrange.model.Audit;
2
+
3
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4
+import org.springframework.data.annotation.CreatedBy;
5
+import org.springframework.data.annotation.LastModifiedBy;
6
+
7
+import javax.persistence.Column;
8
+import javax.persistence.MappedSuperclass;
9
+
10
+@MappedSuperclass
11
+@JsonIgnoreProperties(
12
+        value = {"createdBy", "updatedBy"},
13
+        allowGetters = true
14
+)
15
+public abstract class UserDateAudit extends DateAudit {
16
+    @CreatedBy
17
+    @Column(updatable = false)
18
+    private Long createdBy;
19
+
20
+    @LastModifiedBy
21
+    private Long updatedBy;
22
+
23
+    public Long getCreatedBy() {
24
+        return createdBy;
25
+    }
26
+
27
+    public void setCreatedBy(Long createdBy) {
28
+        this.createdBy = createdBy;
29
+    }
30
+
31
+    public Long getUpdatedBy() {
32
+        return updatedBy;
33
+    }
34
+
35
+    public void setUpdatedBy(Long updatedBy) {
36
+        this.updatedBy = updatedBy;
37
+    }
38
+}

+ 17
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserIdentityAvailability.java 查看文件

@@ -0,0 +1,17 @@
1
+package ZipTeamOrange.payload;
2
+
3
+public class UserIdentityAvailability {
4
+    private Boolean available;
5
+
6
+    public UserIdentityAvailability(Boolean available) {
7
+        this.available = available;
8
+    }
9
+
10
+    public Boolean getAvailable() {
11
+        return available;
12
+    }
13
+
14
+    public void setAvailable(Boolean available) {
15
+        this.available = available;
16
+    }
17
+}

+ 50
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserProfile.java 查看文件

@@ -0,0 +1,50 @@
1
+package ZipTeamOrange.payload;
2
+
3
+import java.time.Instant;
4
+
5
+public class UserProfile {
6
+
7
+    private Long id;
8
+    private String username;
9
+    private Instant joinedAt;
10
+    private long messageCount;
11
+
12
+    public UserProfile(Long id, String username, Instant joinedAt, long messageCount) {
13
+        this.id = id;
14
+        this.username = username;
15
+        this.joinedAt = joinedAt;
16
+        this.messageCount = messageCount;
17
+    }
18
+
19
+    public Long getId() {
20
+        return id;
21
+    }
22
+
23
+    public void setId(Long id) {
24
+        this.id = id;
25
+    }
26
+
27
+    public String getUsername() {
28
+        return username;
29
+    }
30
+
31
+    public void setUsername(String username) {
32
+        this.username = username;
33
+    }
34
+
35
+    public Instant getJoinedAt() {
36
+        return joinedAt;
37
+    }
38
+
39
+    public void setJoinedAt(Instant joinedAt) {
40
+        this.joinedAt = joinedAt;
41
+    }
42
+
43
+    public long getMessageCount() {
44
+        return messageCount;
45
+    }
46
+
47
+    public void setMessageCount(long messageCount) {
48
+        this.messageCount = messageCount;
49
+    }
50
+}

+ 28
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/UserSummary.java 查看文件

@@ -0,0 +1,28 @@
1
+package ZipTeamOrange.payload;
2
+
3
+public class UserSummary {
4
+    private Long id;
5
+    private String username;
6
+
7
+    public UserSummary(Long id, String username, String name) {
8
+        this.id = id;
9
+        this.username = username;
10
+    }
11
+
12
+    public Long getId() {
13
+        return id;
14
+    }
15
+
16
+    public void setId(Long id) {
17
+        this.id = id;
18
+    }
19
+
20
+    public String getUsername() {
21
+        return username;
22
+    }
23
+
24
+    public void setUsername(String username) {
25
+        this.username = username;
26
+    }
27
+
28
+}

+ 49
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/ChatRequest.java 查看文件

@@ -0,0 +1,49 @@
1
+package ZipTeamOrange.payload.request;
2
+
3
+import ZipTeamOrange.model.User;
4
+
5
+import javax.validation.Valid;
6
+import javax.validation.constraints.NotBlank;
7
+import javax.validation.constraints.NotNull;
8
+import javax.validation.constraints.Size;
9
+import java.util.List;
10
+import java.util.Set;
11
+
12
+public class ChatRequest {
13
+    @NotBlank
14
+    @Size(max = 140)
15
+    private String topic;
16
+
17
+    @NotNull
18
+    @Valid
19
+    private List<MessageRequest> messages;
20
+
21
+    @NotNull
22
+    @Valid
23
+    private Set<User> users;
24
+
25
+    public String getTopic() {
26
+        return topic;
27
+    }
28
+
29
+    public void setTopic(String topic) {
30
+        this.topic = topic;
31
+    }
32
+
33
+    public List<MessageRequest> getMessages() {
34
+        return messages;
35
+    }
36
+
37
+    public void setMessages(List<MessageRequest> messages) {
38
+        this.messages = messages;
39
+    }
40
+
41
+    public Set<User> getUsers() {
42
+        return users;
43
+    }
44
+
45
+    public void setUsers(Set<User> users) {
46
+        this.users = users;
47
+    }
48
+
49
+}

+ 27
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/LoginRequest.java 查看文件

@@ -0,0 +1,27 @@
1
+package ZipTeamOrange.payload.request;
2
+
3
+import javax.validation.constraints.NotBlank;
4
+
5
+public class LoginRequest {
6
+    @NotBlank
7
+    private String usernameOrEmail;
8
+
9
+    @NotBlank
10
+    private String password;
11
+
12
+    public String getUsernameOrEmail() {
13
+        return usernameOrEmail;
14
+    }
15
+
16
+    public void setUsernameOrEmail(String usernameOrEmail) {
17
+        this.usernameOrEmail = usernameOrEmail;
18
+    }
19
+
20
+    public String getPassword() {
21
+        return password;
22
+    }
23
+
24
+    public void setPassword(String password) {
25
+        this.password = password;
26
+    }
27
+}

+ 31
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/MessageRequest.java 查看文件

@@ -0,0 +1,31 @@
1
+package ZipTeamOrange.payload.request;
2
+
3
+import ZipTeamOrange.model.User;
4
+
5
+import javax.validation.constraints.NotBlank;
6
+import javax.validation.constraints.Size;
7
+
8
+public class MessageRequest {
9
+    @NotBlank
10
+    @Size(max = 40)
11
+    private String text;
12
+
13
+    @NotBlank
14
+    private User user;
15
+
16
+    public User getUser() {
17
+        return user;
18
+    }
19
+
20
+    public void setUser(User user) {
21
+        this.user = user;
22
+    }
23
+
24
+    public String getText() {
25
+        return text;
26
+    }
27
+
28
+    public void setText(String text) {
29
+        this.text = text;
30
+    }
31
+}

+ 45
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/request/SignUpRequest.java 查看文件

@@ -0,0 +1,45 @@
1
+package ZipTeamOrange.payload.request;
2
+
3
+import javax.validation.constraints.Email;
4
+import javax.validation.constraints.NotBlank;
5
+import javax.validation.constraints.Size;
6
+
7
+public class SignUpRequest {
8
+
9
+    @NotBlank
10
+    @Size(min = 3, max = 15)
11
+    private String username;
12
+
13
+    @NotBlank
14
+    @Size(max = 40)
15
+    @Email
16
+    private String email;
17
+
18
+    @NotBlank
19
+    @Size(min = 6, max = 20)
20
+    private String password;
21
+
22
+    public String getUsername() {
23
+        return username;
24
+    }
25
+
26
+    public void setUsername(String username) {
27
+        this.username = username;
28
+    }
29
+
30
+    public String getEmail() {
31
+        return email;
32
+    }
33
+
34
+    public void setEmail(String email) {
35
+        this.email = email;
36
+    }
37
+
38
+    public String getPassword() {
39
+        return password;
40
+    }
41
+
42
+    public void setPassword(String password) {
43
+        this.password = password;
44
+    }
45
+}

+ 27
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ApiResponse.java 查看文件

@@ -0,0 +1,27 @@
1
+package ZipTeamOrange.payload.response;
2
+
3
+public class ApiResponse {
4
+    private Boolean success;
5
+    private String message;
6
+
7
+    public ApiResponse(Boolean success, String message) {
8
+        this.success = success;
9
+        this.message = message;
10
+    }
11
+
12
+    public Boolean getSuccess() {
13
+        return success;
14
+    }
15
+
16
+    public void setSuccess(Boolean success) {
17
+        this.success = success;
18
+    }
19
+
20
+    public String getMessage() {
21
+        return message;
22
+    }
23
+
24
+    public void setMessage(String message) {
25
+        this.message = message;
26
+    }
27
+}

+ 4
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ChatResonse.java 查看文件

@@ -0,0 +1,4 @@
1
+package ZipTeamOrange.payload.response;
2
+
3
+public class ChatResonse {
4
+}

+ 6
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/ChatResponse.java 查看文件

@@ -0,0 +1,6 @@
1
+package ZipTeamOrange.payload.response;
2
+
3
+public class ChatResponse {
4
+
5
+
6
+}

+ 26
- 0
ZipTeamOrange-server/src/main/java/ZipTeamOrange/payload/response/JwtAuthenticationResponse.java 查看文件

@@ -0,0 +1,26 @@
1
+package ZipTeamOrange.payload.response;
2
+
3
+public class JwtAuthenticationResponse {
4
+    private String accessToken;
5
+    private String tokenType = "Bearer";
6
+
7
+    public JwtAuthenticationResponse(String accessToken) {
8
+        this.accessToken = accessToken;
9
+    }
10
+
11
+    public String getAccessToken() {
12
+        return accessToken;
13
+    }
14
+
15
+    public void setAccessToken(String accessToken) {
16
+        this.accessToken = accessToken;
17
+    }
18
+
19
+    public String getTokenType() {
20
+        return tokenType;
21
+    }
22
+
23
+    public void setTokenType(String tokenType) {
24
+        this.tokenType = tokenType;
25
+    }
26
+}

+ 0
- 8
ZipTeamOrange-server/src/main/java/ZipTeamOrange/user/UserRepository.java 查看文件

@@ -1,8 +0,0 @@
1
-package ZipTeamOrange.user;
2
-
3
-import org.springframework.data.jpa.repository.JpaRepository;
4
-
5
-
6
-public interface UserRepository extends JpaRepository<User, Long>{
7
-
8
-}

+ 23
- 1
ZipTeamOrange-server/src/main/resources/application.properties 查看文件

@@ -1,3 +1,24 @@
1
+<<<<<<< HEAD
2
+#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
3
+spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
4
+spring.jpa.hibernate.ddl-auto=create-drop
5
+
6
+spring.datasource.url=jdbc:mysql://localhost:3306/ZipTeamOrange?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
7
+spring.datasource.username=root
8
+spring.datasource.password=password
9
+
10
+## Hibernate Logging
11
+logging.level.org.hibernate.SQL= DEBUG
12
+
13
+## Jackson Properties
14
+spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
15
+spring.jackson.time-zone= UTC
16
+logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
17
+
18
+## App Properties
19
+app.jwtSecret= JWTSuperSecretKey
20
+app.jwtExpirationInMs = 604800000
21
+=======
1 22
 #spring.datasource.url= postgres://vanvxvunakzykh:7f9d6108e7c2676b57af5eb672250e42c960147e28ba8786bb45ffa0efb5b866@ec2-75-101-142-91.compute-1.amazonaws.com:5432/d4i371u3ci642k
2 23
 #spring.datasource.driverClassName=org.postgresql.Driver
3 24
 #spring.datasource.maxActive=10
@@ -16,4 +37,5 @@ spring.jpa.hibernate.ddl-auto=create-drop
16 37
 spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
17 38
 
18 39
 # Because detection is disabled you have to set correct dialect by hand.
19
-spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
40
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
41
+>>>>>>> e9af7a6a8011fcb914952fcfb97bc9d9550b2637

+ 3
- 0
ZipTeamOrange-server/src/main/resources/data.sql 查看文件

@@ -0,0 +1,3 @@
1
+insert into roles(name) values ('ROLE_ADMIN');
2
+insert into roles(name) values ('ROLE_USER');
3
+--select count (m.id) from Messages where m.userId = userId;