Skip to content
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
26 changes: 26 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"pretty-bytes": "^6.0.0",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^17.0.2",
"react-gravatar": "^2.6.3",
"react-loading-overlay-ts": "^1.0.4",
Expand Down
99 changes: 75 additions & 24 deletions frontend/src/actions/user.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
import {V2} from "../openapi";
import { V2 } from "../openapi";
import Cookies from "universal-cookie";
import config from "../app.config";
import {handleErrors} from "./common";
import {ADD_GROUP_MEMBER} from "./group";

const cookies = new Cookies();

export const userActions = {
login,
logout
logout,
};

// TODO need to clean up this file with all the mixed login/logout methods

export async function loginHelper(email, password, first_name=null, last_name=null, register = false) {
const data = {"email": email, "password": password};
export async function loginHelper(
email,
password,
first_name = null,
last_name = null,
register = false
) {
const data = { email: email, password: password };
if (register) {
return V2.LoginService.saveUserApiV2UsersPost({...data, "first_name":first_name, "last_name": last_name})
.then(user => {return user;})
.catch(reason => {
// logout();
return {"errorMsg": `Failed to register a user! ${reason}`};
return V2.LoginService.saveUserApiV2UsersPost({
...data,
first_name: first_name,
last_name: last_name,
})
.then((user) => {
return user;
})
.catch((reason) => {
// logout();
return { errorMsg: `Failed to register a user! ${reason}` };
});
} else {
return V2.LoginService.loginApiV2LoginPost(data)
.then(user => {return user;})
.catch(reason => {
// logout();
return {"errorMsg": `Failed to login a user! ${reason}`};
.then((user) => {
return user;
})
.catch((reason) => {
// logout();
return { errorMsg: `Failed to login a user! ${reason}` };
});
}
}

export async function logoutHelper(){
const headers = {"Authorization": cookies.get("Authorization")};
export async function logoutHelper() {
const headers = { Authorization: cookies.get("Authorization") };
V2.OpenAPI.TOKEN = undefined;
cookies.remove("Authorization", { path: "/" });
return await fetch(config.KeycloakLogout, { method: "GET", headers: headers});
return await fetch(config.KeycloakLogout, {
method: "GET",
headers: headers,
});
}

export const LOGIN_ERROR = "LOGIN_ERROR";
Expand All @@ -61,7 +76,10 @@ export function login(email, password) {
} else {
return dispatch({
type: LOGIN_ERROR,
errorMsg: json["errorMsg"] !== undefined && json["errorMsg"] !== "" ? json["errorMsg"]: "Email/Password incorrect!"
errorMsg:
json["errorMsg"] !== undefined && json["errorMsg"] !== ""
? json["errorMsg"]
: "Email/Password incorrect!",
});
}
};
Expand All @@ -77,7 +95,10 @@ export function register(email, password, firstname, lastname) {
} else {
return dispatch({
type: REGISTER_ERROR,
errorMsg: json["errorMsg"] !== undefined && json["errorMsg"] !== "" ? json["errorMsg"]: "Fail to register!"
errorMsg:
json["errorMsg"] !== undefined && json["errorMsg"] !== ""
? json["errorMsg"]
: "Fail to register!",
});
}
};
Expand All @@ -93,18 +114,48 @@ export function logout() {
}

export const LIST_USERS = "LIST_USERS";
export function fetchAllUsers(skip=0, limit=101){

export function fetchAllUsers(skip = 0, limit = 101) {
return (dispatch) => {
return V2.UsersService.getUsersApiV2UsersGet(skip, limit)
.then(json => {
.then((json) => {
dispatch({
type: LIST_USERS,
users: json,
receivedAt: Date.now(),
});
})
.catch(reason => {
dispatch(fetchAllUsers(skip=0, limit=21));
.catch((reason) => {
dispatch(fetchAllUsers((skip = 0), (limit = 21)));
});
};
}

export const GENERATE_API_KEY = "GENERATE_API_KEY";

export function generateApiKey(minutes = 30) {
return (dispatch) => {
return V2.UsersService.generateUserApiKeyApiV2UsersKeysPost(minutes)
.then((json) => {
dispatch({
type: GENERATE_API_KEY,
apiKey: json,
receivedAt: Date.now(),
});
})
.catch((reason) => {
dispatch(generateApiKey((minutes = 30)));
});
};
}

export const RESET_API_KEY = "RESET_API_KEY";

export function resetApiKey() {
return (dispatch) => {
dispatch({
type: RESET_API_KEY,
receivedAt: Date.now(),
});
};
}
Loading