本文整理汇总了PHP中UserService::createUser方法的典型用法代码示例。如果您正苦于以下问题:PHP UserService::createUser方法的具体用法?PHP UserService::createUser怎么用?PHP UserService::createUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserService
的用法示例。
在下文中一共展示了UserService::createUser方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: synchroniseUser
/**
* Create or update a user's account
*
* @param string $username
* @param array $entry
*/
private function synchroniseUser($entry)
{
$mapping = ifset($this->config, 'mapping', array());
$username = ifset($entry, $mapping['username'], false);
if (!$username) {
throw new Exception("No username mapping found.");
}
// Cast back from the array representation
$username = $username[0];
// get all the user's details and map the relevant attributes... which we'll skip!
$user = $this->userService->getUserByField('username', $username);
if ($user == null) {
$params = array();
$params['username'] = $username;
$params['password'] = md5(time() . rand(1, 10000));
// Fill in mapped params
$email = ifset($entry, $mapping['email'], null);
if ($email) {
$email = $email[0];
} else {
$email = $params['password'] . '@null.com';
}
$params['email'] = $email;
try {
$user = $this->userService->createUser($params, false);
} catch (Exception $e) {
$this->log->err("Failed creating user for {$username}: " . $e->getMessage() . ': ' . current_url() . "\r\n" . print_r($params, true));
return null;
}
}
za()->log(__CLASS__ . ':' . __LINE__ . " User is " . get_class($user));
return $user;
}
示例2: createUserForContact
/**
* Creates a user object for the given contact
*
* Default attempted username is firstname.surname
*
* Failing that, initial.surname
*/
public function createUserForContact(Contact $contact)
{
// try and find a user for the given username
$username = $contact->firstname . '.' . $contact->lastname;
$username = trim($username, '.');
$username = mb_strtolower(preg_replace('/[^a-zA-Z.+_-]/', '', $username));
if ($username == '.') {
throw new ExistingUserException("Contact must have a firstname and surname");
}
if ($this->userService->getByName($username)) {
// try a different username
$username = $username[0] . $contact->lastname;
$username = trim($username, '.');
$username = mb_strtolower(preg_replace('/[^a-zA-Z.+_-]/', '', $username));
if ($this->userService->getByName($username)) {
// crapp it
throw new Exception("All possible usernames taken");
}
}
try {
$this->dbService->beginTransaction();
$new_pass = substr(md5(uniqid(rand(), 1)), 3, 5);
$params = array('username' => $username, 'email' => $contact->email, 'firstname' => $contact->firstname, 'lastname' => $contact->lastname, 'contactid' => $contact->id, 'password' => $new_pass);
$user = $this->userService->createUser($params, false, User::ROLE_EXTERNAL);
$this->trackerService->track('create-contact-user', $contact->id);
$this->dbService->commit();
} catch (Exception $e) {
$this->log->debug($e->getMessage() . ": \r\n" . $e->getTraceAsString());
$this->dbService->rollback();
throw $e;
}
return $user;
}
示例3: processCreateUser
/**
* Process a form to create a user.
*
* @return mixed The response.
*/
public function processCreateUser()
{
$user = new User();
$user->username = Input::get('username');
$user->password = Input::get('password');
$user->password_confirmation = Input::get('password_confirmation');
$user->first_name = Input::get('first_name');
$user->last_name = Input::get('last_name');
$user->email = Input::get('email');
$user->status = Input::get('status');
$user->role = Input::get('role');
$user->locale_id = Input::get('locale_id');
try {
UserService::createUser($user);
$this->success(trans('messages.userCreated'));
return Redirect::route('users.list');
} catch (ValidationException $e) {
return Redirect::route('users.create')->withInput(Input::all())->withErrors($e->getValidator());
} catch (Exception $e) {
return $this->unexpected($e);
}
}
示例4: registerAction
/**
* Display the register form
*
*/
public function registerAction()
{
if ($this->_getParam('email')) {
// alright then, lets create the user
if ($this->_getParam('password') != $this->_getParam('confirm')) {
$this->view->addError('unmatched_password', 'Passwords do not match');
} else {
try {
$this->userService->createUser($this->_getAllParams());
$this->returnOrHome();
} catch (ExistingUserException $eu) {
$this->view->addError('create_user', "Email " . $this->_getParam('email') . ' already exists');
} catch (InvalidModelException $im) {
$this->view->addErrors($im->getMessages());
} catch (Exception $e) {
$this->view->addError('unknown', $e->getMessage());
error_log($e->getTraceAsString());
}
}
}
$this->getResponse()->appendBody($this->view->render('user/signup.php'));
}
示例5: function
<?php
require "../vendor/autoload.php";
require_once '../app/include/PassHash.php';
require_once '../app/include/DbConnect.php';
require_once '../app/include/Utils.php';
require_once '../app/models/Book.php';
require_once '../app/models/User.php';
require_once '../app/services/UserService.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
//Restful for Users
$app->post('/users', function () use($app) {
$jsonUser = $app->request->getBody();
$objUser = json_decode($jsonUser, true);
$res = UserService::createUser($objUser);
$response = array();
if ($res == USER_CREATED_SUCCESSFULLY) {
$response["error"] = false;
$response["message"] = "You are successfully registered";
Utils::echoResponse(201, $response);
} else {
if ($res == USER_CREATE_FAILED) {
$response["error"] = true;
$response["message"] = "Oops! An error occurred while registering. Please try again";
Utils::echoResponse(200, $response);
} else {
if ($res == USER_ALREADY_EXISTED) {
$response["error"] = true;
$response["message"] = "Sorry, this email already existed";
Utils::echoResponse(200, $response);
示例6: explode
$method = $_SERVER['REQUEST_METHOD'];
$request = explode("/", substr(@$_SERVER['PATH_INFO'], 1));
if ($method == 'GET' && $request[0] == 'test') {
$sv = new UserService();
$sv->test('json');
} else {
if ($method == 'GET' && $request[0] == 'search') {
echo 'mofidy search function ';
} else {
if ($method == 'POST' && $request[0] == 'test') {
if (isset($request[1]) && $request[1] == 'add') {
//add json object { "a":"aa","b":"bb", user":{"userid":"aaaa"}}
$sv = new UserService();
$input = json_decode(file_get_contents("php://input"));
// var_dump($input);
$rs = $sv->createUser($input, getuserid($input));
// var_dump($rs);
return $rs;
exit;
}
} else {
if ($method == 'PUT' && $request[0] == 'test') {
if (isset($request[1]) && is_numeric($request[1])) {
$sv = new UserService();
$input = json_decode(file_get_contents("php://input"));
// var_dump($input);
$rs = $sv->updateUser($input, getuserid($input));
// var_dump($rs);
return $rs;
exit;
}