Skip to content

Commit

Permalink
Merge pull request #460 from adessoSE/Reset_Password
Browse files Browse the repository at this point in the history
Reset_Password
  • Loading branch information
dsorna authored Sep 1, 2023
2 parents 6354644 + 7cb5fc7 commit 6c6dfe2
Show file tree
Hide file tree
Showing 15 changed files with 958 additions and 435 deletions.
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

0 comments on commit 6c6dfe2

Please sign in to comment.