forked from buckyroberts/Social-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallet.php
75 lines (54 loc) · 2.38 KB
/
wallet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require(dirname(__FILE__) . '/includes/bootstrap.php');
//Getting Current User ID
if(!buckys_check_user_acl(USER_ACL_REGISTERED)){
buckys_redirect('/register.php');
}
$bitcoinClass = new BuckysBitcoin();
//Create Wallet if it is not created
$bitcoinInfo = BuckysUser::getUserBitcoinInfo($userID);
if(!$bitcoinInfo){
$bitcoinInfo = $bitcoinClass->createWallet($TNB_GLOBALS['user']['userID'], $TNB_GLOBALS['user']['email']);
}
if(isset($_POST['action']) && $_POST['action'] == 'send-bitcoins'){
//Check Token
if(!buckys_check_form_token()){
buckys_redirect("/wallet.php", MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
$toAddress = $_POST['receiver'];
$amount = doubleval($_POST['amount']);
$password = $_POST['password'];
$user = BuckysUser::getUserData($TNB_GLOBALS['user']['userID']);
$is_error = false;
if(!$password || !buckys_validate_password($password, $user['password'])){
buckys_redirect("/wallet.php", MSG_CURRENT_PASSWORD_NOT_CORRECT, MSG_TYPE_ERROR);
}
if(!$toAddress){
buckys_redirect("/wallet.php", MSG_ENTER_BITCOINS_ADDRESS_OF_RECIPIENT, MSG_TYPE_ERROR);
}
if(!$amount || $amount <= 0){
buckys_redirect("/wallet.php", MSG_INVALID_BITCOIN_AMOUNT, MSG_TYPE_ERROR);
}
if(!$is_error){
$bitcoinClass->sendBitcoin($userID, $toAddress, $amount);
}
buckys_redirect("/wallet.php");
}
$page = isset($_GET['page']) ? $_GET['page'] : 1;
list($totalCount, $bitcoinBalance, $transactions) = $bitcoinClass->getTransactions($userID, $page, $bitcoinClass->COUNT_PER_PAGE);
if(!$bitcoinBalance)
$bitcoinBalance = 0;
//Init Pagination Class
$pagination = new Pagination($totalCount, $bitcoinClass->COUNT_PER_PAGE, $page);
$page = $pagination->getCurrentPage();
//Getting Balance
//$bitcoinBalance = $bitcoinClass->getWalletBalance($bitcoinInfo['bitcoin_guid'], buckys_decrypt($bitcoinInfo['bitcoin_password']));
buckys_enqueue_stylesheet('account.css');
buckys_enqueue_stylesheet('credits.css');
buckys_enqueue_javascript('wallet.js');
$TNB_GLOBALS['content'] = 'wallet';
$TNB_GLOBALS['title'] = "Wallet - " . TNB_SITE_NAME;
$TNB_GLOBALS['payerID'] = $userID;
$TNB_GLOBALS['meta'] = '<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">';
require(DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php");