/** * Can user like entity? * @param User $User * @return bool */ public function canUserLikeOrDislike(User $User) { $userId = $User->getId(); $whoLiked = $this->getLikedUsersIds(); $whoDisliked = $this->getDislikedUsersIds(); return !array_key_exists($userId, $whoLiked) && !array_key_exists($userId, $whoDisliked); }
/** * @param User $User */ public function setOwner(User $User) { if (!$User->getId()) { throw new LogicException("Can not set owner without id"); } $this->set(self::FIELD_USER_OWNER, $User); }
/** * @param string $email * @param string $name * @param string $password * @return User * @throws Exception */ public function registerUser($email, $name, $password) { if ($this->getIdByName($name)) { throw new Exception("User with name {$name} already exists"); } $User = new User([User::FIELD_EMAIL => $email, User::FIELD_NAME => $name, User::FIELD_PASSWORD => password_hash($password, PASSWORD_DEFAULT)]); $User->save(); $this->saveNameIdIndex($name, $User->getId()); return $User; }
public function testParseEntity() { $testEntity = $this->getMockBuilder('Entity\\EntityManager')->disableOriginalConstructor()->setMethods(null)->getMock(); $user = new User(); $user->setCreatedAt('1111'); $user->setUserName('Roma'); // $testEntity = new EntityManager(); $this->assertInstanceOf('User\\User', $user); $parsedEntity = $testEntity->entityParse($user); $this->assertCount(2, $parsedEntity); $this->assertArraySubset(['entity' => 'User', 'properties' => ['id' => null, 'userName' => 'Roma', 'createdAt' => '1111', 'updatedAt' => null, 'deletedAt' => null]], $parsedEntity); }
/** * @method POST * @api register */ public function register() { $result = parent::register(); $userID = $result->body['userID']; $db = DB::instance(); $db->insert('adr_users', array('userID' => $userID, 'user_points' => 1000)); return $result; }
public static function getSettings($name = null) { if (User::$settings == null) { $settings = file_get_contents('../core/Modules/Social/settings/settings.json'); User::$settings = json_decode($settings, true); } $settings = User::$settings; return $name == null ? $settings : $settings[$name]['value']; }
public function getTableFields() { $fields = parent::getTableFields(); // create Groups field $fields['groups'] = $groups = new \Meta\Field\CheckboxMulti(array('name' => 'groups', 'label' => t('Groups'), 'options' => \User\User::listAllGroups())); if (isset($_GET['id'])) { $user = new \User\User($_GET['id']); $groups->setValue(array_keys($user->groups)); } return $fields; }
public function onBeforeRender() { $user = \User\User::logged(); $queryItems = new \Meta\Query(array('from' => 'items')); $queryReserves = new \Meta\Query(array('from' => 'reserves')); $queryUsers = new \Meta\Query(array('from' => 'users')); $query = new \Meta\Query(array('select' => 'r.id, r.dt_request, r.dt_begin, r.dt_end, r.status, i.name AS item', 'from' => 'reserves r INNER JOIN items i ON i.id = r.item_id', 'order' => 'dt_request DESC', 'limit' => 5)); $myReservesQuery = clone $query; $myReservesQuery->whereAnd('r.requester_id = ' . \User\User::logged()->id); $pendingQuery = clone $query; $pendingQuery->whereAnd("r.status = 'W'"); $this->add(render('dashboard.php', array('myReserves' => $myReservesQuery->executeQuery()->fetchAll(\PDO::FETCH_ASSOC), 'isReservesManager' => $user->allowedToPage('res-reserves') || $user->isAdmin, 'pendingReserves' => $pendingQuery->executeQuery()->fetchAll(\PDO::FETCH_ASSOC), 'countItems' => $queryItems->countRows(), 'countReserves' => $queryReserves->countRows(), 'countUsers' => $queryUsers->countRows()))); }
public function doLogin() { $email = Input::get('email'); $password = Input::get('password'); $user = UserModel::whereRaw('email = ? and secure_key = md5(concat(salt, ?))', array($email, $password))->get(); if (count($user) != 0) { Session::set('user_id', $user[0]->id); return Redirect::route('user.home'); } else { $alert['msg'] = 'Email & Password is incorrect'; $alert['type'] = 'danger'; return Redirect::route('user.auth.login')->with('alert', $alert); } }
public function onValidated() { $uid = \User\User::logged()->id; $data = $this->getData(); Db::saveSafe('users', $data); Flash::success(t('Profile saved')); // change password $pass = $data['password_new']; if (strlen($pass) > 0) { Db::update('users', array('password' => md5($pass)), array('id' => $uid)); Flash::success(t('Password changed')); } redirect(url(current_path())); }
public function onBeforeRender() { // logout actin if (is_action('logout')) { User::logout(); redirect(page_home()); } // login form if (is_post()) { $username = filter_input(INPUT_POST, 'username'); $password = filter_input(INPUT_POST, 'password'); $backTo = filter_input(INPUT_GET, 'back_to'); if (User::authenticate($username, $password)) { $url = strlen($backTo) > 0 ? urldecode($backTo) : page_home(); redirect($url); } else { Flash::error(t('Invalid username or password!')); } } $this->add(render('user-login.php')); }
<!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"> </script> </head> <body class="add-user"> <div class="container"> <?php $entity = new EntityManager(); $entity->db_init(); if (isset($_POST['name'])) { $user_login = new User(); $user_login->setUserName($_POST['name']); $id = $entity->insert($user_login); $_SESSION['user'] = $id; header("Location: /user/index.php"); exit; } ?> <form method="post"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" placeholder="Name" name="name"> </div> <button type="submit" class="btn btn-default">Sign in</button>
public function execute() { return !User::loginExists($this->value); }
<body class="add-user"> <div class="container"> <div id="header"> <a href="/../shop/" class="btn btn-default">Shop</a> <a href="/../user/" class="btn btn-default">Users</a> <a href="/../user/AddUser.php" class="btn btn-default">Add User</a> <a href="/../products/index.php" class="btn btn-default">Products</a> <a href="/../products/AddProduct.php" class="btn btn-default">Add Product</a> <a href="/../orders/index.php" class="btn btn-default">Orders</a> </div> <?php if (isset($_POST['name'])) { $user = new User(); $user->setUserName($_POST['name']); // $date = new DateTime('now'); $user->setCreatedAt(1111111111); // $user = array( // 'entity' => 'users', // 'user_name' => $_POST['name'] // ); $user_insert = new EntityManager(); $user_insert->insert($user); header("Location: index.php"); exit; } ?> <form method="post">
/** * Validate a user object. * * Invokes User::validate(), and additionally tests that the User's email address isn't associated with another User. * * @param User $user * @return array An array of error messages, or an empty array if the User is valid. */ public function validate(User $user) { $errors = $user->validate(); $duplicates = $this->findBy(array('email' => $user->getEmail())); if (!empty($duplicates)) { foreach ($duplicates as $dup) { if ($user->getId() && $dup->getId() == $user->getId()) { continue; } $errors['email'] = 'An account with that email address already exists.'; } } return $errors; }
public function register() { if (!$this->path) { throw new \Exception(t('Page path not defined')); } // add menu item if ($this->menu && $this->isUserAllowed()) { $this->menu->path = $this->path; // set menu label same as page title if (!$this->menu->label) { $this->menu->label = $this->title; } Menu::get()->add($this->menu); } // add route callback $obj = $this; Route::get()->add($this->path, function () use($obj) { if (!$obj->isUserAllowed()) { if (!User::hasLoggedUser()) { redirect(page_login()); } echo new Page\AccessDenied(); } echo $obj->render(); }); }
/** * @method GET * @api name */ public function name() { // if not logged in, getID is 0 (anonymous) Analytics::track('saidhello', 'HelloWorld', User::getID()); return $this->response(array('status' => 1, 'message' => "Hello " . $_GET['myName'] . "!")); }