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 #460

Merged
merged 11 commits into from
Sep 1, 2023
Merged
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
99 changes: 85 additions & 14 deletions backend/src/nodemailer.js

Large diffs are not rendered by default.

56 changes: 37 additions & 19 deletions frontend/src/app/Services/http-logger.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent, HttpErrorResponse, HttpStatusCode} from '@angular/common/http';
import { tap, catchError} from 'rxjs/operators';
import { Injectable } from "@angular/core";
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
HttpEvent,
HttpErrorResponse,
HttpStatusCode,
} from "@angular/common/http";
import { tap, catchError } from "rxjs/operators";
import { NGXLogger } from "ngx-logger";
import { Observable, throwError } from "rxjs";

@Injectable()
export class HttpLoggerInterceptor implements HttpInterceptor {
constructor(private logger: NGXLogger) {
console.log("constructor http interceptor");

}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
const startTime = Date.now();

const detail = {'Time': startTime, 'reqMethod': req.method, 'reqURL': req.urlWithParams};
this.logger.log('sended request', detail, req.headers);
const detail = {
Time: startTime,
reqMethod: req.method,
reqURL: req.urlWithParams,
};
this.logger.log("sended request", detail, req.headers);

return next.handle(req).pipe(
tap( event => {
console.debug('http-logger tap', event)
}),
catchError((err: HttpErrorResponse)=>{
if(window.localStorage.getItem('login') !== 'true') {
if(err.status == HttpStatusCode.Unauthorized){
if(window.location.pathname != '/login')window.location.href = '/login'
window.localStorage.setItem("login", 'false')}
tap((event) => {
console.debug("http-logger tap", event);
}),
catchError((err: HttpErrorResponse) => {
if (window.localStorage.getItem("login") !== "true") {
if (err.status == HttpStatusCode.Unauthorized) {
if (
window.location.pathname != "/login" &&
window.location.pathname != "/resetpasswordconfirm"
)
window.location.href = "/login";
window.localStorage.setItem("login", "false");
}
console.error(err);
return throwError(()=> err)
})
}
console.error(err);
return throwError(() => err);
})
);
}
}
}
199 changes: 109 additions & 90 deletions frontend/src/app/Services/login.service.ts
Original file line number Diff line number Diff line change
@@ -1,176 +1,195 @@
import { EventEmitter, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ApiService } from '../Services/api.service';
import { HttpClient } from '@angular/common/http';
import { catchError, tap } from 'rxjs/operators';
import { EventEmitter, Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { ApiService } from "../Services/api.service";
import { HttpClient } from "@angular/common/http";
import { catchError, tap } from "rxjs/operators";

/**
* Service for communication between login component and the backend
*/
@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class LoginService {

/**
* @ignore
*/
constructor(public apiService: ApiService, private http: HttpClient) { }
* @ignore
*/
constructor(public apiService: ApiService, private http: HttpClient) {}
/**
* Event emitter to logout the user
*/
* Event emitter to logout the user
*/
public logoutEvent = new EventEmitter();
/**
* Starts the github login
*/
* Starts the github login
*/
public githubLogin() {
const scope = 'repo';
const AUTHORIZE_URL = 'https://github.com/login/oauth/authorize';
const s = `${AUTHORIZE_URL}?scope=${scope}&client_id=${localStorage.getItem('clientId')}`;
const scope = "repo";
const AUTHORIZE_URL = "https://github.com/login/oauth/authorize";
const s = `${AUTHORIZE_URL}?scope=${scope}&client_id=${localStorage.getItem(
"clientId"
)}`;
window.location.href = s;
}
/**
* Returns the callback from github to the backend
* @param code
* @returns
*/
* Returns the callback from github to the backend
* @param code
* @returns
*/
githubCallback(code: string): Observable<any> {
const url = this.apiService.apiServer + '/user/callback?code=' + code;
return this.http.get(url, { withCredentials: true })
.pipe(tap(_ => {
const url = this.apiService.apiServer + "/user/callback?code=" + code;
return this.http.get(url, { withCredentials: true }).pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError));
catchError(this.apiService.handleError)
);
}

/**
* Loggs in the user with a github token
* @param login
* @param id
* @returns
*/
* Loggs in the user with a github token
* @param login
* @param id
* @returns
*/
loginGithubToken(login: string, id): Observable<any> {
const str = this.apiService.apiServer + '/user/githubLogin';
const str = this.apiService.apiServer + "/user/githubLogin";
const user = { login, id };

return this.http.post<any>(str, user, ApiService.getOptions())
.pipe(tap(_ => {
return this.http.post<any>(str, user, ApiService.getOptions()).pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError));
catchError(this.apiService.handleError)
);
}
/**
* Merges Seed-Test account and github account
* @param userId
* @param login
* @param id
* @returns
*/
* Merges Seed-Test account and github account
* @param userId
* @param login
* @param id
* @returns
*/
mergeAccountGithub(userId: string, login: string, id: any) {
const str = this.apiService.apiServer + '/user/mergeGithub';
const body = {userId, login, id};
const str = this.apiService.apiServer + "/user/mergeGithub";
const body = { userId, login, id };

return this.http.post<any>(str, body, ApiService.getOptions())
.pipe(tap(_ => {
//
}),
catchError(this.apiService.handleError));
return this.http.post<any>(str, body, ApiService.getOptions()).pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError)
);
}
/**
* Loggs in a user
* @param user
* @returns
*/
* Loggs in a user
* @param user
* @returns
*/
loginUser(user): Observable<any> {
const str = this.apiService.apiServer + '/user/login';
const str = this.apiService.apiServer + "/user/login";

return this.http.post<any>(str, user, ApiService.getOptions())
.pipe(tap(_ => {
return this.http.post<any>(str, user, ApiService.getOptions()).pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError));
catchError(this.apiService.handleError)
);
}
/**
* Loggs in the user into jira
* @param jiraName
* @param jiraPassword
* @param jiraServer
* @returns
*/
*/
jiraLogin(jiraName: string, jiraPassword: string, jiraServer: string) {
const body = {
jiraAccountName: jiraName,
jiraPassword: jiraPassword,
jiraServer: jiraServer
jiraServer: jiraServer,
};
return this.http.post(this.apiService.apiServer + '/jira/login', body, ApiService.getOptions())
.pipe(tap(resp => {
localStorage.setItem('JiraSession', resp.toString());
}));
return this.http
.post(
this.apiService.apiServer + "/jira/login",
body,
ApiService.getOptions()
)
.pipe(
tap((resp) => {
localStorage.setItem("JiraSession", resp.toString());
})
);
}
/**
* Requests a password reset
* @param email
* @returns
*/
*/
public requestReset(email: string): Observable<any> {
const body = { 'email': email };
const body = { email: email };
return this.http
.post<any>(this.apiService.apiServer + '/user/resetpassword/', body)
.pipe(tap(_ => {
//
}));
.post<any>(this.apiService.apiServer + "/user/resetpassword/", body)
.pipe(
tap((_) => {
//
})
);
}

/**
* Change the old password into the new password
* @param uuid
* @param password
* @returns
*/
*/
confirmReset(uuid: string, password: string): Observable<any> {
const body = { 'uuid': uuid, 'password': password };
const body = { uuid: uuid, password: password };
return this.http
.patch<any>(this.apiService.apiServer + '/user/reset', body)
.pipe(tap(_ => {
//
}));
.patch<any>(this.apiService.apiServer + "/user/reset", body)
.pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError)
);
}
/**
* If the user is logged in
* @returns
*/
* If the user is logged in
* @returns
*/
isLoggedIn(): boolean {
return !!localStorage.getItem('login');
return !!localStorage.getItem("login");
}
/**
* Logs out the user
* @returns
*/
*/
logoutUser() {
const url = this.apiService.apiServer + '/user/logout';
localStorage.removeItem('login');
return this.http.get<string[]>(url, ApiService.getOptions())
.pipe(tap(_ => {
const url = this.apiService.apiServer + "/user/logout";
localStorage.removeItem("login");
return this.http.get<string[]>(url, ApiService.getOptions()).pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError));
catchError(this.apiService.handleError)
);
}
/**
* Registers a user for a seed-test account
* @param email
* @param password
* @param userId
* @returns
*/
*/
registerUser(email: string, password: string, userId: any): Observable<any> {
const user = { email, password, userId };
return this.http
.post<any>(this.apiService.apiServer + '/user/register', user)
.pipe(tap(_ => {
//
}),
catchError(this.apiService.handleError));
.post<any>(this.apiService.apiServer + "/user/register", user)
.pipe(
tap((_) => {
//
}),
catchError(this.apiService.handleError)
);
}

}
Loading
Loading