• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

marscoin / martianrepublic / 23750714281

30 Mar 2026 02:42PM UTC coverage: 8.401% (-0.07%) from 8.467%
23750714281

push

github

Martian Congress
security: Sprint 1 — comprehensive security hardening (S1–S14)

S1:  Command injection — replaced shell_exec with Process facade
     in BlockDisplay, BlockIntervalSparkline, LegislationRepo
S2:  XSS — removed addslashes(), use json_encode for JS contexts,
     strip_tags on markdown, escaped feed display messages
S3:  Input validation — added FormRequest classes for Congress
     amendments, tier challenges, and ballot key storage
S4:  Ballot encryption — encrypted_key/encryption_iv now use
     Laravel's encrypted cast (encrypted at rest with APP_KEY)
S6:  Rate limiting — throttle on AI chat (20/m), forum posts
     (5-10/m), contact form (3/m)
S7:  2FA brute-force — 5 failed attempts triggers 15min lockout
S8:  Token expiry — Sanctum tokens expire after 24 hours
S10: Log level — production changed from debug to warning
S13: HSTS preload — added preload directive
S14: CI hardened — composer audit now fails build on vulnerabilities

79 tests passing, 0 PHPStan errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

1 of 75 new or added lines in 9 files covered. (1.33%)

9 existing lines in 4 files now uncovered.

445 of 5297 relevant lines covered (8.4%)

1.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.31
/app/Http/Controllers/Wallet/DashboardController.php
1
<?php
2

3
namespace App\Http\Controllers\Wallet;
4

5
use App\Http\Controllers\Controller;
6
use PragmaRX\Google2FA\Google2FA;
7
use BaconQrCode\Renderer\ImageRenderer;
8
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
9
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
10
use BaconQrCode\Writer;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Facades\Auth;
13
use Illuminate\Support\Facades\View;
14
use Illuminate\Support\Facades\Cache;
15
use App\Models\Profile;
16
use App\Models\HDWallet;
17
use App\Models\Proposals;
18
use App\Models\IPFSRoot;
19
use App\Models\User;
20
use App\Models\Voucher;
21
use App\Includes\jsonRPCClient;
22
use App\Includes\AppHelper;
23
use App\Models\CivicWallet;
24
use App\Models\Feed;
25
use App\Models\Citizen;
26
use Illuminate\Support\Facades\Log;
27
use Exception;
28

29
class DashboardController extends Controller
30
{
31

32
        /**
33
         * Setup the layout used by the controller.
34
         *
35
         * @return void
36
         */
37

38
        public function __construct()
5✔
39
        {
40
        }
5✔
41

42

43
        public function index()
×
44
    {
45
        return redirect("/wallet/dashboard");
×
46
    }
47

48

49
        protected function showLogout()
×
50
        {
51

52
                if (Auth::check()) {
×
53
                        $uid = Auth::user()->id;
×
54
                        $profile = Profile::where('userid', '=', $uid)->first();
×
55

56
                        $profile->wallet_open = 0;
×
57
                        $profile->civic_wallet_open = 0;
×
58
                        $profile->save();
×
59
                }
60

61
                Auth::logout();
×
62

63
                return redirect('/login');
×
64
        }
65

66

67
        protected function show2FA(Request $request)
×
68
        {
69

70
                if (Auth::check()) {
×
71
                        $email = Auth::user()->email;
×
72
                        $uid = Auth::user()->id;
×
73
                        $google2fa = app(Google2FA::class);
×
74
                        $secret = $request->input('secret');
×
75
                        if ($secret) {
×
76
                                // Rate limit 2FA attempts: 5 per 15 minutes
NEW
77
                                $cacheKey = '2fa_attempts:' . Auth::id();
×
NEW
78
                                $attempts = (int) Cache::get($cacheKey, 0);
×
NEW
79
                                if ($attempts >= 5) {
×
NEW
80
                                        return redirect('/twofa')->with('error', 'Too many failed attempts. Please wait 15 minutes.');
×
81
                                }
82

83
                                $view = View::make('wallet.hello2fa');
×
84
                                $view->qrcode_image = NULL;
×
85
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
86
                                $google2fa_secret = $profile->twofakey;
×
87
                                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
88

89

90

91
                                if ($valid) {
×
92
                                        $profile->twofaset = 1;
×
93
                                        $profile->save();
×
94
                                        $view->isvalid = "Success";
×
95
                                        return redirect('wallet/dashboard')->with('success', 'Two-factor authentication enabled! Your account is now secured.');
×
96
                                } else {
NEW
97
                                        Cache::put($cacheKey, $attempts + 1, now()->addMinutes(15));
×
UNCOV
98
                                        $view->isvalid = "Failed";
×
99
                                }
100

101

102

103
                                return $view;
×
104
                        } else {
105
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
106

107
                                if (!$profile) {
×
108
                                        $key = $google2fa->generateSecretKey();
×
109
                                        $g2faUrl = $google2fa->getQRCodeUrl(
×
110
                                                'marscoinwallet',
×
111
                                                $email,
×
112
                                                $key
×
113
                                        );
×
114

115

116

117
                                        $profile = new Profile;
×
118
                                        $profile->userid = $uid;
×
119
                                        $profile->twofaset = 0;
×
120
                                        $profile->twofakey = $key;
×
121
                                        $profile->save();
×
122
                                        $writer = new Writer(
×
123
                                                new ImageRenderer(
×
124
                                                        new RendererStyle(300),
×
125
                                                        new ImagickImageBackEnd()
×
126
                                                )
×
127
                                        );
×
128

129
                                        $view = View::make('wallet.hello2fa');
×
130
                                        $view->isvalid = NULL;
×
131
                                        $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
132
                                        return $view;
×
133
                                } else if ($profile && $profile->twofaset == 0) {
×
134

135

136
                                        $key = $google2fa->generateSecretKey();
×
137
                                        $g2faUrl = $google2fa->getQRCodeUrl(
×
138
                                                'marscoinwallet',
×
139
                                                $email,
×
140
                                                $key
×
141
                                        );
×
142

143
                                        $profile->userid = $uid;
×
144
                                        $profile->twofakey = $key;
×
145
                                        $profile->save();
×
146

147
                                        $writer = new Writer(
×
148
                                                new ImageRenderer(
×
149
                                                        new RendererStyle(300),
×
150
                                                        new ImagickImageBackEnd()
×
151
                                                )
×
152
                                        );
×
153
                                        $view = View::make('wallet.hello2fa');
×
154
                                        $view->isvalid = NULL;
×
155
                                        $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
156

157
                                        return $view;
×
158
                                }
159
                                // else
160
                                // {
161
                                //         return redirect('wallet/dashboard');
162
                                // }
163
                        }
164
                } else {
165
                        return redirect('/login');
×
166
                }
167
        }
168

169

170
        protected function show2FAChallenge(Request $request)
×
171
        {
172
                if (Auth::check()) {
×
173
                        $email = Auth::user()->email;
×
174
                        $uid = Auth::user()->id;
×
175
                        $google2fa = app(Google2FA::class);
×
176
                        $secret = $request->input('secret');
×
177

178

179

180
                        if ($secret) {
×
181
                                // Rate limit 2FA attempts: 5 per 15 minutes
NEW
182
                                $cacheKey = '2fa_attempts:' . Auth::id();
×
NEW
183
                                $attempts = (int) Cache::get($cacheKey, 0);
×
NEW
184
                                if ($attempts >= 5) {
×
NEW
185
                                        return redirect('/twofachallenge')->with('error', 'Too many failed attempts. Please wait 15 minutes.');
×
186
                                }
187

188
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
189
                                $google2fa_secret = $profile->twofakey;
×
190
                                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
191
                                if ($valid) {
×
NEW
192
                                        Cache::forget($cacheKey);
×
193

194
                                        $profile->openchallenge = 0;
×
195
                                        $profile->save();
×
196

197
                                        return redirect('wallet/dashboard');
×
198
                                } else {
NEW
199
                                        Cache::put($cacheKey, $attempts + 1, now()->addMinutes(15));
×
200
                                        $view = View::make('wallet.challenge2fa');
×
201
                                        return $view;
×
202
                                }
203
                        } else {
204
                                $view = View::make('wallet.challenge2fa');
×
205
                                return $view;
×
206
                        }
207
                } else {
208
                        return redirect('/login');
×
209
                }
210
        }
211

212

213
        protected function showChallenge()
×
214
        {
215
                if (Auth::check()) {
×
216
                        //check if 2FA is on. If not, go to 2FA screen first
217
                        $uid = Auth::user()->id;
×
218
                        $profile = Profile::where('userid', '=', $uid)->first();
×
219
                        if (!$profile) {
×
220
                                return redirect('/twofa');
×
221
                        } else {
222
                                $is2faset = $profile->twofaset;
×
223
                                $profile->openchallenge = 1;
×
224
                                $profile->wallet_open = 0;
×
225
                                $profile->save();
×
226
                                if (!$is2faset) {
×
227
                                        return redirect('/twofa');
×
228
                                } else {
229
                                        return redirect('/twofachallenge');
×
230
                                }
231
                        }
232
                } else {
233
                        return redirect('/login');
×
234
                }
235
        }
236

237
        protected function showDashboard()
×
238
        {
239
                if (Auth::check()) {
×
240
                        $uid = Auth::user()->id;
×
241
                        $profile = Profile::where('userid', '=', $uid)->first();
×
242
                        $wallet = HDWallet::where('user_id', '=', $uid)->get();
×
243
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
244
                        if (!$profile) {
×
245
                                return redirect('/twofa');
×
246
                        } else {
247
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
248
                                        return redirect('/twofachallenge');
×
249
                                }
250
                        }
251
                        $view = View::make('wallet.dashboard');
×
252
                        $view->public_addr = "";
×
253

254
                        // Collect ALL wallet addresses for this user
255
                        $allAddresses = [];
×
256
                        if ($civic_wallet) {
×
257
                                $allAddresses[] = $civic_wallet->public_addr;
×
258
                        }
259
                        $hdWallets = HDWallet::where('user_id', '=', $uid)->get();
×
260
                        foreach ($hdWallets as $hw) {
×
261
                                if (!in_array($hw->public_addr, $allAddresses)) {
×
262
                                        $allAddresses[] = $hw->public_addr;
×
263
                                }
264
                        }
265

266
                        $isWalletOpen = ($profile->civic_wallet_open > 0 || $profile->wallet_open > 0);
×
267

268
                        if ($isWalletOpen && count($allAddresses) > 0) {
×
269
                                // Primary address for transaction display (civic first)
270
                                $view->public_addr = $civic_wallet ? $civic_wallet->public_addr : $allAddresses[0];
×
271
                                // Pass all addresses for aggregated transaction view
272
                                $view->all_addresses = $allAddresses;
×
273
                                $view->has_civic_wallet = ($civic_wallet !== null);
×
274
                                $view->has_wallet = true;
×
275
                                $view->wallet_open = true;
×
276
                        } else {
277
                                $view->public_addr = "";
×
278
                                $view->all_addresses = [];
×
279
                                $view->has_civic_wallet = ($civic_wallet !== null);
×
280
                                $view->has_wallet = count($allAddresses) > 0;
×
281
                                $view->wallet_open = false;
×
282
                        }
283

284
                        $view->transactions = array();
×
285

286
                        // Cache dashboard stats to reduce DB/API calls on every page load
287
                        $view->coincount = AppHelper::getMarscoinTotalAmount();
×
288
                        $view->forum_count = Cache::remember('forum_recent_count', 300, function () {
×
289
                                return AppHelper::checkForRecentPosts();
×
290
                        });
×
291
                        $view->proposal_count = Cache::remember('proposal_open_count', 300, function () {
×
292
                                return Proposals::countOpenProposals();
×
293
                        });
×
294
                        $citizenStatus = AppHelper::getCitizenStatus($uid);
×
295
                        $view->citizen_status = $citizenStatus ? $citizenStatus->type : 'GP';
×
296

297
                        return $view;
×
298
                } else {
299
                        return redirect('/login');
×
300
                }
301
        }
302

303
        // Wallet history
304

305
        // Create Wallet Wizard (full-page, replaces modal)
306
        public function showCreateWallet()
×
307
        {
308
                if (!Auth::check()) return redirect('/login');
×
309
                $uid = Auth::user()->id;
×
310
                $profile = Profile::where('userid', $uid)->first();
×
311
                if (!$profile) return redirect('/twofa');
×
312
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) return redirect('/twofachallenge');
×
313

314
                $view = View::make('wallet.create');
×
315
                $data = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
316
                $view->SALT = $data['salt'];
×
317
                $view->iv = $data['iv'];
×
318
                return $view;
×
319
        }
320

321
        // Show HD Wallet (Not Open)
322
        // /wallet/dashboard/hd
323
        protected function listHDWallet(Request $request)
×
324
        {
325
                if (Auth::check()) {
×
326
                        $uid = Auth::user()->id;
×
327
                        $profile = Profile::where('userid', '=', $uid)->first();
×
328

329
                        $key = $request->input('key');
×
330
                        if($key == "none")
×
331
                        {
332
                                Log::debug("Something went wrong with key storage");
×
333
                                $profile->wallet_open = 0;
×
334
                                $profile->civic_wallet_open = 0;
×
335
                                $profile->save();
×
336
                                return redirect('/wallet/dashboard');
×
337
                        }
338

339
                        //if wallet currently open, redirect to hd-open
340
                        if($profile->wallet_open > 0){
×
341
                                return redirect('/wallet/dashboard/hd-open');
×
342
                        }
343
                        if($profile->civic_wallet_open > 0){
×
344
                                return redirect('/wallet/dashboard/hd-open');
×
345
                        }
346

347
                        // list of all user wallets.
348
                        $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
349

350
                        // only one civic wallet ever...
351
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
352

353
                        // get balance of wallets.
354
                        foreach($wallets as $wallet)
×
355
                        {
356
                                $wallet->balance = AppHelper::getMarscoinBalance($wallet->public_addr);
×
357
                        }
358

359
                        // handle redirects...
360
                        if (!$profile) {
×
361
                                return redirect('/twofa');
×
362
                        } else {
363
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
364
                                        return redirect('/twofachallenge');
×
365
                                }
366
                        }
367
                        if ($profile->wallet_open >= 1 && !is_null($wallets)) {
×
368
                                return redirect('/wallet/dashboard/hd-open');
×
369
                        }
370

371
                        $view = View::make('wallet.hd');
×
372
                        
373

374
                        if(!is_null($civic_wallet))
×
375
                        {
376
                                $view->civic_balance = AppHelper::getMarscoinBalance($civic_wallet->public_addr);
×
377
                                $view->network = AppHelper::getMarscoinNetworkInfo();
×
378
                        $view->user = Auth::user();
×
379
                        $view->citizen = Citizen::where('userid', '=', $uid)->first();
×
380
                        $view->profile = $profile;
×
381
                                $view->public_addr = $civic_wallet->public_addr;
×
382

383
                                $view->general_public = $profile->general_public;
×
384
                                $view->citizen = $profile->citizen;
×
385
                                $view->applied = $profile->has_application;
×
386
                                $view->wallet_open = $profile->civic_wallet_open;
×
387
                        }
388

389

390
                        if (is_null($civic_wallet)) {
×
391
                                $view->wallet_open = 0;
×
392
                                $view->wallets = null;
×
393
                                $view->encrypted_seed = null;
×
394
                                $view->civic_wallet = null;
×
395
                                $view->public_addr = null;
×
396
                                $view->citizen = null;
×
397
                                $view->applied = null;
×
398
                        } else {
399
                                $view->civic_wallet = $civic_wallet;
×
400
                                $view->wallet_open = $profile->wallet_open;
×
401
                                $view->encrypted_seed = $civic_wallet->encrypted_seed;
×
402
                                $view->wallets = $wallets;
×
403
                                $view->citizen = null;
×
404
                                $view->applied = null;
×
405
                        }
406

407
                        $data = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
408
                        $view->SALT = $data['salt'];
×
409
                        $view->iv = $data['iv'];
×
410
                        return $view;
×
411
                } else {
412
                        return redirect('/login');
×
413
                }
414
        }
415

416
        // Show HD Wallet (Open)
417
        // /wallet/dashboard/hd-open
418
        protected function showHDOpen(Request $request)
×
419
        {
420
                if (Auth::check()) {
×
421
                        $uid = Auth::user()->id;
×
422
                        $profile = Profile::where('userid', '=', $uid)->first();
×
423
                        $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
424
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
425

426
                        if (!$profile) {
×
427
                                return redirect('/twofa');
×
428
                        } else {
429
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
430
                                        return redirect('/twofachallenge');
×
431
                                }
432
                        }
433
                        $data = json_decode($request->input("wallet"));
×
434

435
                        if ($data || ($wallets || $civic_wallet)) {
×
436
                                // Fetch wallet info from profile if this is not a newly unlocked wallet
437
                                if(is_null($data)){
×
438
                                        $data = HDWallet::where('id', '=', $profile->wallet_open)->first();
×
439
                                }
440
                                if(is_null($data)){
×
441
                                        $data = CivicWallet::where('user_id', '=', $uid)->first();
×
442
                                }
443
                                if (is_null($data)) {
×
444
                                        $profile->wallet_open = 0;
×
445
                                        $profile->civic_wallet_open = 0;
×
446
                                        $profile->save();
×
447
                                        return redirect('/wallet/dashboard/hd');
×
448
                                }
449

450
                                $view = View::make('wallet.hd-open');
×
451

452
                                $codes = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
453
                                $view->SALT = $codes['salt'];
×
454
                                $view->iv = $codes['iv'];
×
455

456
                                $view->public_addr = $data->public_addr;
×
457
                                $view->encrypted_seed = $data->encrypted_seed;
×
458
                                $view->fullname = Auth::user()->fullname;
×
459
                                $view->wallet_open = $data->id;
×
460

461
                                $isCivicWalletOpen = $civic_wallet && $data && $civic_wallet->id === $data->id;
×
462

463
                                if($isCivicWalletOpen){
×
464
                                        $profile->wallet_open = 0;
×
465
                                        $profile->civic_wallet_open = $civic_wallet->id;
×
466
                                        $view->is_civic_wallet = $isCivicWalletOpen;
×
467
                                }else{
468
                                        $profile->wallet_open = $data->id;
×
469
                                        $profile->civic_wallet_open = 0;
×
470
                                        $view->is_civic_wallet = 0;
×
471
                                }
472
                                $profile->save();
×
473

474
                                // Pass civic wallet address for HD discovery linking
475
                                $view->civic_addr = $civic_wallet ? $civic_wallet->public_addr : '';
×
476

477
                                return $view;
×
478
                        }else{
479
                                return redirect('/wallet/dashboard/hd');
×
480
                        }
481

482
                } else {
483
                        return redirect('/login');
×
484
                }
485
        }
486

487

488
        // Show HD Wallet (Close)
489
        protected function showHDClose()
×
490
        {
491
                if (Auth::check()) {
×
492
                        $uid = Auth::user()->id;
×
493
                        $profile = Profile::where('userid', '=', $uid)->first();
×
494

495
                        if (!$profile) {
×
496
                                return redirect('/twofa');
×
497
                        } else {
498
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
499
                                        return redirect('/twofachallenge');
×
500
                                }
501
                        }
502
                        Log::info("set open wallet to zero");
×
503
                        $profile->wallet_open = 0;
×
504
                        $profile->civic_wallet_open = 0;
×
505
                        $profile->save();
×
506

507
                        // Render the close view so client-side JS can clear localStorage,
508
                        // then redirect via JS. Previously this was a server redirect which
509
                        // meant the close() JS function never ran and keys persisted.
510
                        $view = View::make('wallet.hd-close');
×
511
                        $view->wallet_open = 0;
×
512
                        return $view;
×
513

514
                } else {
515
                        return redirect('/login');
×
516
                }
517
        }
518

519

520
        protected function forgetWallet(Request $request)
×
521
        {
522
                if (Auth::check()) {
×
523
                        $uid = Auth::user()->id;
×
524
                        $walletid = $request->input('hdwallet_id');
×
525

526
                        // Civic wallet reset (only if no on-chain activity)
527
                        if ($request->input('civic_reset')) {
×
528
                                $hasActivity = Feed::where('userid', $uid)->whereIn('tag', ['GP', 'CT', 'ED'])->exists();
×
529
                                if ($hasActivity) {
×
530
                                        return response()->json(['error' => 'Cannot reset: on-chain civic activity exists'], 403);
×
531
                                }
532
                                $civic = CivicWallet::where('id', $walletid)->where('user_id', $uid)->first();
×
533
                                if ($civic) {
×
534
                                        $profile = Profile::where('userid', $uid)->first();
×
535
                                        if ($profile) {
×
536
                                                $profile->civic_wallet_open = 0;
×
537
                                                $profile->has_application = 0;
×
538
                                                $profile->save();
×
539
                                        }
540
                                        Citizen::where('userid', $uid)->delete();
×
541
                                        $civic->delete();
×
542
                                        return response()->json(['success' => 'Civic wallet reset successfully']);
×
543
                                }
544
                        }
545

546
                        // Regular HD wallet delete
547
                        $wallet = HDWallet::where('id', $walletid)->where('user_id', $uid)->firstOrFail();
×
548
                        $wallet->delete();
×
549

550
                        return response()->json(['success' => 'Wallet deleted successfully']);
×
551
                }
552
                return response()->json(['error' => 'Unauthorized'], 403);
×
553
        }
554

555

556
        public function postCreateWallet(Request $request)
1✔
557
        {
558
                if (Auth::check()) {
1✔
559
                        $uid = Auth::user()->id;
1✔
560
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
561
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->get();
1✔
562
                        $civic = CivicWallet::where('user_id', '=', $uid)->first();
1✔
563

564
                        Log::info("See if user has civic wallet");
1✔
565
                        // Check if the user has a Civic wallet already, even if it's not opened
566
                        $civicExists = CivicWallet::where('user_id', '=', $uid)->exists();
1✔
567

568
                        // user must insert password.. no null accepted...
569

570
                        // 3 States of Wallets: 
571
                        // 1) NO civic + No wallets
572
                        // 2) Civic + No wallets
573
                        // 3) Civic + wallets
574
                        if($request->input('wallet_name') == "Imported")
1✔
575
                        {
576
                                Log::debug("imported wallets are not being stored ... yet");
×
577
                                $new_wallet = new HDWallet;
×
578
                                $new_wallet->encrypted_seed = "ADHOC";
×
579
                                $new_wallet->public_addr = $request->input('public_addr');
×
580
                                $new_wallet->backup = 1;
×
581
                                $new_wallet->user_id = $uid;
×
582
                                $new_wallet->wallet_type = $request->input('wallet_name');;
×
583
                                $new_wallet->save();
×
584
                                $profile->wallet_open = $new_wallet->id;
×
585
                                $profile->civic_wallet_open = 0;
×
586
                                $profile->save();
×
587
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
588
                        }
589
                        else if (!$civicExists && $profile->civic_wallet_open == 0 && $profile->wallet_open == 0) 
1✔
590
                        {
591
                                Log::debug("first wallet created has to be civic wallet");
1✔
592
                                $new_civic_wallet = new CivicWallet;
1✔
593
                                if(empty($request->input('password')))
1✔
594
                                        $new_civic_wallet->encrypted_seed = "UNSET";
1✔
595
                                else
596
                                        $new_civic_wallet->encrypted_seed = $request->input('password');
×
597
                                $new_civic_wallet->public_addr = $request->input('public_addr');
1✔
598

599
                                $new_civic_wallet->backup = 1;
1✔
600

601
                                $new_civic_wallet->user_id = $uid;
1✔
602
                                $new_civic_wallet->wallet_type = $request->input('wallet_name');
1✔
603
                                $new_civic_wallet->save();
1✔
604
                                
605
                                $profile->civic_wallet_open = $new_civic_wallet->id;
1✔
606
                                $profile->wallet_open = 0;
1✔
607
                                $profile->save();
1✔
608
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
1✔
609
                        }
610
                        else if ($civicExists || $profile->civic_wallet_open == 1) 
×
611
                        {
612
                            Log::debug("non-civic wallet being created");
×
613
                                $new_wallet = new HDWallet;
×
614

615
                                $encseed = $request->input('password');
×
616
                                if(empty($encseed))
×
617
                                {
618
                                        $new_wallet->encrypted_seed = "ADHOC";
×
619
                                }
620
                                else{
621
                                        $new_wallet->encrypted_seed = $request->input('password');
×
622
                                }
623

624
                                $new_wallet->public_addr = $request->input('public_addr');
×
625

626
                                $new_wallet->backup = 1;
×
627

628
                                $new_wallet->user_id = $uid;
×
629
                                $new_wallet->wallet_type = $request->input('wallet_name');
×
630
                                
631
                                $new_wallet->save();
×
632

633
                                $profile->wallet_open = $new_wallet->id;
×
634
                                $profile->civic_wallet_open = 0;
×
635
                                $profile->save();
×
636
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
637
                        }
638
                        else
639
                        {
640
                                Log::debug("no wallet entry created in local db cache");
×
641
                                return redirect('/wallet/dashboard/hd');
×
642
                        }
643
                        return redirect('/wallet/dashboard/hd');
644

645
                } else {
646

647
                        return redirect('/login');
×
648
                }
649
        }
650

651
        // GET
652
        // Open Pre-Existing Wallet
653
        public function getWallet(Request $request)
2✔
654
        {
655
                if (Auth::check()) {
2✔
656

657
                        $uid = Auth::user()->id;
2✔
658
                        $profile = Profile::where('userid', '=', $uid)->first();
2✔
659

660
                        // Try HD wallet first, then civic wallet
661
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->first();
2✔
662
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
2✔
663

664
                        if ($hd_wallet) {
2✔
665
                                $profile->wallet_open = $hd_wallet->id;
1✔
666
                        } elseif ($civic_wallet) {
1✔
667
                                $profile->civic_wallet_open = $civic_wallet->id;
1✔
668
                        }
669
                        $profile->save();
2✔
670

671
                        return redirect('wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Open!');
2✔
672
                } else {
673
                        return redirect('/login');
×
674
                }
675
        }
676

677
        public function failWallet()
1✔
678
        {
679

680

681
                return redirect('wallet/dashboard/hd')->with('error', 'Wallet unlock failed. Please check your credentials and try again.');
1✔
682
        }
683

684

685
        // Logout of Wallet ONLY
686
        public function walletLogout()
1✔
687
        {
688
                if (Auth::check()) {
1✔
689

690
                        $uid = Auth::user()->id;
1✔
691
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
692
                        $profile->wallet_open = 0;
1✔
693
                        $profile->civic_wallet_open = 0;
1✔
694
                        $profile->save();
1✔
695
                        return redirect('/wallet/dashboard');
1✔
696
                }
697

698
        }
699

700

701

702
        protected function showProfile()
×
703
        {
704
                if (Auth::check()) {
×
705
                        $uid = Auth::user()->id;
×
706
                        $profile = Profile::where('userid', '=', $uid)->first();
×
707
                        if (!$profile) {
×
708
                                return redirect('/twofa');
×
709
                        } else {
710
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
711
                                        return redirect('/twofachallenge');
×
712
                                }
713
                        }
714
                        $user = Auth::user();
×
715
                        $citizen = $user->citizen;
×
716
                        $view = View::make('wallet.profile');
×
717
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
718
                        $view->user = $user;
×
719
                        $view->citizen = $citizen;
×
720
                        $view->profile = $profile;
×
721

722
                        return $view;
×
723
                } else {
724
                        return redirect('/login');
×
725
                }
726
        }
727

728

729
        protected function showReports()
×
730
        {
731
                if (Auth::check()) {
×
732
                        $uid = Auth::user()->id;
×
733
                        $profile = Profile::where('userid', '=', $uid)->first();
×
734
                        if (!$profile) {
×
735
                                return redirect('/twofa');
×
736
                        } else {
737
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
738
                                        return redirect('/twofachallenge');
×
739
                                }
740
                        }
741
                                $user = Auth::user();
×
742
                                $citizen = $user->citizen;
×
743
                        $view = View::make('wallet.reports');
×
744
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
745
                        $view->user = $user;
×
746
                        $view->citizen = $citizen;
×
747
                        $view->profile = $profile;
×
748
                        return $view;
×
749
                } else {
750
                        return redirect('/login');
×
751
                }
752
        }
753

754

755

756
        protected function anchor()
×
757
        {
758

759
                if (Auth::check()) {
×
760
                        $uid = Auth::user()->id;
×
761
                        $profile = Profile::where('userid', '=', $uid)->first();
×
762
                        $wallet = HDWallet::where('user_id', '=', $uid)->first();
×
763

764
                        if (!$profile) {
×
765
                                return redirect('/twofa');
×
766
                        } else {
767
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
768
                                        return redirect('/twofachallenge');
×
769
                                }
770
                        }
771
                        $view = View::make('wallet.anchor');
×
772

773
                        if ($wallet) {
×
774
                                $view->public_address = $wallet['public_addr'];
×
775
                        } else {
776
                                $view->balance = 0;
×
777
                                $view->public_address = "";
×
778
                        }
779
                        return $view;
×
780
                } else {
781
                        return redirect('/login');
×
782
                }
783
        }
784

785
        protected function showCamera()
×
786
        {
787
                if (Auth::check()) {
×
788
                        $uid = Auth::user()->id;
×
789
                        $profile = Profile::where('userid', '=', $uid)->first();
×
790
                        if (!$profile) {
×
791
                                return redirect('/twofa');
×
792
                        } else {
793
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
794
                                        return redirect('/twofachallenge');
×
795
                                }
796
                        }
797
                                $user = Auth::user();
×
798
                                $citizen = $user->citizen;
×
799
                        $view = View::make('wallet.camera');
×
800
                        $view->email = Auth::user()->email;
×
801
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
802
                        $view->user = $user;
×
803
                        $view->citizen = $citizen;
×
804
                        $view->profile = $profile;
×
805

806
                        return $view;
×
807
                } else {
808
                        return redirect('/login');
×
809
                }
810
        }
811

812

813
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc