BETTERZON-111: Adding service functions for login and registration (#64)

This commit is contained in:
Patrick 2021-05-26 20:51:19 +02:00 committed by GitHub
parent f28dae3272
commit 36173c6117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -207,4 +207,48 @@ export class ApiService {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`); process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
} }
} }
/* __ __
/ / / /_______ __________
/ / / / ___/ _ \/ ___/ ___/
/ /_/ (__ ) __/ / (__ )
\____/____/\___/_/ /____/
*/
/**
* Registers a new user with the API
* @param username The username for the new user
* @param password The password for the new user
* @param email The email address for the new user
* @return Observable<any> The observable response of the api
*/
registerUser(username: string, password: string, email: string): Observable<any> {
try {
return this.http.post((this.apiUrl + '/users/register'), JSON.stringify({
username,
password,
email
}));
} catch (exception) {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
}
}
/**
* Logs a user in with the api
* @param username The username of the user to log in
* @param password The password of the user to log in
* @return Observable<any> The observable response of the api
*/
loginUser(username: string, password: string): Observable<any> {
try {
return this.http.post((this.apiUrl + '/users/login'), JSON.stringify({
username,
password
}));
} catch (exception) {
process.stderr.write(`ERROR received from ${this.apiUrl}: ${exception}\n`);
}
}
} }