2019-12-16 08:49:10 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
|
|
|
|
import Api from "./Api";
|
|
|
|
|
import { ApiResponse } from "./ApiResponses";
|
2020-01-03 08:49:47 +00:00
|
|
|
import { getAppsmithConfigs } from "configs";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
export interface LoginUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateUserResponse extends ApiResponse {
|
|
|
|
|
email: string;
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ForgotPasswordRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ResetPasswordRequest {
|
|
|
|
|
token: string;
|
|
|
|
|
user: {
|
|
|
|
|
password: string;
|
|
|
|
|
email: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ResetPasswordVerifyTokenRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
token: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
export interface FetchUserResponse extends ApiResponse {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FetchUserRequest {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InviteUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
groupIds: string[];
|
|
|
|
|
status?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
class UserApi extends Api {
|
2019-12-23 12:16:33 +00:00
|
|
|
//TODO(abhinav): make a baseURL, to which the other paths are added.
|
2019-12-16 08:49:10 +00:00
|
|
|
static createURL = "v1/users";
|
|
|
|
|
static forgotPasswordURL = "v1/users/forgotPassword";
|
|
|
|
|
static verifyResetPasswordTokenURL = "v1/users/verifyPasswordResetToken";
|
|
|
|
|
static resetPasswordURL = "v1/users/resetPassword";
|
2019-12-23 12:16:33 +00:00
|
|
|
static fetchUserURL = "v1/users";
|
|
|
|
|
static inviteUserURL = "v1/users/invite";
|
2020-01-03 08:49:47 +00:00
|
|
|
static logoutURL = "/logout";
|
2019-12-16 08:49:10 +00:00
|
|
|
static createUser(
|
|
|
|
|
request: CreateUserRequest,
|
|
|
|
|
): AxiosPromise<CreateUserResponse> {
|
|
|
|
|
return Api.post(UserApi.createURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static forgotPassword(
|
|
|
|
|
request: ForgotPasswordRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.forgotPasswordURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static resetPassword(
|
|
|
|
|
request: ResetPasswordRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.resetPasswordURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static verifyResetPasswordToken(
|
|
|
|
|
request: ResetPasswordVerifyTokenRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.verifyResetPasswordTokenURL, request);
|
|
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
static fetchUser(request: FetchUserRequest): AxiosPromise<FetchUserResponse> {
|
|
|
|
|
return Api.get(UserApi.fetchUserURL + "/" + request.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inviteUser(request: InviteUserRequest): AxiosPromise<ApiResponse> {
|
|
|
|
|
request.status = "INVITED";
|
|
|
|
|
return Api.post(UserApi.inviteUserURL, request);
|
|
|
|
|
}
|
2020-01-03 08:49:47 +00:00
|
|
|
|
|
|
|
|
static logoutUser(): AxiosPromise<ApiResponse> {
|
|
|
|
|
const { baseUrl } = getAppsmithConfigs();
|
|
|
|
|
return Api.post(UserApi.logoutURL, undefined, undefined, {
|
|
|
|
|
baseURL: baseUrl,
|
|
|
|
|
withCredentials: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserApi;
|