Skip to content
Snippets Groups Projects
Commit a95a3c7b authored by michael.minelli's avatar michael.minelli
Browse files

SessionManager => Add login function

parent ee8556c8
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,9 @@ import * as jwt from 'jsonwebtoken';
import User from '../models/User';
import LocalConfig from '../Config/LocalConfig/LocalConfig';
import LocalConfigKeys from '../Config/LocalConfig/LocalConfigKeys';
import axios, { AxiosError } from 'axios';
import logger from '../shared/logging/WinstonLogger';
import HttpManager from './HttpManager';
class SessionManager {
......@@ -41,6 +44,28 @@ class SessionManager {
LocalConfig.updateConfig(LocalConfigKeys.API_TOKEN, token);
}
async login(user: string, password: string) {
try {
const response = await axios.post(HttpManager.LOGIN_URL, {
user : user,
password: password
}, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
logger.info('Login successful');
} catch ( error ) {
if ( error instanceof AxiosError ) {
if ( error.response && error.response.status === 404 ) {
logger.error(`User not found or password incorrect`);
}
} else {
logger.error(`Login error: ${ error }`);
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment