コード例 #1
0
ファイル: api.php プロジェクト: YounessTayer/directus
})->name('auth_reset_password');
$app->post("/{$v}/auth/forgot-password/?", function () use($app, $acl, $ZendDb) {
    if (!isset($_POST['email'])) {
        return JsonView::render(['success' => false, 'message' => __t('password_forgot_invalid_email')]);
    }
    $DirectusUsersTableGateway = new DirectusUsersTableGateway($acl, $ZendDb);
    $user = $DirectusUsersTableGateway->findOneBy('email', $_POST['email']);
    if (false === $user) {
        return JsonView::render(['success' => false, 'message' => __t('password_forgot_no_account_found')]);
    }
    $set = [];
    $set['reset_token'] = StringUtils::randomString(30);
    $set['reset_expiration'] = DateUtils::inDays(2);
    // Skip ACL
    $DirectusUsersTableGateway = new \Zend\Db\TableGateway\TableGateway('directus_users', $ZendDb);
    $affectedRows = $DirectusUsersTableGateway->update($set, ['id' => $user['id']]);
    if (1 !== $affectedRows) {
        return JsonView::render(['success' => false]);
    }
    $data = ['reset_token' => $set['reset_token']];
    Mail::send('mail/reset-password.twig.html', $data, function ($message) use($user) {
        $message->setSubject(__t('password_forgot_password_reset_email_subject'));
        $message->setTo($user['email']);
    });
    $success = true;
    return JsonView::render(['success' => $success]);
})->name('auth_permissions');
// debug helper
$app->get("/{$v}/auth/permissions/?", function () use($app, $acl) {
    if ('production' === DIRECTUS_ENV) {
        return $app->halt('404');
コード例 #2
0
ファイル: api.php プロジェクト: smkkstudios/Directus
$app->post("/{$v}/auth/forgot-password/?", function () use($app, $acl, $ZendDb) {
    if (!isset($_POST['email'])) {
        return JsonView::render(array('success' => false, 'message' => 'Invalid email address.'));
    }
    $DirectusUsersTableGateway = new DirectusUsersTableGateway($acl, $ZendDb);
    $user = $DirectusUsersTableGateway->findOneBy('email', $_POST['email']);
    if (false === $user) {
        return JsonView::render(array('success' => false, 'message' => "An account with that email address doesn't exist."));
    }
    $password = uniqid();
    $set = array();
    $set['salt'] = uniqid();
    $set['password'] = Auth::hashPassword($password, $set['salt']);
    // Skip ACL
    $DirectusUsersTableGateway = new \Zend\Db\TableGateway\TableGateway('directus_users', $ZendDb);
    $affectedRows = $DirectusUsersTableGateway->update($set, array('id' => $user['id']));
    if (1 !== $affectedRows) {
        return JsonView::render(array('success' => false));
    }
    $mail = new Directus\Mail\Mailer();
    $mail->send(new Directus\Mail\ForgotPasswordMail($user['email'], $password));
    $success = true;
    return JsonView::render(array('success' => $success));
})->name('auth_permissions');
// debug helper
$app->get("/{$v}/auth/permissions/?", function () use($app, $acl) {
    if ('production' === DIRECTUS_ENV) {
        return $app->halt('404');
    }
    $groupPrivileges = $acl->getGroupPrivileges();
    JsonView::render(array('groupPrivileges' => $groupPrivileges));
コード例 #3
0
<?php

$adapter = (include file_exists('bootstrap.php') ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
/* @var $adapter Zend\Db\Adapter */
$artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter);
$result = $artistTable->update(array('name' => 'New Artist'), array('id' => 2));
assert_example_works($result === 1, true);
$artistTable = new Zend\Db\TableGateway\TableGateway('artist', $adapter);
$rowset = $artistTable->select(array('id' => 2));
$row = $rowset->current();
$name = $row['name'];
assert_example_works($name == 'New Artist');