本文整理汇总了PHP中user::create方法的典型用法代码示例。如果您正苦于以下问题:PHP user::create方法的具体用法?PHP user::create怎么用?PHP user::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user
的用法示例。
在下文中一共展示了user::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create
public function action_create()
{
try {
user::create($_POST);
ajax::success(__('User created'), array('redirect' => 'users'));
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
$errstr = array('<ul>');
if ((bool) count($errors)) {
foreach ($errors as $error) {
if (is_array($error)) {
foreach ($error as $err) {
$errstr[] = '<li>' . $err . '</li>';
}
} else {
$errstr[] = '<li>' . $error . '</li>';
}
}
}
$errstr[] = '</li>';
ajax::error(implode('', $errstr));
} catch (exception $e) {
ajax::error(__('An uncaught error occurred: :error', array(':error' => $e->getMessage())));
}
}
示例2: add_user
public function add_user()
{
access::verify_csrf();
$form = $this->_get_user_add_form_admin();
$valid = $form->validate();
$name = $form->add_user->inputs["name"]->value;
if ($user = user::lookup_by_name($name)) {
$form->add_user->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
if ($valid) {
$user = user::create($name, $form->add_user->full_name->value, $form->add_user->password->value);
$user->email = $form->add_user->email->value;
$user->admin = $form->add_user->admin->checked;
if ($form->add_user->locale) {
$desired_locale = $form->add_user->locale->value;
$user->locale = $desired_locale == "none" ? null : $desired_locale;
}
$user->save();
module::event("user_add_form_admin_completed", $user, $form);
message::success(t("Created user %user_name", array("user_name" => $user->name)));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error", "form" => $form->__toString()));
}
}
示例3: install
static function install()
{
$db = Database::instance();
$version = module::get_version("user");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {users} (\n `id` int(9) NOT NULL auto_increment,\n `name` varchar(32) NOT NULL,\n `full_name` varchar(255) NOT NULL,\n `password` varchar(64) NOT NULL,\n `login_count` int(10) unsigned NOT NULL DEFAULT 0,\n `last_login` int(10) unsigned NOT NULL DEFAULT 0,\n `email` varchar(64) default NULL,\n `admin` BOOLEAN default 0,\n `guest` BOOLEAN default 0,\n `hash` char(32) default NULL,\n `url` varchar(255) default NULL,\n `locale` char(10) default NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY(`hash`),\n UNIQUE KEY(`name`))\n ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups} (\n `id` int(9) NOT NULL auto_increment,\n `name` char(64) default NULL,\n `special` BOOLEAN default 0,\n PRIMARY KEY (`id`),\n UNIQUE KEY(`name`))\n ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups_users} (\n `group_id` int(9) NOT NULL,\n `user_id` int(9) NOT NULL,\n PRIMARY KEY (`group_id`, `user_id`),\n UNIQUE KEY(`user_id`, `group_id`))\n ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$everybody = group::create("Everybody");
$everybody->special = true;
$everybody->save();
$registered = group::create("Registered Users");
$registered->special = true;
$registered->save();
$guest = user::create("guest", "Guest User", "");
$guest->guest = true;
$guest->remove($registered);
$guest->save();
$admin = user::create("admin", "Gallery Administrator", "admin");
$admin->admin = true;
$admin->save();
// Let the admin own everything
$db->update("items", array("owner_id" => $admin->id), array("owner_id" => "IS NULL"));
module::set_version("user", 1);
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
access::allow($everybody, "view_full", $root);
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
}
}
示例4: add_user
public function add_user()
{
access::verify_csrf();
$form = user::get_add_form_admin();
$valid = $form->validate();
$name = $form->add_user->inputs["name"]->value;
$user = ORM::factory("user")->where("name", $name)->find();
if ($user->loaded) {
$form->add_user->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
if ($valid) {
$user = user::create($name, $form->add_user->full_name->value, $form->add_user->password->value);
$user->email = $form->add_user->email->value;
$user->admin = $form->add_user->admin->checked;
if ($form->add_user->locale) {
$desired_locale = $form->add_user->locale->value;
$user->locale = $desired_locale == "none" ? null : $desired_locale;
}
$user->save();
message::success(t("Created user %user_name", array("user_name" => p::clean($user->name))));
print json_encode(array("result" => "success"));
} else {
print json_encode(array("result" => "error", "form" => $form->__toString()));
}
}
示例5: create
function create()
{
$user = new user();
$user->firstname = "Temp";
$user->lastname = "";
$user->mail = "";
$user->mail_password = "";
$user->mobile = "";
$user->comment = "";
$user->user_id = $user->create();
$user->id = $user->user_id;
$data['user'] = $user;
$this->view('users/edit_view.php', $data, 'main_template.php');
}
示例6: store_user
public function store_user()
{
$user = new user();
$data = Input::all();
$data['password'] = Hash::make($data['password']);
$uid = $user->create($data);
$priviledge = new Priviledge();
$priviledge->user_id = $uid->id;
$priviledge->name_show = '2';
$priviledge->user_authority = '2';
$priviledge->save();
//send mail on registration
Mail::send('authentications.mails.welcome', array('user_name' => Input::get('user_name')), function ($message) {
$message->to(Input::get('email'), Input::get('user_name'))->subject('Welcome to the Votting-System App!');
});
return Redirect::intended('login');
}
示例7: install
static function install()
{
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {users} (\n `id` int(9) NOT NULL auto_increment,\n `name` varchar(32) NOT NULL,\n `full_name` varchar(255) NOT NULL,\n `password` varchar(64) NOT NULL,\n `login_count` int(10) unsigned NOT NULL DEFAULT 0,\n `last_login` int(10) unsigned NOT NULL DEFAULT 0,\n `email` varchar(64) default NULL,\n `admin` BOOLEAN default 0,\n `guest` BOOLEAN default 0,\n `hash` char(32) default NULL,\n `url` varchar(255) default NULL,\n `locale` char(10) default NULL,\n PRIMARY KEY (`id`),\n UNIQUE KEY(`hash`),\n UNIQUE KEY(`name`))\n DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups} (\n `id` int(9) NOT NULL auto_increment,\n `name` char(64) default NULL,\n `special` BOOLEAN default 0,\n PRIMARY KEY (`id`),\n UNIQUE KEY(`name`))\n DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups_users} (\n `group_id` int(9) NOT NULL,\n `user_id` int(9) NOT NULL,\n PRIMARY KEY (`group_id`, `user_id`),\n UNIQUE KEY(`user_id`, `group_id`))\n DEFAULT CHARSET=utf8;");
$everybody = group::create("Everybody");
$everybody->special = true;
$everybody->save();
$registered = group::create("Registered Users");
$registered->special = true;
$registered->save();
$guest = user::create("guest", "Guest User", "");
$guest->guest = true;
$guest->remove($registered);
$guest->save();
$admin = user::create("admin", "Gallery Administrator", "admin");
$admin->admin = true;
$admin->save();
$current_provider = module::get_var("gallery", "identity_provider");
if (empty($current_provider)) {
// If there is no provider defined then we are doing an initial install
// so we need to set the provider and make the administrator own everything
// If the installer is called and there is an identity provider, then we
// are switching identity providers and and the event handlers will do the
// right things
module::set_var("gallery", "identity_provider", "user");
// Let the admin own everything
$db->query("update {items} set owner_id = {$admin->id}");
}
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
access::allow($everybody, "view_full", $root);
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
module::set_var("user", "mininum_password_length", 5);
module::set_version("user", 2);
}
示例8: action_signup
public function action_signup()
{
$errors = false;
$password = false;
if ($_POST) {
$user = ORM::factory('User');
try {
user::create($_POST);
notes::add('success', 'You are now signed up. Welcome!');
if (user::logged()) {
site::redirect('write');
} else {
// should log this error (user wasnt logged in with user::create())
user::redirect('login');
}
} catch (ORM_Validation_Exception $e) {
$errors = $e->errors('models');
}
}
$this->bind('errors', $errors);
}
示例9: __construct
/**
* @brief Constructor for Password Authentication
*
* @param string $username The username for which to validate the token
* @param string $password The user's password.
*/
public function __construct()
{
$token = request::get('token')->toString();
$apikey = config::get('lepton.user.engage.apikey');
$ret = new HttpRequest('https://rpxnow.com/api/v2/auth_info', array('method' => 'post', 'parameters' => array('apiKey' => $apikey, 'token' => $token, 'format' => 'xml')));
$dom = DOMDocument::loadXml($ret->responseText());
$domx = new DOMXPath($dom);
// Get the status
$status = $domx->query('/rsp')->item(0)->getAttribute('stat');
if ($status == 'ok') {
// Call on the successful callback method
event::invoke(EngageEvents::EVENT_SUCCESSFUL_CALLBACK, array('profile' => $dom, 'profiletext' => $ret->responseText()));
// Extract the values
$identifier = $domx->query('/rsp/profile/identifier')->item(0)->nodeValue;
$displayname = $domx->query('/rsp/profile/displayName')->item(0)->nodeValue;
$provider = $domx->query('/rsp/profile/providerName')->item(0)->nodeValue;
$firstname = $domx->query('/rsp/profile/name/givenName')->item(0)->nodeValue;
$lastname = $domx->query('/rsp/profile/name/familyName')->item(0)->nodeValue;
$preferredusername = $domx->query('/rsp/profile/preferredUsername')->item(0)->nodeValue;
$email = $domx->query('/rsp/profile/email')->item(0)->nodeValue;
// Sign in
$db = new DatabaseConnection();
$idrs = $db->getSingleRow("SELECT * FROM userengage WHERE identifier=%s", $identifier);
if ($idrs) {
$cu = $idrs['userid'];
$db->updateRow("UPDATE userengage SET lastseen=NOW(), lastip=%s WHERE id=%d", request::getRemoteIp(), $idrs['id']);
} else {
if (!user::isAuthenticated()) {
if (!config::get(EngageAuthentication::KEY_ALLOW_CREATION, false)) {
throw new SecurityException("User creation is disabled for EngageAuthentication");
}
// Check username, add random numbers if not available
$username = $preferredusername;
$retrycount = 0;
while (!user::checkUsername($username)) {
$username = substr($preferredusername, 0, 6) . rand(1000, 9999);
$retrycount = $retrycount + 1;
if ($retrycount > 10) {
throw new UserException("Bad username");
}
}
// Generate a new password
$password = substr(md5(uniqid()), 0, 6);
// And create the userrecord
$u = new UserRecord();
$u->username = $username;
$u->password = $password;
$u->flags = config::get(EngageAuthentication::KEY_DEFAULT_FLAGS, EngageAuthentication::DEFAULT_FLAGS);
$u->displayname = $displayname;
$u->firstname = $firstname;
$u->lastname = $lastname;
$u->email = $email;
$cu = user::create($u);
session::set(self::SESSIONKEY_USER_CREATED, true);
} else {
$cu = user::getActiveUser();
}
// Add identifier to user
$db->updateRow("INSERT INTO userengage (userid,identifier,provider,lastseen,lastip) VALUES (%d,%s,%s,NOW(),%s)", $cu, $identifier, $provider, request::getRemoteIp());
}
$this->userid = $cu;
} else {
$this->userid = null;
}
}
示例10: user
<?php
require_once "user_class.php";
$login = $_POST['input_login'];
$password = $_POST['input_pass'];
$mail = $_POST['input_mail'];
if (isset($login) && isset($password) && isset($mail) && !empty($login) && !empty($password) && !empty($mail)) {
$newuser = new user($login, $password, $mail);
$newuser->create($login, $password, $mail);
} else {
echo "Error";
}
示例11: array
if (input::get('type')) {
$user_t = input::get('type');
$users_id = DB::getInstance()->get('user_type', array('name', '=', $user_t));
if ($users_id->count()) {
foreach ($users_id->results() as $ids) {
$user_t_id = $ids->id;
}
}
}
$Validate = new validate();
$validation = $Validate->check($_POST, array('username' => array('required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users'), 'password' => array('required' => true, 'min' => 6), 'password_again' => array('required' => true, 'matches' => 'password'), 'Address' => array('required' => true, 'min' => 5, 'max' => 50)));
if ($validation->passed()) {
$user = new user();
$salt = Hash::salt(32);
try {
$user->create(array('username' => input::get('username'), 'password' => Hash::make(input::get('password'), $salt), 'name' => input::get('name'), 'salt' => $salt, 'email' => input::get('email'), 'Address' => input::get('Address'), 'Mobile' => input::get('Mobile'), 'joined' => date('Y-m-d H:i:s'), 'user_type_id' => $user_t_id));
Redirect::to('admin.php');
} catch (Exception $e) {
die($e->getMessage());
}
} else {
$i = 0;
foreach ($validation->errors() as $error) {
$rs[$i] = $error;
$i++;
}
}
}
}
} else {
Redirect::to('includes/errors/404.php');
示例12: user
require_once '../Core/init.php';
$user = new user(null, $_log);
if (!$user->isLoggedIn() || !$user->hasPermission('Admin')) {
redirect::to('../index.php');
}
if (input::exists()) {
if (token::check(input::get('token'))) {
$validate = new validate();
$validation = $validate->check($_POST, array('Username' => array('required' => true, 'min' => 2, 'max' => 20, 'unique' => 'Users'), 'Password' => array('required' => true, 'min' => 6), 'password_again' => array('required' => true, 'matches' => 'Password'), 'Name' => array('required' => true, 'min' => 2, 'max' => 50)));
if ($validation->passed()) {
//session::flash('success','You registered successfully!');
//header('Location: index.php');
$user = new user(null, $_log);
$salt = hash::salt(32);
try {
$user->create(array('Username' => input::get('Username'), 'User_Group' => 3, 'Password' => hash::make(input::get('Password'), $salt), 'Salt' => $salt));
session::flash('home', 'You have been registered');
redirect::to('index.php');
} catch (Exception $e) {
//echo $e->getMessage(), '<br>';
die($e->getMessage());
}
} else {
foreach ($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
示例13: test
/**
* test
*
* tests almost all functions in the class
*
* @return boolean
*/
public function test()
{
$pass = true;
$user1 = new user();
$user1->create('testuser4', 'Passw0rd', 'test@email4.com', 'TEST');
$user2 = new user();
$user2->create('testuser5', 'Passw0rd', 'test@email5.com', 'TEST');
//create
$pass = $this->testRun($this->create($user2->id, $user1->id, "this is a test message." . time()));
echo "|create\n";
//getOutgoing
$outmess = $this->getOutgoing($user1->id);
$pass = $this->testRun($outmess);
echo "|getOutgoing\n";
//getIncoming
$this->create($user1->id, $user2->id, "this is a second test message." . time());
$inmess = $this->getIncoming($user1->id);
$pass = $this->testRun($inmess);
echo "|getIncomming\n";
//delete
$delpass = true;
foreach ($inmess as $mess) {
if (!$this->delete($mess['id'])) {
$delpass = false;
}
}
foreach ($outmess as $mess) {
if (!$this->delete($mess['id'])) {
$delpass = false;
}
}
$pass = $this->testRun($delpass);
echo "|delete\n";
$user1->delete();
$user2->delete();
return $pass;
}
示例14: import_user
/**
* Import a single user.
*/
static function import_user(&$queue)
{
$g2_user_id = array_shift($queue);
if (self::map($g2_user_id)) {
return;
}
if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) {
self::set_map($g2_user_id, user::guest()->id);
return;
}
$g2_admin_group_id = g2(GalleryCoreApi::getPluginParameter("module", "core", "id.adminGroup"));
try {
$g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id));
} catch (Exception $e) {
g2_import::log(t("Failed to import Gallery 2 user with id: %id", array("id" => $g2_user_id)));
return;
}
$g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId()));
try {
$user = user::create($g2_user->getUsername(), $g2_user->getfullname(), "");
} catch (Exception $e) {
// @todo For now we assume this is a "duplicate user" exception
$user = user::lookup_by_name($g2_user->getUsername());
}
$user->hashed_password = $g2_user->getHashedPassword();
$user->email = $g2_user->getEmail();
$user->locale = $g2_user->getLanguage();
foreach ($g2_groups as $g2_group_id => $g2_group_name) {
if ($g2_group_id == $g2_admin_group_id) {
$user->admin = true;
} else {
$user->add(ORM::factory("group", self::map($g2_group_id)));
}
}
$user->save();
self::set_map($g2_user->getId(), $user->id);
}
示例15: session_start
<?php
require_once "../config/database.php";
require "../model/user_model.php";
session_start();
$request = $_POST["request"];
$user = $_POST["user"];
switch ($request) {
case 'create':
user::create($user);
echo "<script>location.href = '/view/'; </script>";
break;
case 'login':
$login = user::login($user);
if ($login == 0) {
echo "ユーザ名かパスワードが正しくわありません";
} else {
$_SESSION["user_id"] = $login;
//var_dump($_SESSION);
header("location: http://192.168.33.10/view/");
//echo "<script>location.href = '/view/'; </script>";
}
break;
case null:
$_SESSION["user_id"] = null;
echo "<script>location.href = '/view/'; </script>";
break;
}