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

marscoin / martianrepublic / 23902636081

02 Apr 2026 01:24PM UTC coverage: 11.256%. Remained the same
23902636081

push

github

Martian Congress
refactor: A5 — standardize model names to singular (Laravel convention)

Renamed:
- Ballots → Ballot
- Proposals → Proposal
- Threads → Thread
- Posts → Post

Updated all imports and references across 15 files.
Table names unchanged ($table property preserved).
146 tests passing, 0 PHPStan errors.

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

6 of 38 new or added lines in 11 files covered. (15.79%)

664 of 5899 relevant lines covered (11.26%)

1.6 hits per line

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

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

3
namespace App\Http\Controllers\Wallet;
4

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

25
class DashboardController extends Controller
26
{
27
    /**
28
     * Setup the layout used by the controller.
29
     *
30
     * @return void
31
     */
32
    public function __construct() {}
7✔
33

34
    public function index()
×
35
    {
36
        return redirect('/wallet/dashboard');
×
37
    }
38

39
    protected function showLogout()
×
40
    {
41

42
        if (Auth::check()) {
×
43
            $uid = Auth::user()->id;
×
44
            $profile = Profile::where('userid', '=', $uid)->first();
×
45

46
            $profile->wallet_open = 0;
×
47
            $profile->civic_wallet_open = 0;
×
48
            $profile->save();
×
49
        }
50

51
        Auth::logout();
×
52

53
        return redirect('/login');
×
54
    }
55

56
    protected function show2FA(Request $request)
×
57
    {
58

59
        if (Auth::check()) {
×
60
            $email = Auth::user()->email;
×
61
            $uid = Auth::user()->id;
×
62
            $google2fa = app(Google2FA::class);
×
63
            $secret = $request->input('secret');
×
64
            if ($secret) {
×
65
                // Rate limit 2FA attempts: 5 per 15 minutes
66
                $cacheKey = '2fa_attempts:'.Auth::id();
×
67
                $attempts = (int) Cache::get($cacheKey, 0);
×
68
                if ($attempts >= 5) {
×
69
                    return redirect('/twofa')->with('error', 'Too many failed attempts. Please wait 15 minutes.');
×
70
                }
71

72
                $view = View::make('wallet.hello2fa');
×
73
                $view->qrcode_image = null;
×
74
                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
75
                $google2fa_secret = $profile->twofakey;
×
76
                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
77

78
                if ($valid) {
×
79
                    $profile->twofaset = 1;
×
80
                    $profile->save();
×
81
                    $view->isvalid = 'Success';
×
82

83
                    return redirect('wallet/dashboard')->with('success', 'Two-factor authentication enabled! Your account is now secured.');
×
84
                } else {
85
                    Cache::put($cacheKey, $attempts + 1, now()->addMinutes(15));
×
86
                    $view->isvalid = 'Failed';
×
87
                }
88

89
                return $view;
×
90
            } else {
91
                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
92

93
                if (! $profile) {
×
94
                    $key = $google2fa->generateSecretKey();
×
95
                    $g2faUrl = $google2fa->getQRCodeUrl(
×
96
                        'marscoinwallet',
×
97
                        $email,
×
98
                        $key
×
99
                    );
×
100

101
                    $profile = new Profile;
×
102
                    $profile->userid = $uid;
×
103
                    $profile->twofaset = 0;
×
104
                    $profile->twofakey = $key;
×
105
                    $profile->save();
×
106
                    $writer = new Writer(
×
107
                        new ImageRenderer(
×
108
                            new RendererStyle(300),
×
109
                            new ImagickImageBackEnd
×
110
                        )
×
111
                    );
×
112

113
                    $view = View::make('wallet.hello2fa');
×
114
                    $view->isvalid = null;
×
115
                    $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
116

117
                    return $view;
×
118
                } elseif ($profile && $profile->twofaset == 0) {
×
119

120
                    $key = $google2fa->generateSecretKey();
×
121
                    $g2faUrl = $google2fa->getQRCodeUrl(
×
122
                        'marscoinwallet',
×
123
                        $email,
×
124
                        $key
×
125
                    );
×
126

127
                    $profile->userid = $uid;
×
128
                    $profile->twofakey = $key;
×
129
                    $profile->save();
×
130

131
                    $writer = new Writer(
×
132
                        new ImageRenderer(
×
133
                            new RendererStyle(300),
×
134
                            new ImagickImageBackEnd
×
135
                        )
×
136
                    );
×
137
                    $view = View::make('wallet.hello2fa');
×
138
                    $view->isvalid = null;
×
139
                    $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
140

141
                    return $view;
×
142
                }
143
                // else
144
                // {
145
                //         return redirect('wallet/dashboard');
146
                // }
147
            }
148
        } else {
149
            return redirect('/login');
×
150
        }
151
    }
152

153
    protected function show2FAChallenge(Request $request)
×
154
    {
155
        if (Auth::check()) {
×
156
            $email = Auth::user()->email;
×
157
            $uid = Auth::user()->id;
×
158
            $google2fa = app(Google2FA::class);
×
159
            $secret = $request->input('secret');
×
160

161
            if ($secret) {
×
162
                // Rate limit 2FA attempts: 5 per 15 minutes
163
                $cacheKey = '2fa_attempts:'.Auth::id();
×
164
                $attempts = (int) Cache::get($cacheKey, 0);
×
165
                if ($attempts >= 5) {
×
166
                    return redirect('/twofachallenge')->with('error', 'Too many failed attempts. Please wait 15 minutes.');
×
167
                }
168

169
                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
170
                $google2fa_secret = $profile->twofakey;
×
171
                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
172
                if ($valid) {
×
173
                    Cache::forget($cacheKey);
×
174

175
                    $profile->openchallenge = 0;
×
176
                    $profile->save();
×
177

178
                    return redirect('wallet/dashboard');
×
179
                } else {
180
                    Cache::put($cacheKey, $attempts + 1, now()->addMinutes(15));
×
181
                    $view = View::make('wallet.challenge2fa');
×
182

183
                    return $view;
×
184
                }
185
            } else {
186
                $view = View::make('wallet.challenge2fa');
×
187

188
                return $view;
×
189
            }
190
        } else {
191
            return redirect('/login');
×
192
        }
193
    }
194

195
    protected function showChallenge()
×
196
    {
197
        if (Auth::check()) {
×
198
            // check if 2FA is on. If not, go to 2FA screen first
199
            $uid = Auth::user()->id;
×
200
            $profile = Profile::where('userid', '=', $uid)->first();
×
201
            if (! $profile) {
×
202
                return redirect('/twofa');
×
203
            } else {
204
                $is2faset = $profile->twofaset;
×
205
                $profile->openchallenge = 1;
×
206
                $profile->wallet_open = 0;
×
207
                $profile->save();
×
208
                if (! $is2faset) {
×
209
                    return redirect('/twofa');
×
210
                } else {
211
                    return redirect('/twofachallenge');
×
212
                }
213
            }
214
        } else {
215
            return redirect('/login');
×
216
        }
217
    }
218

219
    protected function showDashboard()
×
220
    {
221
        if (Auth::check()) {
×
222
            $uid = Auth::user()->id;
×
223
            $profile = Profile::where('userid', '=', $uid)->first();
×
224
            $wallet = HDWallet::where('user_id', '=', $uid)->get();
×
225
            $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
226
            if (! $profile) {
×
227
                return redirect('/twofa');
×
228
            } else {
229
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
230
                    return redirect('/twofachallenge');
×
231
                }
232
            }
233
            $view = View::make('wallet.dashboard');
×
234
            $view->public_addr = '';
×
235

236
            // Collect ALL wallet addresses for this user
237
            $allAddresses = [];
×
238
            if ($civic_wallet) {
×
239
                $allAddresses[] = $civic_wallet->public_addr;
×
240
            }
241
            $hdWallets = HDWallet::where('user_id', '=', $uid)->get();
×
242
            foreach ($hdWallets as $hw) {
×
243
                if (! in_array($hw->public_addr, $allAddresses)) {
×
244
                    $allAddresses[] = $hw->public_addr;
×
245
                }
246
            }
247

248
            $isWalletOpen = ($profile->civic_wallet_open > 0 || $profile->wallet_open > 0);
×
249

250
            if ($isWalletOpen && count($allAddresses) > 0) {
×
251
                // Primary address for transaction display (civic first)
252
                $view->public_addr = $civic_wallet ? $civic_wallet->public_addr : $allAddresses[0];
×
253
                // Pass all addresses for aggregated transaction view
254
                $view->all_addresses = $allAddresses;
×
255
                $view->has_civic_wallet = ($civic_wallet !== null);
×
256
                $view->has_wallet = true;
×
257
                $view->wallet_open = true;
×
258
            } else {
259
                $view->public_addr = '';
×
260
                $view->all_addresses = [];
×
261
                $view->has_civic_wallet = ($civic_wallet !== null);
×
262
                $view->has_wallet = count($allAddresses) > 0;
×
263
                $view->wallet_open = false;
×
264
            }
265

266
            $view->transactions = [];
×
267

268
            // Cache dashboard stats to reduce DB/API calls on every page load
269
            $view->coincount = AppHelper::getMarscoinTotalAmount();
×
270
            $view->forum_count = Cache::remember('forum_recent_count', 300, function () {
×
271
                return AppHelper::checkForRecentPosts();
×
272
            });
×
273
            $view->proposal_count = Cache::remember('proposal_open_count', 300, function () {
×
NEW
274
                return Proposal::countOpenProposals();
×
275
            });
×
276
            $citizenStatus = AppHelper::getCitizenStatus($uid);
×
277
            $view->citizen_status = $citizenStatus ? $citizenStatus->type : 'GP';
×
278

279
            return $view;
×
280
        } else {
281
            return redirect('/login');
×
282
        }
283
    }
284

285
    // Wallet history
286

287
    // Create Wallet Wizard (full-page, replaces modal)
288
    public function showCreateWallet()
×
289
    {
290
        if (! Auth::check()) {
×
291
            return redirect('/login');
×
292
        }
293
        $uid = Auth::user()->id;
×
294
        $profile = Profile::where('userid', $uid)->first();
×
295
        if (! $profile) {
×
296
            return redirect('/twofa');
×
297
        }
298
        if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
299
            return redirect('/twofachallenge');
×
300
        }
301

302
        $view = View::make('wallet.create');
×
303
        $data = json_decode(file_get_contents('/home/mars/constitution/marswallet.json'), true);
×
304
        $view->SALT = $data['salt'];
×
305
        $view->iv = $data['iv'];
×
306

307
        return $view;
×
308
    }
309

310
    // Show HD Wallet (Not Open)
311
    // /wallet/dashboard/hd
312
    protected function listHDWallet(Request $request)
×
313
    {
314
        if (Auth::check()) {
×
315
            $uid = Auth::user()->id;
×
316
            $profile = Profile::where('userid', '=', $uid)->first();
×
317

318
            $key = $request->input('key');
×
319
            if ($key == 'none') {
×
320
                Log::debug('Something went wrong with key storage');
×
321
                $profile->wallet_open = 0;
×
322
                $profile->civic_wallet_open = 0;
×
323
                $profile->save();
×
324

325
                return redirect('/wallet/dashboard');
×
326
            }
327

328
            // if wallet currently open, redirect to hd-open
329
            if ($profile->wallet_open > 0) {
×
330
                return redirect('/wallet/dashboard/hd-open');
×
331
            }
332
            if ($profile->civic_wallet_open > 0) {
×
333
                return redirect('/wallet/dashboard/hd-open');
×
334
            }
335

336
            // list of all user wallets.
337
            $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
338

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

342
            // get balance of wallets.
343
            foreach ($wallets as $wallet) {
×
344
                $wallet->balance = AppHelper::getMarscoinBalance($wallet->public_addr);
×
345
            }
346

347
            // handle redirects...
348
            if (! $profile) {
×
349
                return redirect('/twofa');
×
350
            } else {
351
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
352
                    return redirect('/twofachallenge');
×
353
                }
354
            }
355
            if ($profile->wallet_open >= 1 && ! is_null($wallets)) {
×
356
                return redirect('/wallet/dashboard/hd-open');
×
357
            }
358

359
            $view = View::make('wallet.hd');
×
360

361
            if (! is_null($civic_wallet)) {
×
362
                $view->civic_balance = AppHelper::getMarscoinBalance($civic_wallet->public_addr);
×
363
                $view->network = AppHelper::getMarscoinNetworkInfo();
×
364
                $view->user = Auth::user();
×
365
                $view->citizen = Citizen::where('userid', '=', $uid)->first();
×
366
                $view->profile = $profile;
×
367
                $view->public_addr = $civic_wallet->public_addr;
×
368

369
                $view->general_public = $profile->general_public;
×
370
                $view->citizen = $profile->citizen;
×
371
                $view->applied = $profile->has_application;
×
372
                $view->wallet_open = $profile->civic_wallet_open;
×
373
            }
374

375
            if (is_null($civic_wallet)) {
×
376
                $view->wallet_open = 0;
×
377
                $view->wallets = null;
×
378
                $view->encrypted_seed = null;
×
379
                $view->civic_wallet = null;
×
380
                $view->public_addr = null;
×
381
                $view->citizen = null;
×
382
                $view->applied = null;
×
383
            } else {
384
                $view->civic_wallet = $civic_wallet;
×
385
                $view->wallet_open = $profile->wallet_open;
×
386
                $view->encrypted_seed = $civic_wallet->encrypted_seed;
×
387
                $view->wallets = $wallets;
×
388
                $view->citizen = null;
×
389
                $view->applied = null;
×
390
            }
391

392
            $data = json_decode(file_get_contents('/home/mars/constitution/marswallet.json'), true);
×
393
            $view->SALT = $data['salt'];
×
394
            $view->iv = $data['iv'];
×
395

396
            // Pre-compute all wallet seeds for multi-wallet discovery
397
            $allSeeds = [];
×
398
            if ($wallets) {
×
399
                foreach ($wallets as $w) {
×
400
                    if ($w->encrypted_seed && $w->public_addr) {
×
401
                        $allSeeds[] = ['s' => $w->encrypted_seed, 'a' => $w->public_addr, 't' => 'hd'];
×
402
                    }
403
                }
404
            }
405
            if ($civic_wallet && $civic_wallet->encrypted_seed) {
×
406
                $allSeeds[] = ['s' => $civic_wallet->encrypted_seed, 'a' => $civic_wallet->public_addr, 't' => 'civic'];
×
407
            }
408
            $view->all_seeds_json = json_encode($allSeeds);
×
409

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

448
                    return redirect('/wallet/dashboard/hd');
×
449
                }
450

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

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

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

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

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

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

478
                // Pass ALL wallet encrypted seeds for multi-wallet discovery
479
                // Some wallets were encrypted with legacy 1-round PBKDF2
480
                $allWallets = [];
×
481
                foreach ($wallets as $w) {
×
482
                    if ($w->encrypted_seed && $w->public_addr) {
×
483
                        $allWallets[] = [
×
484
                            'encrypted_seed' => $w->encrypted_seed,
×
485
                            'public_addr' => $w->public_addr,
×
486
                            'type' => 'hd',
×
487
                        ];
×
488
                    }
489
                }
490
                if ($civic_wallet && $civic_wallet->encrypted_seed) {
×
491
                    $allWallets[] = [
×
492
                        'encrypted_seed' => $civic_wallet->encrypted_seed,
×
493
                        'public_addr' => $civic_wallet->public_addr,
×
494
                        'type' => 'civic',
×
495
                    ];
×
496
                }
497
                $view->all_wallets = json_encode($allWallets);
×
498

499
                return $view;
×
500
            } else {
501
                return redirect('/wallet/dashboard/hd');
×
502
            }
503

504
        } else {
505
            return redirect('/login');
×
506
        }
507
    }
508

509
    // Show HD Wallet (Close)
510
    protected function showHDClose()
×
511
    {
512
        if (Auth::check()) {
×
513
            $uid = Auth::user()->id;
×
514
            $profile = Profile::where('userid', '=', $uid)->first();
×
515

516
            if (! $profile) {
×
517
                return redirect('/twofa');
×
518
            } else {
519
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
520
                    return redirect('/twofachallenge');
×
521
                }
522
            }
523
            Log::info('set open wallet to zero');
×
524
            $profile->wallet_open = 0;
×
525
            $profile->civic_wallet_open = 0;
×
526
            $profile->save();
×
527

528
            // Render the close view so client-side JS can clear localStorage,
529
            // then redirect via JS. Previously this was a server redirect which
530
            // meant the close() JS function never ran and keys persisted.
531
            $view = View::make('wallet.hd-close');
×
532
            $view->wallet_open = 0;
×
533

534
            return $view;
×
535

536
        } else {
537
            return redirect('/login');
×
538
        }
539
    }
540

541
    protected function forgetWallet(Request $request)
×
542
    {
543
        if (Auth::check()) {
×
544
            $uid = Auth::user()->id;
×
545
            $walletid = $request->input('hdwallet_id');
×
546

547
            // Civic wallet reset (only if no on-chain activity)
548
            if ($request->input('civic_reset')) {
×
549
                $hasActivity = Feed::where('userid', $uid)->whereIn('tag', ['GP', 'CT', 'ED'])->exists();
×
550
                if ($hasActivity) {
×
551
                    return response()->json(['error' => 'Cannot reset: on-chain civic activity exists'], 403);
×
552
                }
553
                $civic = CivicWallet::where('id', $walletid)->where('user_id', $uid)->first();
×
554
                if ($civic) {
×
555
                    $profile = Profile::where('userid', $uid)->first();
×
556
                    if ($profile) {
×
557
                        $profile->civic_wallet_open = 0;
×
558
                        $profile->has_application = 0;
×
559
                        $profile->save();
×
560
                    }
561
                    Citizen::where('userid', $uid)->delete();
×
562
                    $civic->delete();
×
563

564
                    return response()->json(['success' => 'Civic wallet reset successfully']);
×
565
                }
566
            }
567

568
            // Regular HD wallet delete
569
            $wallet = HDWallet::where('id', $walletid)->where('user_id', $uid)->firstOrFail();
×
570
            $wallet->delete();
×
571

572
            return response()->json(['success' => 'Wallet deleted successfully']);
×
573
        }
574

575
        return response()->json(['error' => 'Unauthorized'], 403);
×
576
    }
577

578
    public function postCreateWallet(Request $request)
1✔
579
    {
580
        if (Auth::check()) {
1✔
581
            $uid = Auth::user()->id;
1✔
582
            $profile = Profile::where('userid', '=', $uid)->first();
1✔
583
            $hd_wallet = HDWallet::where('user_id', '=', $uid)->get();
1✔
584
            $civic = CivicWallet::where('user_id', '=', $uid)->first();
1✔
585

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

590
            // user must insert password.. no null accepted...
591

592
            // 3 States of Wallets:
593
            // 1) NO civic + No wallets
594
            // 2) Civic + No wallets
595
            // 3) Civic + wallets
596
            if ($request->input('wallet_name') == 'Imported') {
1✔
597
                Log::debug('imported wallets are not being stored ... yet');
×
598
                $new_wallet = new HDWallet;
×
599
                $new_wallet->encrypted_seed = 'ADHOC';
×
600
                $new_wallet->public_addr = $request->input('public_addr');
×
601
                $new_wallet->backup = 1;
×
602
                $new_wallet->user_id = $uid;
×
603
                $new_wallet->wallet_type = $request->input('wallet_name');
×
604
                $new_wallet->save();
×
605
                $profile->wallet_open = $new_wallet->id;
×
606
                $profile->civic_wallet_open = 0;
×
607
                $profile->save();
×
608

609
                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
610
            } elseif (! $civicExists && $profile->civic_wallet_open == 0 && $profile->wallet_open == 0) {
1✔
611
                Log::debug('first wallet created has to be civic wallet');
1✔
612
                $new_civic_wallet = new CivicWallet;
1✔
613
                if (empty($request->input('password'))) {
1✔
614
                    $new_civic_wallet->encrypted_seed = 'UNSET';
1✔
615
                } else {
616
                    $new_civic_wallet->encrypted_seed = $request->input('password');
×
617
                }
618
                $new_civic_wallet->public_addr = $request->input('public_addr');
1✔
619

620
                $new_civic_wallet->backup = 1;
1✔
621

622
                $new_civic_wallet->user_id = $uid;
1✔
623
                $new_civic_wallet->wallet_type = $request->input('wallet_name');
1✔
624
                $new_civic_wallet->save();
1✔
625

626
                $profile->civic_wallet_open = $new_civic_wallet->id;
1✔
627
                $profile->wallet_open = 0;
1✔
628
                $profile->save();
1✔
629

630
                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
1✔
631
            } elseif ($civicExists || $profile->civic_wallet_open == 1) {
×
632
                Log::debug('non-civic wallet being created');
×
633
                $new_wallet = new HDWallet;
×
634

635
                $encseed = $request->input('password');
×
636
                if (empty($encseed)) {
×
637
                    $new_wallet->encrypted_seed = 'ADHOC';
×
638
                } else {
639
                    $new_wallet->encrypted_seed = $request->input('password');
×
640
                }
641

642
                $new_wallet->public_addr = $request->input('public_addr');
×
643

644
                $new_wallet->backup = 1;
×
645

646
                $new_wallet->user_id = $uid;
×
647
                $new_wallet->wallet_type = $request->input('wallet_name');
×
648

649
                $new_wallet->save();
×
650

651
                $profile->wallet_open = $new_wallet->id;
×
652
                $profile->civic_wallet_open = 0;
×
653
                $profile->save();
×
654

655
                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
656
            } else {
657
                Log::debug('no wallet entry created in local db cache');
×
658

659
                return redirect('/wallet/dashboard/hd');
×
660
            }
661

662
            return redirect('/wallet/dashboard/hd');
663

664
        } else {
665

666
            return redirect('/login');
×
667
        }
668
    }
669

670
    // GET
671
    // Open Pre-Existing Wallet
672
    public function getWallet(Request $request)
2✔
673
    {
674
        if (Auth::check()) {
2✔
675

676
            $uid = Auth::user()->id;
2✔
677
            $profile = Profile::where('userid', '=', $uid)->first();
2✔
678

679
            // Try HD wallet first, then civic wallet
680
            $hd_wallet = HDWallet::where('user_id', '=', $uid)->first();
2✔
681
            $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
2✔
682

683
            if ($hd_wallet) {
2✔
684
                $profile->wallet_open = $hd_wallet->id;
1✔
685
            } elseif ($civic_wallet) {
1✔
686
                $profile->civic_wallet_open = $civic_wallet->id;
1✔
687
            }
688
            $profile->save();
2✔
689

690
            return redirect('wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Open!');
2✔
691
        } else {
692
            return redirect('/login');
×
693
        }
694
    }
695

696
    public function failWallet()
1✔
697
    {
698

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

702
    // Logout of Wallet ONLY
703
    public function walletLogout()
1✔
704
    {
705
        if (Auth::check()) {
1✔
706

707
            $uid = Auth::user()->id;
1✔
708
            $profile = Profile::where('userid', '=', $uid)->first();
1✔
709
            $profile->wallet_open = 0;
1✔
710
            $profile->civic_wallet_open = 0;
1✔
711
            $profile->save();
1✔
712

713
            return redirect('/wallet/dashboard');
1✔
714
        }
715

716
    }
717

718
    protected function showProfile()
×
719
    {
720
        if (Auth::check()) {
×
721
            $uid = Auth::user()->id;
×
722
            $profile = Profile::where('userid', '=', $uid)->first();
×
723
            if (! $profile) {
×
724
                return redirect('/twofa');
×
725
            } else {
726
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
727
                    return redirect('/twofachallenge');
×
728
                }
729
            }
730
            $user = Auth::user();
×
731
            $citizen = $user->citizen;
×
732
            $view = View::make('wallet.profile');
×
733
            $view->network = AppHelper::getMarscoinNetworkInfo();
×
734
            $view->user = $user;
×
735
            $view->citizen = $citizen;
×
736
            $view->profile = $profile;
×
737

738
            return $view;
×
739
        } else {
740
            return redirect('/login');
×
741
        }
742
    }
743

744
    protected function showReports()
×
745
    {
746
        if (Auth::check()) {
×
747
            $uid = Auth::user()->id;
×
748
            $profile = Profile::where('userid', '=', $uid)->first();
×
749
            if (! $profile) {
×
750
                return redirect('/twofa');
×
751
            } else {
752
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
753
                    return redirect('/twofachallenge');
×
754
                }
755
            }
756
            $user = Auth::user();
×
757
            $citizen = $user->citizen;
×
758
            $view = View::make('wallet.reports');
×
759
            $view->network = AppHelper::getMarscoinNetworkInfo();
×
760
            $view->user = $user;
×
761
            $view->citizen = $citizen;
×
762
            $view->profile = $profile;
×
763

764
            return $view;
×
765
        } else {
766
            return redirect('/login');
×
767
        }
768
    }
769

770
    protected function anchor()
×
771
    {
772

773
        if (Auth::check()) {
×
774
            $uid = Auth::user()->id;
×
775
            $profile = Profile::where('userid', '=', $uid)->first();
×
776
            $wallet = HDWallet::where('user_id', '=', $uid)->first();
×
777

778
            if (! $profile) {
×
779
                return redirect('/twofa');
×
780
            } else {
781
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
782
                    return redirect('/twofachallenge');
×
783
                }
784
            }
785
            $view = View::make('wallet.anchor');
×
786

787
            if ($wallet) {
×
788
                $view->public_address = $wallet['public_addr'];
×
789
            } else {
790
                $view->balance = 0;
×
791
                $view->public_address = '';
×
792
            }
793

794
            return $view;
×
795
        } else {
796
            return redirect('/login');
×
797
        }
798
    }
799

800
    protected function showCamera()
×
801
    {
802
        if (Auth::check()) {
×
803
            $uid = Auth::user()->id;
×
804
            $profile = Profile::where('userid', '=', $uid)->first();
×
805
            if (! $profile) {
×
806
                return redirect('/twofa');
×
807
            } else {
808
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
809
                    return redirect('/twofachallenge');
×
810
                }
811
            }
812
            $user = Auth::user();
×
813
            $citizen = $user->citizen;
×
814
            $view = View::make('wallet.camera');
×
815
            $view->email = Auth::user()->email;
×
816
            $view->network = AppHelper::getMarscoinNetworkInfo();
×
817
            $view->user = $user;
×
818
            $view->citizen = $citizen;
×
819
            $view->profile = $profile;
×
820

821
            return $view;
×
822
        } else {
823
            return redirect('/login');
×
824
        }
825
    }
826
}
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