Ejemplo n.º 1
0
 /**
  * create a new user the settings page via ajax call
  *
  * @return array   $ret       the JSON encoded response for the ajax call
  */
 public function create_user_js()
 {
     // make sure the user calling the action has permission to do so
     if (false === TempAdminUser_Utilities::check_user_perm()) {
         return;
     }
     // set up return array for ajax responses
     $ret = array();
     // die fast without a nonce
     if (empty($_POST['nonce'])) {
         $ret['success'] = false;
         $ret['errcode'] = 'NO_NONCE';
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('nonce');
         echo json_encode($ret);
         die;
     }
     // check to make sure we got an email
     if (empty($_POST['email'])) {
         $ret['success'] = false;
         $ret['errcode'] = 'NO_EMAIL';
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('noemail');
         echo json_encode($ret);
         die;
     }
     // check to make sure our email isn't already used
     if (!empty($_POST['email']) && email_exists($_POST['email'])) {
         $ret['success'] = false;
         $ret['errcode'] = 'USED_EMAIL';
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('usedemail');
         echo json_encode($ret);
         die;
     }
     // check to see if our nonce failed
     if (false === check_ajax_referer('tempadmin_make_js', 'nonce', false)) {
         $ret['success'] = false;
         $ret['errcode'] = 'NONCE_FAILED';
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('nonce');
         echo json_encode($ret);
         die;
     }
     // if our time isn't passed for some reason, make it one day
     $time = !empty($_POST['time']) ? $_POST['time'] : 'day';
     // create our user
     $user = self::create_new_user($_POST['email'], $time);
     // return error if no user was created
     if (empty($user)) {
         $ret['success'] = false;
         $ret['errcode'] = 'NO_USER';
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('nocreate');
         echo json_encode($ret);
         die;
     }
     // return success if user was created
     if (!empty($user)) {
         $ret['success'] = true;
         $ret['errcode'] = null;
         $ret['newrow'] = TempAdminUser_Layout::single_user_row($user);
         $ret['message'] = TempAdminUser_Utilities::get_admin_messages('created');
         echo json_encode($ret);
         die;
     }
     // unknown error
     $ret['success'] = false;
     $ret['errcode'] = 'UNKNOWN_ERROR';
     $ret['message'] = TempAdminUser_Utilities::get_admin_messages('default');
     echo json_encode($ret);
     die;
 }