Skip to content
This repository was archived by the owner on Nov 21, 2025. It is now read-only.

Commit b3e346c

Browse files
author
YangJiao
committed
Remember me function
Signed-off-by: YangJiao <[email protected]>
1 parent 73a1e55 commit b3e346c

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

ui/src/app/pages/nav/nav.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ export class NavComponent implements OnInit {
2323
"readSddcSoftwareConfigByID","readSddcSoftwareConfigByVRO","readSddcSoftwareConfigByVC","readSddcSoftwareConfigByUserAndPage","readVROsSddcSoftwareConfigByUser","readSddcSoftwareConfigByTypeAndUser"];
2424
servermapping:string []= ["updateServerMapping","readMappingsByVROIDAndPage","readMappingsByVCIDAndPage","readSddcSoftwareConfigByTypeAndUser"];
2525
facility:string[] = ["createFacilitySoftwareConfig","readFacilityByType","readFacilityByPage"];
26-
26+
2727
setting:string[] = ["createSensorSetting","readSensorSettingsByPage","updateSensorSetting","deleteSensorSetting","startFullMappingAggregation","generateServerPDUMapping","readUnMappedServers"];
2828
sensorsetting:string[] = ["createSensorSetting","readSensorSettingsByPage","updateSensorSetting","deleteSensorSetting"];
2929
systemSetting:string[] = ["startFullMappingAggregation","generateServerPDUMapping","readUnMappedServers"];
3030
assetmanagement:string [] = ["createAnAsset", "updateAsset", "deleteAsset", "readAsset", "readAssetBySource"];
3131
adaptermanagement:string [] = ["createFacilityAdapter","updateFacilityAdapter","readAnFacilityAdapterById","deleteAnFacilityAdapterById","readFacilityAdaptersByPage"];
3232
constructor(private activedRoute:ActivatedRoute,private router: Router,private auth:AuthenticationService) { }
3333
logout(){
34+
localStorage.clear()
3435
this.auth.logout();
35-
3636
}
3737
userprofile(){
3838
this.router.navigate(["/ui/nav/user/user-profile"]);
3939
}
40-
40+
4141
ngOnInit() {
4242
this.username = this.auth.getUsername();
4343
}

ui/src/app/pages/user-login/user-login.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h3 class="welcome">Welcome to</h3>
1818
</clr-password-container>
1919
<clr-checkbox-wrapper>
2020
<label>Remember me</label>
21-
<input type="checkbox" name="rememberMe" clrCheckbox />
21+
<input type="checkbox" name="rememberMe" clrCheckbox [(ngModel)]="user.rememberMe"/>
2222
</clr-checkbox-wrapper>
2323
<div *ngIf="tips" class="error active" >
2424
{{textContent}}

ui/src/app/pages/user-login/user-login.component.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,32 @@ export class UserLoginComponent implements OnInit {
1919
tips:boolean = false;
2020
textContent = "";
2121
user ={
22-
id:"",
23-
username:"",
24-
password:"",
22+
id:"",
23+
username:"",
24+
password:"",
25+
rememberMe:false
2526
}
2627
constructor(private router: Router,private data:AuthenticationService,private ls:LocalStorage) {
2728
}
2829
userName:string
29-
password:string
30+
password:string
31+
rememberMe:boolean
3032
toLogin(){
3133
this.userName = this.user.username;
3234
this.password = this.user.password;
35+
this.rememberMe = this.user.rememberMe;
36+
3337
if(this.userName == ""){
3438
this.tips = true;
3539
this.textContent = "please input a userName";
36-
3740
}else if(this.password == ""){
3841
this.tips = true;
3942
this.textContent = "please input a password";
4043
}else{
4144
this.login(this.userName,this.password);
4245
}
4346
}
44-
47+
4548
login(userName,password){
4649
let userInfoBase64:string = "";
4750
let user:string = "";
@@ -55,6 +58,10 @@ export class UserLoginComponent implements OnInit {
5558
privilegeName = priData;
5659
let currentUser = btoa(JSON.stringify({username: JSON.parse(user).sub, token: res['access_token'], authorities:privilegeName,expires_in:res['expires_in']}));
5760
sessionStorage.setItem('currentUser', currentUser);
61+
if (this.rememberMe) {
62+
localStorage.setItem("username", btoa(userName));
63+
localStorage.setItem("password", btoa(password));
64+
}
5865
this.tips = false;
5966
this.router.navigate(["ui/nav"]);
6067
}
@@ -67,11 +74,16 @@ export class UserLoginComponent implements OnInit {
6774
this.tips = true;
6875
this.textContent = "Internal error";
6976
}
70-
71-
})
77+
})
78+
}
79+
80+
ngOnInit() {
81+
let username = localStorage.getItem("username");
82+
let password = localStorage.getItem("password");
83+
if (username == null || password == null) {
84+
return
85+
}
86+
this.login(atob(username), atob(password));
7287
}
73-
ngOnInit() {
74-
75-
}
7688

7789
}

0 commit comments

Comments
 (0)