Quellcode durchsuchen

添加密码复杂度处理逻辑

heyiwen vor 1 Woche
Ursprung
Commit
c5d6fa93b1

+ 9 - 0
src/app/app.module.ts

@@ -50,10 +50,14 @@ import {UrlHelper} from "./utility/urlHelper";
 import {CertisfierDistributePageModule} from "../pages/certisfier/certisfierdistribute/certisfierdistribute.module";
 import {CardMessagePageModule} from "../pages/myexam/CardMessage/cardMessage.module";
 import {CertisfierDistributePage} from "../pages/certisfier/certisfierdistribute/certisfierdistribute";
+import {ChangePassPageModule} from "../pages/changepass/changepass.module";
+import {ChangePassPage} from "../pages/changepass/changepass";
+import {EqualValidatorDirective} from "./directives/equal-validator.directive";
 
 
 @NgModule({
   declarations: [
+    EqualValidatorDirective,
     EMISWeb
   ],
   imports: [
@@ -71,6 +75,7 @@ import {CertisfierDistributePage} from "../pages/certisfier/certisfierdistribute
     LoginPageModule,
     UserRegistPageModule,
     MePageModule,
+    ChangePassPageModule,
     RegisterPageModule,
     SubjectPageModule,
     MustReadPageModule,
@@ -89,6 +94,7 @@ import {CertisfierDistributePage} from "../pages/certisfier/certisfierdistribute
     AnnouncementPage,
     AnnouncementListPage,
     MePage,
+    ChangePassPage,
     RegisterPage,
     SubjectPage,
     MustReadPage,
@@ -114,6 +120,9 @@ import {CertisfierDistributePage} from "../pages/certisfier/certisfierdistribute
     ComponentsModule,
     UrlHelper,
     {provide: ErrorHandler, useClass: IonicErrorHandler}
+  ],
+  exports: [
+    EqualValidatorDirective
   ]
 })
 export class AppModule {}

+ 19 - 0
src/app/services/user/user.service.ts

@@ -9,6 +9,7 @@ import {StudentInfoView} from "../../../viewmodel/user/studentInfo";
 import {StudentView} from "../../../viewmodel/user/studentView";
 import {DictionaryItemView} from "../../../viewmodel/common/dictionaryItemView";
 import {RegistView} from "../../../viewmodel/user/registView";
+import {ChangePassView} from "../../../viewmodel/user/changePassView";
 
 @Injectable()
 export class UserService {
@@ -52,6 +53,7 @@ export class UserService {
               UserID: student.UserID,
               LoginID: loginID,
               UserName: student.UserName,
+              IDNumber: student.IDNumber,
               classmajorID: student.ClassMajorID,
               classmajorName: student.ClassMajorName
             }
@@ -232,6 +234,23 @@ export class UserService {
       })
   }
 
+  changePass(changePassView: ChangePassView): Promise<ResultMessage>{
+    let url: string = AppConfig.getServiceUrl();
+    url += "UserServices/ChangePassword";
+    let openID: string = localStorage.openID;
+    if (!openID) openID = null;
+    return this.http.post(url, JSON.stringify({ changePasswordView: changePassView, userID: localStorage.userID }), {headers: ServiceCommon.getHeader()})
+      .toPromise()
+      .then(res => {
+        let resMessage = res.json();
+        return{
+          isSuccess: resMessage.IsSuccess,
+          message: resMessage.Message,
+          data: resMessage.Data
+        } as ResultMessage;
+      })
+  }
+
   unbind(): Promise<ResultMessage> {
     let url: string = AppConfig.getServiceUrl();
     url += "UserServices/UnBind";

+ 29 - 10
src/pages/changepass/changepass.html

@@ -1,10 +1,29 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-  <meta charset="UTF-8">
-  <title>Title</title>
-</head>
-<body>
-
-</body>
-</html>
+<ion-header>
+</ion-header>
+<ion-content>
+  <form role="form" #editform="ngForm" (ngSubmit)="confim(editform.valid)" novalidate>
+    <ion-item-group>
+      <ion-item>
+        <ion-label stacked>密码*</ion-label>
+        <ion-input #password="ngModel" [(ngModel)]="changePass.OldPassword" name="password" required placeholder="原密码" type="password"></ion-input>
+      </ion-item>
+      <ion-item>
+        <ion-label stacked>新密码*</ion-label>
+        <ion-input #newPassword="ngModel" [(ngModel)]="changePass.Password" validateEqual="confirmPass" name="newPassword" required pattern="^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$" placeholder="新密码" type="password"></ion-input>
+      </ion-item>
+      <span *ngIf="(newPassword.touched || newPassword.dirty) && newPassword.hasError('required')" class="help-block">请输入密码</span>
+      <ion-item>
+        <ion-label stacked>密码确认*</ion-label>
+        <ion-input type="password" #confirmPass="ngModel" validateEqual="newPassword" name="confirmPass" required placeholder="再次输入密码" [(ngModel)]="changePass.PasswordRep"></ion-input>
+      </ion-item>
+      <span *ngIf="newPassword.hasError('pattern')" class="help-block">密码须包含大小写英文、特殊字符、数字且长度大于或等于8位</span>
+      <span *ngIf="(confirmPass.touched || confirmPass.dirty) && confirmPass.hasError('required')" class="help-block">请再次输入密码</span>
+      <span *ngIf="(newPassword.touched || newPassword.dirty || confirmPass.touched || confirmPass.dirty) && (confirmPass.hasError('validateEqual') || newPassword.hasError('validateEqual'))" class="help-block">两次输入的密码必须一致</span>
+    </ion-item-group>
+    <ion-item-group>
+      <ion-item align-items-center>
+        <button type="submit" ion-button color="danger" [disabled]="editform.invalid" align-self-center round col-12>确定</button>
+      </ion-item>
+    </ion-item-group>
+  </form>
+</ion-content>

+ 20 - 0
src/pages/changepass/changepass.module.ts

@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { IonicPageModule } from 'ionic-angular';
+import { ChangePassPage } from "./changepass";
+import {ComponentsModule} from "../../app/components/components.module";
+import {FormsModule} from "@angular/forms";
+
+@NgModule({
+  declarations: [
+    ChangePassPage
+  ],
+  imports: [
+    IonicPageModule.forChild(ChangePassPage),
+    ComponentsModule,
+    FormsModule
+  ],
+  exports: [
+    ChangePassPage
+  ]
+})
+export class ChangePassPageModule {}

+ 3 - 0
src/pages/changepass/changepass.scss

@@ -0,0 +1,3 @@
+page-changepass {
+
+}

+ 74 - 0
src/pages/changepass/changepass.ts

@@ -0,0 +1,74 @@
+import {AlertController, IonicPage, NavController, NavParams, ToastController} from "ionic-angular";
+import {Component, Injectable} from '@angular/core';
+import {SystemService} from "../../app/services/system.service";
+import {DictionaryItemView} from "../../viewmodel/common/dictionaryItemView";
+import {RegistView} from "../../viewmodel/user/registView";
+import {UserService} from "../../app/services/user/user.service";
+import {HomePage} from "../home/home";
+import { ChangePassView } from "../../viewmodel/user/changePassView";
+import {LoginPage} from "../login/login";
+
+@IonicPage()
+@Injectable()
+@Component({
+  templateUrl: 'changepass.html'
+})
+export class ChangePassPage {
+  private changePass: ChangePassView = {
+    OldPassword: null,
+    Password: null,
+    PasswordRep: null
+  } as ChangePassView;
+
+  constructor(
+    public navCtrl: NavController,
+    public navParams: NavParams,
+    public toastCtrl: ToastController,
+    private userService: UserService,
+    private alertCtrl: AlertController) {
+
+  }
+
+  confim(valid) {
+    if (!valid) return;
+    this.userService.changePass(this.changePass).then(res => {
+      if (res.isSuccess) {
+        this.userService.unbind().then(res => {
+          if (res.isSuccess) {
+            this.alertCtrl.create({
+              title: '信息', message: '密码修改成功,即将重新登录。',
+              buttons: [{
+                text: '确定',
+                handler: () => {
+                  localStorage.removeItem("name");
+                  localStorage.removeItem("userID");
+                  localStorage.removeItem("loginID");
+                  this.navCtrl.push(LoginPage);
+                }
+              }]
+            }).present();
+          } else {
+            this.presentToast(res.message,"error");
+          }
+        });
+      } else {
+        this.presentToast(res.message,"error");
+      }
+    });
+  }
+
+  presentToast(message:string,classstyle:string) {
+    let toast = this.toastCtrl.create({
+      message:  message,
+      duration: 2000,
+      position: 'middle',
+      cssClass: classstyle
+    });
+
+    toast.onDidDismiss(() => {
+      //console.log('Dismissed toast');
+    });
+
+    toast.present();
+  }
+}

+ 26 - 7
src/pages/login/login.ts

@@ -7,6 +7,7 @@ import {StudentView} from '../../viewmodel/user/studentView';
 // import {TabPage} from "../tabs/tabs";
 import {HomePage} from "../home/home";
 import {UserRegistPage} from "../userregist/userregist";
+import {ChangePassPage} from "../changepass/changepass";
 
 @IonicPage()
 @Component({
@@ -50,10 +51,6 @@ export class LoginPage {
 	  				localStorage.removeItem("EMISPassword");
   				}
 
-          if (!(/^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$/g).test(this.loginForm.value.password)) {
-
-          }
-
   				this.loginSuccess(this.loginForm.value.userName);
   			} else {
   				this.loginFailed = true;
@@ -76,9 +73,31 @@ export class LoginPage {
           localStorage.name = student.UserName;
           localStorage.userID = student.UserID;
           localStorage.loginID = student.LoginID;
-          // localStorage.classmajorID = student.classmajorID;
-          // localStorage.classmajorName = student.classmajorName;
-				  this.navCtrl.push(HomePage);
+
+          if (!(/^(?=.*?[0-9])(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[#?!@$%^&*-]).{8,}$/g).test(this.loginForm.value.password)) {
+            this.alertCtrl.create({
+              message: '你的密码不符合系统的复杂度限制,请重新修改密码。',
+              buttons: [{
+                text: '确定',
+                handler: () => {
+                  this.navCtrl.push(ChangePassPage);
+                }
+              }]
+            }).present();
+          } else if (this.loginForm.value.password == 'Ab#888888'
+            || this.loginForm.value.password == 'Ab!' + student.IDNumber.substring(student.IDNumber.length - 6)) {
+            this.alertCtrl.create({
+              message: '你在重置密码后首次登录,请重新修改密码。',
+              buttons: [{
+                text: '确定',
+                handler: () => {
+                  this.navCtrl.push(ChangePassPage);
+                }
+              }]
+            }).present();
+          } else {
+            this.navCtrl.push(HomePage);
+          }
   			} else {
   				localStorage.removeItem("EMISPassword");
   				this.loginFailed = true;

+ 2 - 5
src/pages/userregist/userregist.module.ts

@@ -3,12 +3,10 @@ import { IonicPageModule } from 'ionic-angular';
 import { UserRegistPage } from "./userregist";
 import {ComponentsModule} from "../../app/components/components.module";
 import {FormsModule} from "@angular/forms";
-import {EqualValidatorDirective} from "../../app/directives/equal-validator.directive";
 
 @NgModule({
   declarations: [
-    UserRegistPage,
-    EqualValidatorDirective
+    UserRegistPage
   ],
   imports: [
     IonicPageModule.forChild(UserRegistPage),
@@ -16,8 +14,7 @@ import {EqualValidatorDirective} from "../../app/directives/equal-validator.dire
     FormsModule
   ],
   exports: [
-    UserRegistPage,
-    EqualValidatorDirective
+    UserRegistPage
   ]
 })
 export class UserRegistPageModule {}

+ 5 - 0
src/viewmodel/user/changePassView.ts

@@ -0,0 +1,5 @@
+export interface ChangePassView {
+  OldPassword: string;
+  Password: string;
+  PasswordRep: string;
+}