Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profilePic func #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/Components/Forms/SignUp/SignUpForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const SignUpForm = () => {

function handleChangeImage(event){
if(event.target.files[0]){
setImage(event.target.files[0].name)
setImage(event.target.files[0])
}
}

Expand All @@ -63,7 +63,7 @@ const SignUpForm = () => {
</div>
<div className={styles.formRight}>
<div className={styles.imageArea}>
{image ? (<React.Fragment>Uploaded: <div>{image}</div></React.Fragment>) : "Drag or click to upload a profile image"}
{image ? (<React.Fragment>Uploaded: <div>{image.name}</div></React.Fragment>) : "Drag or click to upload a profile image"}
<input type="file" className={styles.inputImage} name="image" accept="image/png, image/jpeg" onChange={(e)=>handleChangeImage(e)} />
</div>

Expand Down
256 changes: 245 additions & 11 deletions src/utilities/Auth.Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,33 @@ export const AuthProvider = ({children}) => {
})
}

const signup = (username,email,password,mobile) => {
const reqObj = {
username,
email,
password,
mobile
}
const signup = (username,email,password,mobile,image) => {
var reqObj = new FormData()
reqObj.append('username',username)
reqObj.append('email',email)
reqObj.append('password',password)
reqObj.append('mobile',mobile)
reqObj.append('profilePic',image)

let axiosConfig = {
headers: {
'Content-Type': 'application/json'
'Content-Type': 'multipart/form-data'
}
};

//https://rivi-test-backend.herokuapp.com/api/v1/user/signup
axios.post('https://rivi-test-backend.herokuapp.com/api/v1/user/signup', reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
alert(res.data.message)
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
alert(res.data.message)
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
Expand All @@ -114,6 +120,224 @@ export const AuthProvider = ({children}) => {

}

const verifyEmail = (email)=>{
const reqObj = {
email
}
axios.post('https://rivi-test-backend.herokuapp.com/api/v1/user/verify/email', reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const verify = (token)=>{
axios.post(`https://rivi-test-backend.herokuapp.com/api/v1/user/verify/${token}`, reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const resetEmail = (email, host)=>{
const reqObj = {
email,
host
}
axios.post(`https://rivi-test-backend.herokuapp.com/api/v1/user/reset/email`, reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const updatePassword = (token,password1,password2)=>{
const reqObj = {
password1,
password2
}
axios.put(`https://rivi-test-backend.herokuapp.com/api/v1/user/reset/${token}`, reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const getProfile = (token)=>{
axios.get(`https://rivi-test-backend.herokuapp.com/api/v1/user/profile?token=${token}`, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const getUserProfile = (token,id)=>{
axios.get(`https://rivi-test-backend.herokuapp.com/api/v1/user/profile/${id}?token=${token}`, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const updateProfile = (token,user)=>{
const reqObj = user
axios.put(`https://rivi-test-backend.herokuapp.com/api/v1/user/profile?token=${token}`,reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const getChats = (token)=>{
axios.get(`https://rivi-test-backend.herokuapp.com/api/v1/user/chats?token=${token}`, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const getChatById = (token,id)=>{
axios.get(`https://rivi-test-backend.herokuapp.com/api/v1/user/chats/${id}?token=${token}`, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const report = (token,by,to,title,description)=>{
const reqObj = {
by,
to,
title,
description,
}
axios.post(`https://rivi-test-backend.herokuapp.com/api/v1/user/report?token=${token}`,reqObj, axiosConfig)
.then((res) => {
if(res.data.success === false){
riviToasteer({
type:"danger",
message:res.data.message,
})
}else{
riviToasteer({
type:"success",
message:res.data.message,
})
}
})
.catch((err) => {
console.log("AXIOS ERROR: ", err);
})
}

const logout = () => {
clearTimeout(loginTimeout)
localStorage.clear();
Expand Down Expand Up @@ -167,7 +391,17 @@ export const AuthProvider = ({children}) => {
setLoading,
login,
signup,
logout
logout,
verifyEmail,
verify,
resetEmail,
updatePassword,
getProfile,
getUserProfile,
updateProfile,
getChats,
getChatById,
report
}

return (
Expand Down