{"size": 1916, "ext": "js", "max_stars_repo_path": "client/src/Components/authsystem/UserFunctions.js", "max_stars_repo_name": "IsaacDarko/turing-project-live", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/Components/authsystem/UserFunctions.js", "max_issues_repo_name": "IsaacDarko/turing-project-live", "max_issues_repo_issues_event_min_datetime": "2021-05-10T16:45:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T19:05:40.000Z", "max_forks_repo_path": "client/src/Components/authsystem/UserFunctions.js", "max_forks_repo_name": "IsaacDarko/turing-project-live", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.5466666667, "max_line_length": 63, "alphanum_fraction": 0.5339248434}
import axios from 'axios';

export const adminRegister = newUser => {
    return axios
    .post('user/register', {
        fname : newUser.fname,
        lname : newUser.lname,
        email : newUser.email,
        password : newUser.password,
    })
    .then(response =>{
        console.log('New Admin has been added successfully')
    })
} 

export const login = (user) => {
    return axios
    .post('/customers/login', {
        email: user.email,
        password: user.password
    })
    .then(res => {
        const user = res.data.user;
        localStorage.setItem('xauthtoken', res.data.token);
        localStorage.setItem('customer', JSON.stringify(user));
        console.log(res);
        if (res.status === 200){
            this.props.history.push('/');
        }else{
            const error = new Error(res.error);
            throw error;
        }
    })
    .catch(err => {
        console.log(err)
    })
}

export const register = (user) => {
    return axios
    .post('/customers/', {
        name: user.name,
        email: user.email,
        password: user.password,

        credit_card: {
            cc_name: user.cc_name,
            cc_number: user.cc_number,
            cc_cvv: user.cc_cvv,
            cc_exp: user.cc_exp
        },

        address_1: user.address_1,
        address_2: user.address_2,
        city: user.city,
        postal_code: user.postal_code,
        country: user.country,
        mob_phone: user.phone
    })
    .then(res => {
        const user = res.data.user;
        localStorage.setItem('xauthtoken', res.data.token);
        localStorage.setItem('customer', JSON.stringify(user));
        console.log(res);
        if (res.status === 200){
            this.props.history.push('/');
        }else{
            const error = new Error(res.error);
            throw error;
        }
    })
    .catch(err => {
        console.log(err)
    })
}