Esempio n. 1
0
function web_controller_auth_register()
{
    if (web_router_get_method() !== 'POST') {
        web_router_render_page('auth', 'register', []);
        return;
    }
    $email = web_router_get_param('email');
    if (!$email) {
        web_router_render_page('auth', 'register', ['msg' => 'Введите email', 'wrong' => 'email']);
        return;
    }
    preg_match('/[\\w\\d]+@[\\w\\d]+[\\w\\d\\.]+/', $email, $matches);
    if (!isset($matches[0])) {
        web_router_render_page('auth', 'register', ['msg' => 'Введите корректный email', 'wrong' => 'email']);
        return;
    }
    lets_use('user_register');
    $authUserId = user_register_get_user_id_by_email($email);
    if ($authUserId) {
        web_router_render_page('auth', 'register', ['msg' => 'Пользователь с таким email уже существует', 'wrong' => 'email']);
        return;
    }
    $userName = web_router_get_param('name');
    if (!$userName) {
        web_router_render_page('auth', 'register', ['msg' => 'Введите ваше имя', 'wrong' => 'name']);
        return;
    }
    $pass = web_router_get_param('pass');
    if (!$pass || mb_strlen($pass) < 6) {
        web_router_render_page('auth', 'register', ['msg' => 'Пароль должен быть задан и не менее 6ти символов', 'wrong' => 'pass']);
        return;
    }
    $userId = user_register_new_user($userName, $email, $pass);
    if (!$userId) {
        web_router_render_page('auth', 'register', ['msg' => 'Ошибка при сохранении пользвателя, повторите позднее', 'wrong' => 'error']);
        return;
    }
    lets_use('user_session');
    $secret = user_session_get_secret($userId);
    $token = user_session_build_token($userId, $secret);
    user_session_write_session_cookie($userId, $token, 86400 * 30);
    web_router_redirect('/');
}
Esempio n. 2
0
function web_controller_order_success()
{
    lets_use('storage_db', 'order_storage');
    $orderId = web_router_get_param('id');
    $order = order_storage_get_order($orderId);
    if (!$order) {
        web_router_render_page('order', 'success', ['order' => [], 'msg' => 'Не удалось получить созданный заказ']);
        return;
    }
    web_router_render_page('order', 'success', ['order' => $order, 'msg' => 'Заказ успешно создан']);
}
Esempio n. 3
0
function web_controller_billing_refill()
{
    lets_use('web_router', 'billing_balance', 'billing_account', 'billing_transaction', 'billing_locks', 'user_self');
    $incomingSource = 1;
    // благотоврительный фонд
    $sum = (double) web_router_get_param('sum');
    $sum = round($sum, 2);
    $accountFrom = billing_account_get_income_account($incomingSource);
    $accountTo = billing_account_get_user_main_account(user_self_id());
    $trId = billing_transaction_register($accountFrom, $accountTo, $sum);
    if (!$trId) {
        // cant register transaction
        billing_transaction_fail($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Ошибка сервера, повторите позже.']);
        return;
    }
    $lockRes = billing_locks_lock_transaction($trId, [$accountFrom, $accountTo]);
    if (!$lockRes) {
        // cant lock transaction
        billing_transaction_fail($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'В данный момент операция невозможна, повторите позже']);
        return;
    }
    $movementPossible = billing_balance_check_sum_available($accountFrom, $sum);
    if (!$movementPossible) {
        // not enough money
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'На исходящем счете недостаточно денег']);
        return;
    }
    $dbTransactionLock = billing_balance_storage_transaction_start();
    if (!$dbTransactionLock) {
        // cant begin db transaction
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось начать транзакцию']);
        return;
    }
    $moveRes = billing_balance_process_move($accountFrom, $accountTo, $sum, $trId);
    if (!$moveRes) {
        // cant move money
        billing_balance_storage_transaction_rollback();
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось перевести деньги']);
        return;
    }
    $transactionCommit = billing_balance_storage_transaction_commit();
    if ($transactionCommit) {
        // cant commit db transaction
        billing_transaction_fail($trId);
        billing_locks_unlock_transaction($trId);
        web_router_render_page('billing', 'refill', ['result' => false, 'msg' => 'Не удалось завершить транзакцию']);
        return;
    }
    billing_transaction_success($trId);
    billing_locks_unlock_transaction($trId);
    $moneyNow = billing_balance_get_account_amount($accountTo);
    web_router_render_page('billing', 'refill', ['result' => true, 'msg' => $sum . ' денежных единиц успешно переведены вам на счет. На вашем счету теперь: ' . $moneyNow]);
}