84 lines
2.5 KiB
JavaScript
84 lines
2.5 KiB
JavaScript
import { post } from "./baseApi";
|
|
|
|
/**
|
|
* Function wrapping POST request for user registration
|
|
* @param {string} email - email of user to register
|
|
* @param {string} password1 - password of user to register
|
|
* @param {string} password2 - server side password confirmation
|
|
*/
|
|
export function registerUser(email, password1, password2) {
|
|
return post("/rest-auth/registration/", {
|
|
email,
|
|
password1,
|
|
password2
|
|
}).then(resp => Promise.resolve(resp));
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for email validation
|
|
* @param {string} emailKey - key for email validation
|
|
*/
|
|
export function verifyEmail(emailKey) {
|
|
return post("/rest-auth/registration/verify-email/", {
|
|
key: emailKey
|
|
}).then(resp => Promise.resolve(resp));
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for user login
|
|
* @param {string} email - email of user to login
|
|
* @param {string} password - password of user to login
|
|
*/
|
|
export function loginUser(email, password) {
|
|
return post("/rest-auth/login/", { email, password }).then(resp =>
|
|
Promise.resolve(resp)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for user logout
|
|
*/
|
|
export function logoutUser() {
|
|
return post("/rest-auth/logout/").then(resp => Promise.resolve(resp));
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for change password
|
|
* @param {string} new_password1 - user new password
|
|
* @param {string} new_password2 - user new password confirmation
|
|
* @param {string} old_password - old password of user
|
|
*/
|
|
export function changePassword(new_password1, new_password2, old_password) {
|
|
return post("/rest-auth/password/change/", {
|
|
new_password1,
|
|
new_password2,
|
|
old_password
|
|
}).then(resp => Promise.resolve(resp));
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for a forget password email call
|
|
* @param {string} email - email of user for password reset
|
|
*/
|
|
export function forgotPassword(email) {
|
|
return post("/rest-auth/password/reset/", { email }).then(resp =>
|
|
Promise.resolve(resp)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Function wrapping POST request for resetting a user's password
|
|
* @param {string} uid - uid supplied by forgot password email
|
|
* @param {string} token - token supplied by forgot password email
|
|
* @param {string} new_password1 - user new password
|
|
* @param {string} new_password2 - user new password confirmation
|
|
*/
|
|
export function resetPassword(uid, token, new_password1, new_password2) {
|
|
return post("/rest-auth/password/reset/confirm/", {
|
|
uid,
|
|
token,
|
|
new_password1,
|
|
new_password2
|
|
}).then(resp => Promise.resolve(resp));
|
|
}
|