Example #1
0
function _init()
{
    session_start();
    include_once 'classes/xsUTL.php';
    require_once "Hybrid/Auth.php";
    //
    if (isset($_GET['_login'])) {
        switch ($_GET['_login']) {
            case 'tw':
                $src = 'Twitter';
                break;
            case 'fb':
                $src = 'Facebook';
                break;
            case 'gp':
                $src = "Google";
                break;
        }
    }
    $config = dirname(__FILE__) . '/config.php';
    try {
        $hybridauth = new Hybrid_Auth($config);
        $social_login = $hybridauth->authenticate($src);
        $user_profile = $social_login->getUserProfile();
        $id = $user_profile->identifier;
        $name = $user_profile->displayName;
        $fname = $user_profile->firstName;
        $lname = $user_profile->lastName;
        $email = $user_profile->email;
        //creates the user
        if (!is_email($email)) {
            $_SESSION['role'] = $_SESSION['xs_user_type'];
            $_SESSION['src'] = $_GET['hauth.done'];
            $_SESSION['fname'] = $fname;
            $_SESSION['lname'] = $lname;
            $_SESSION['id'] = $id;
            // redirect to enter email
            wp_redirect(SURL . '/email-needed/');
            die;
        }
        if (email_exists($email)) {
            //logs user
            $user = get_user_by('email', $email);
            $logged_in = xsUTL::log_user($user->ID);
            if ($logged_in) {
                wp_redirect(SURL . '/my-account/');
            }
            die('Error');
        }
        $_role = $_SESSION['xs_user_type'];
        $data = ['user_login' => $src . '_' . $id, 'user_email' => $email, 'first_name' => $fname, 'last_name' => $lname, 'user_pass' => substr(wp_hash(time() . rand(0, 100000)), 0, 8), 'role' => $_role];
        $user = wp_insert_user($data);
        if ($user > 0) {
            if (xsUTL::log_user($user)) {
                wp_redirect(SURL . '/my-account/');
            }
            die('Error');
        }
        xsUTL::addError('Sign Up failed');
    } catch (Exception $e) {
    }
    // Form Processsor
    if ($_POST['_act'] && !is_admin()) {
        $_form_processor = new xsFormProcess();
        die;
    }
}
 function email_needed()
 {
     global $f;
     $f = new xsValidateForm();
     $f->setRule('xs_email', 'Email Id', 'trim|required|valid_email|callback[fnValidateEmail]');
     if ($f->validate()) {
         // sign up and create acc 	print_r( $_SESSION );
         $data = ['user_login' => $_SESSION['src'] . '_' . $_SESSION['id'], 'user_email' => $_POST['xs_email'], 'first_name' => $_SESSION['fname'], 'last_name' => $_SESSION['lname'], 'user_pass' => substr(wp_hash(time() . rand(0, 100000)), 0, 8), 'role' => $_SESSION['role']];
         $user = wp_insert_user($data);
         if ($user > 0) {
             if (xsUTL::log_user($user)) {
                 $this->okMsg = "Registration Successful.Please wait...";
                 $this->redirect = SURL . '/my-account/';
             }
         }
         xsUTL::addError('Sign Up failed');
     } else {
         $this->error = $f->returnErrors();
     }
 }
Example #3
0
$uploader->newFileName = sanitize_file_name($uploader->getFileName()) . '_' . rand(0, 10) . '.' . $uploader->getExtension();
$result = $uploader->handleUpload($upload_dir);
//
switch ($_GET['uploadType']) {
    case 'cv':
        if (!$result) {
            exit(json_encode(array('success' => FALSE, 'msg' => $uploader->getErrorMsg())));
        } else {
            ///
            $cv_url = SURL . '/wp-content/' . explode('wp-content', $uploader->getSavedFile())[1];
            $attach_id = xsUTL::add_image($cv_url);
            if ($attach_id > 0) {
                echo json_encode(array('status' => TRUE, 'id' => $attach_id));
            } else {
                echo json_encode(array('status' => TRUE, 'msg' => 'File Upload Failed.Please try again'));
            }
        }
        die;
        break;
}
// Directory where we're storing uploaded images
// Remember to set correct permissions or it won't work
// Handle the upload
do_action('display_init');
$image_url = SURL . '/wp-content/' . explode('wp-content', $uploader->getSavedFile())[1];
$attach_id = xsUTL::add_image($image_url);
if ($attach_id > 0) {
    echo json_encode(array('success' => TRUE, 'id' => $attach_id, 'url' => explode('wp-content', $uploader->getSavedFile())[1]));
} else {
    exit(json_encode(array('success' => FALSE, 'msg' => 'Can\'t add image to library')));
}