本文整理汇总了PHP中UserDB::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP UserDB::insert方法的具体用法?PHP UserDB::insert怎么用?PHP UserDB::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserDB
的用法示例。
在下文中一共展示了UserDB::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: function
$app->post('/register', function () use($app) {
$username = $_POST['username'];
$password = $_POST['password'];
$retypePassword = $_POST['retypePassword'];
$email = $_POST['email'];
$invitationCode = $app->request->post('invitation');
$DBH = new PDO(PDO_DSN, MYSQL_USER, MYSQL_PASS);
$data = array("code" => $invitationCode);
$sth = $DBH->prepare("SELECT code FROM invitation_codes WHERE code = :code");
$sth->execute($data);
if (empty($sth->fetch())) {
echo json_encode(array('status' => false, 'message' => 'You have not entered a valid invitation code'));
return;
}
$userCollection = new UserDB();
$userCreated = $userCollection->insert($username, $password, $retypePassword, $email);
if ($userCreated['status']) {
$data = array("code" => $invitationCode);
$sth = $DBH->prepare("SELECT code FROM invitation_codes WHERE code = :code");
$sth->execute($data);
if (!empty($sth->fetch())) {
$sth = $DBH->prepare("DELETE FROM invitation_codes WHERE code = :code");
$sth->execute($data);
} else {
echo json_encode(array('status' => false, 'message' => 'You have not entered a valid invitation code'));
return;
}
$user = new User($username);
$user->registered = true;
$user->update();
$_SESSION['AUTHED'] = true;
示例2: ujemata
echo "<p>Geslo in ponovni vnos gesla se ne ujemata (obvezno), preverite obrazec. </p>";
}
if (isset($_POST["Email"]) && $_POST["Email"] != "") {
$Email = $_POST["Email"];
} else {
$RegisterFormOK = 0;
echo "<p>E-posta ni vnešena (obvezno), preverite obrazec. </p>";
}
if (isset($_POST["FirstName"]) && $_POST["FirstName"] != "") {
$FirstName = $_POST["FirstName"];
} else {
$RegisterFormOK = 0;
echo "<p>Ime ni vnešeno (obvezno), preverite obrazec. </p>";
}
if (isset($_POST["LastName"]) && $_POST["LastName"] != "") {
$LastName = $_POST["LastName"];
} else {
$RegisterFormOK = 0;
echo "<p>Priimek ni vnešen (obvezno), preverite obrazec. </p>";
}
if ($RegisterFormOK != 100) {
echo "<p>Zaradi napak v obrazcu, registracija ni uspela. Preglejte opozorila in ponovno poskusite.</p>";
} else {
echo "Username:" . $Username;
echo "Password:" . $Password;
echo "Email:" . $Email;
echo "FirstName:" . $FirstName;
echo "LastName:" . $LastName;
UserDB::insert($Username, $Password, $Email, $FirstName, $LastName);
echo "<br/>Registracija uporabnika " . $Username . " je uspela. Prijavite se z uporabniškim imenom in geslom, na obrazcu za prijavo. <br/>";
}
示例3: verifyRequiredParams
$r = json_decode($app->request->getBody());
verifyRequiredParams(array('email', 'name', 'password'), $r->user);
$dbHost = $app->config('db_host');
$dbName = $app->config('db_name');
$dbUser = $app->config('db_user');
$dbPass = $app->config('db_password');
$db = new UserDB($dbHost, $dbName, $dbUser, $dbPass);
$name = $r->user->name;
$email = $r->user->email;
$password = $r->user->password;
$token = $r->token;
$isUserExists = $db->fetchByEmail($email);
if (!$isUserExists) {
//$password = PasswordHash::hash($password);
$hashed_password = password_hash($password, PASSWORD_DEFAULT, array('cost' => 10));
$result = $db->insert($email, $name, $hashed_password);
if ($result) {
$response = array('status' => true, 'message' => 'User account created successfully!', 'user' => array('id' => $result, 'name' => $name, 'email' => $email));
$session = new Session();
$session->set('id', $result);
$session->set('name', $name);
$session->set('email', $email);
// ユーザー登録が完了した時点でトークンファイルを削除する
unlink(dirname(__FILE__) . '/../../token/' . $token);
echoResponse(200, $response);
} else {
$response = array('status' => false, 'message' => 'Failed to create user...');
echoResponse(201, $response);
}
} else {
$response = array('status' => false, 'message' => 'The user with the provided email exists!');