Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset password #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/app/login.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,14 @@ describe('LoginService', () => {
expect(NavbarMock.checkLoggedIn).toHaveBeenCalled();
httpMock.verify();
});

it('should call /api/forgot_password correctly', () => {
let httpMock = TestBed.get(HttpTestingController);
service.resetPassword('testRCS');
let req = httpMock.expectOne(apiServer + '/api/forgot_password');
req.flush("");
expect(req.request.method).toBe('POST');
expect(req.request.body).toBe('{"rcsid":"testRCS"}');
httpMock.verify();
});
});
13 changes: 13 additions & 0 deletions src/app/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ export class LoginService implements CanActivate {
);
}

resetPassword(RCSid):void {
const headers = new HttpHeaders().set('Content-Type', 'application/json');
let body = JSON.stringify({rcsid:RCSid});
this.http.post<any>(apiServer + "/api/forgot_password", body, {headers: headers}).subscribe(
data => {
this.reload();
},
err => {
console.error("Server Error: ", err);
}
);
}

reload():void {
window.location.reload();
}
Expand Down
20 changes: 20 additions & 0 deletions src/app/navbar/navbar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<li class="nav-item" [hidden]="!loggedIn">
<a class="nav-link" onclick="document.getElementById('passwordChange').style.display='block'; return false" href='#'>Change Password</a>
</li>
<li class="nav-item" [hidden]="loggedIn">
</li>
<li class="nav-item" [hidden]="!loggedIn">
<a class="nav-link" placement="right" href="#" (click)="logout();">Logout</a>
</li>
Expand All @@ -54,6 +56,7 @@ <h2> Login </h2>
<div class="bad-request" id="badLogin">
Incorrect username or password!
</div>
<a onclick="document.getElementById('passwordReset').style.display='block'; return false" href='#'>Forgot Password? Click here to reset</a>
<div class="modal-footer" style="background-color:white">
<button class="btn btn-primary" (click)="login(Username.value, Password.value)">Login</button>
</div>
Expand Down Expand Up @@ -97,3 +100,20 @@ <h2> Change Password </h2>
</div>
</form>
</div>

<!-- Password Reset Form -->
<div id="passwordReset" class="modal" *ngIf="!loggedIn">
<button onclick="document.getElementById('passwordReset').style.display='none'" class="close" title="Close Modal">&times;</button>
<!-- Modal Content -->
<form class="modal-content animate">
<h2> Reset Password </h2>
<div class="modal-body">
<div>
<input #userReset type="text" placeholder="Enter Username" aria-label="Current Username" required>
</div>
</div>
<div class="modal-footer" style="background-color:white">
<button class="btn btn-primary" (click)="resetPassword(userReset.value)">Reset Password</button>
</div>
</form>
</div>
4 changes: 4 additions & 0 deletions src/app/navbar/navbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export class NavbarComponent implements OnInit {
this.loginService.changePassword(username, oldPass, newPass);
}

resetPassword(username):void {
this.loginService.resetPassword(username);
}

showFailedLogin():void {
document.getElementById('badLogin').style.visibility = 'visible';
}
Expand Down