当前位置: 首页>>代码示例>>PHP>>正文


PHP UserFactory::getInstance方法代码示例

本文整理汇总了PHP中UserFactory::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP UserFactory::getInstance方法的具体用法?PHP UserFactory::getInstance怎么用?PHP UserFactory::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserFactory的用法示例。


在下文中一共展示了UserFactory::getInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: invoke

 public function invoke()
 {
     $return = "";
     if (!isset($_GET['method'])) {
         $return = '{ "error": "No se envió un método" }';
     } else {
         switch ($_GET['method']) {
             case 'register':
                 $_SESSION["user"] = UserFactory::getInstance()->register($_GET['email'], $_GET['password'], 3);
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "Ya existe un usuario registrado con ese email" }';
                 }
                 break;
             case 'create':
                 $name = $_GET['name'];
                 $email = $_GET['email'];
                 $type = $_GET['type'];
                 $password = $_GET['password'];
                 $user = UserFactory::getInstance()->create($email, $name, $password, $type);
                 if (isset($user) && $user) {
                     $return = '{ "status": "ok", "message": "Se creó el usuario" }';
                 } else {
                     $return = '{ "logged": false, "error": "Ya existe un usuario registrado con ese email" }';
                 }
                 break;
             case 'login':
                 $_SESSION["user"] = UserFactory::getInstance()->login($_GET['email'], $_GET['password']);
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "Error de email / password" }';
                 }
                 break;
             case 'users':
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $uq = $_SESSION["user"]->getUserQueries();
                     $rows = $uq->getUserList();
                     $result = $uq->fetch_all($rows);
                     /*$result = array();
                       while ($row = $rows->fetch_assoc()) {
                           array_push($result, $row);
                       }
                       $rows->free();*/
                     //$result = $rows->fetch_all(MYSQLI_ASSOC);
                     $return = json_encode($result);
                     //$rows->free();
                 } else {
                     $return = '{ "logged": false, "error": "Error obteniendo los usuarios" }';
                 }
                 break;
             case 'user':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $rows = $_SESSION["user"]->getUserQueries()->getUserById($_GET["id"]);
                     /*$result = array();
                       while ($row = $rows->fetch_assoc()) {
                           array_push($result, $row);
                       }
                       $rows->free();
                       $return = json_encode($result);*/
                     $result = $rows->fetch_object(MYSQLI_ASSOC);
                     $return = json_encode($result);
                     $rows->free();
                 } else {
                     $return = '{ "logged": false, "error": "Error obteniendo el usuario" }';
                 }
                 break;
             case 'update':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $email = $_GET["email"];
                     $id = $_GET["id"];
                     $name = $_GET["name"];
                     $password = $_GET["password"];
                     $active = $_GET["active"];
                     $type = $_GET["type"];
                     $rows = $_SESSION["user"]->getUserQueries()->updateUser($email, $id, $name, $password, $active, $type);
                     $return = json_encode($rows);
                 } else {
                     $return = '{ "logged": false, "error": "Error actualizando el usuario" }';
                 }
                 break;
             case 'toggle':
                 if (isset($_SESSION["user"]) && $_SESSION["user"] && isset($_GET["id"])) {
                     $id = $_GET["id"];
                     $active = $_GET["active"];
                     $rows = $_SESSION["user"]->getUserQueries()->toggleUser($id, $active);
                     $return = json_encode($rows);
                 } else {
                     $return = '{ "logged": false, "error": "Error actualizando el usuario" }';
                 }
                 break;
             case 'check':
                 if (isset($_SESSION["user"]) && $_SESSION["user"]) {
                     $return = json_encode($_SESSION["user"]->getUserData());
                 } else {
                     $return = '{ "logged": false, "error": "No se ha iniciado sesión" }';
                 }
                 break;
             case 'logout':
//.........这里部分代码省略.........
开发者ID:CookieQuartet,项目名称:eventosmdp,代码行数:101,代码来源:UserController.php

示例2: session_start

<?php

include_once 'User.php';
include_once 'userAdmin/UserAdmin.php';
include_once 'userGeneral/UserGeneral.php';
include_once 'userPublisher/UserPublisher.php';
include_once 'userType/UserTypeEnum.php';
include_once 'UserFactory.php';
session_start();
include_once './UserController.php';
if (!isset($_SESSION["userFactory"])) {
    $_SESSION["userFactory"] = UserFactory::getInstance();
}
$controller = new UserController($_SESSION["userFactory"]);
$controller->invoke();
开发者ID:CookieQuartet,项目名称:eventosmdp,代码行数:15,代码来源:UserAPI.php

示例3: getUserByID

        return self::$instance;
    }
    // End Singleton Methods
    public function getUserByID($id)
    {
        $db = DB::getInstance();
        $result = $db->query("SELECT ID, Name, Email, Access FROM User WHERE ID = ?", array($id));
        if (empty($result) || count($result) != 1) {
            return FALSE;
        }
        // Idiot Check - We should only have 1 user for that ID
        $user = new User();
        $result = $result[0];
        foreach ($result as $key => $value) {
            $user->{$key} = $value;
        }
        return $user;
    }
}
Config::$dbuser = 'db';
Config::$dbpass = 'db';
Config::$dbhost = 'localhost';
Config::$dbname = 'test';
// now pretend this is in a controller
$userfactory = UserFactory::getInstance();
$user = $userfactory->getUserByID(1);
if ($user->isAdmin()) {
    echo "Woot! you're an admin!";
} else {
    echo "You're a pleb";
}
开发者ID:hemantshekhawat,项目名称:Snippets,代码行数:31,代码来源:basicmvc.php


注:本文中的UserFactory::getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。