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

marscoin / martianrepublic / 23772364858

30 Mar 2026 11:16PM UTC coverage: 9.35% (-0.01%) from 9.364%
23772364858

push

github

Martian Congress
fix: pre-compute wallet seeds JSON in controller, not inline Blade

The fn() arrow function inside {!! !!} was crashing the template.
Now controller pre-computes all_seeds_json and passes it to the view.
Simpler, safer, works.

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

0 of 8 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

511 of 5465 relevant lines covered (9.35%)

1.54 hits per line

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

9.81
/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
77
                                $cacheKey = '2fa_attempts:' . Auth::id();
×
78
                                $attempts = (int) Cache::get($cacheKey, 0);
×
79
                                if ($attempts >= 5) {
×
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 {
97
                                        Cache::put($cacheKey, $attempts + 1, now()->addMinutes(15));
×
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
182
                                $cacheKey = '2fa_attempts:' . Auth::id();
×
183
                                $attempts = (int) Cache::get($cacheKey, 0);
×
184
                                if ($attempts >= 5) {
×
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) {
×
192
                                        Cache::forget($cacheKey);
×
193

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

197
                                        return redirect('wallet/dashboard');
×
198
                                } else {
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

411
                        // Pre-compute all wallet seeds for multi-wallet discovery
NEW
412
                        $allSeeds = [];
×
NEW
413
                        if ($wallets) {
×
NEW
414
                                foreach ($wallets as $w) {
×
NEW
415
                                        if ($w->encrypted_seed && $w->public_addr) {
×
NEW
416
                                                $allSeeds[] = ['s' => $w->encrypted_seed, 'a' => $w->public_addr, 't' => 'hd'];
×
417
                                        }
418
                                }
419
                        }
NEW
420
                        if ($civic_wallet && $civic_wallet->encrypted_seed) {
×
NEW
421
                                $allSeeds[] = ['s' => $civic_wallet->encrypted_seed, 'a' => $civic_wallet->public_addr, 't' => 'civic'];
×
422
                        }
NEW
423
                        $view->all_seeds_json = json_encode($allSeeds);
×
424

UNCOV
425
                        return $view;
×
426
                } else {
427
                        return redirect('/login');
×
428
                }
429
        }
430

431
        // Show HD Wallet (Open)
432
        // /wallet/dashboard/hd-open
433
        protected function showHDOpen(Request $request)
×
434
        {
435
                if (Auth::check()) {
×
436
                        $uid = Auth::user()->id;
×
437
                        $profile = Profile::where('userid', '=', $uid)->first();
×
438
                        $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
439
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
440

441
                        if (!$profile) {
×
442
                                return redirect('/twofa');
×
443
                        } else {
444
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
445
                                        return redirect('/twofachallenge');
×
446
                                }
447
                        }
448
                        $data = json_decode($request->input("wallet"));
×
449

450
                        if ($data || ($wallets || $civic_wallet)) {
×
451
                                // Fetch wallet info from profile if this is not a newly unlocked wallet
452
                                if(is_null($data)){
×
453
                                        $data = HDWallet::where('id', '=', $profile->wallet_open)->first();
×
454
                                }
455
                                if(is_null($data)){
×
456
                                        $data = CivicWallet::where('user_id', '=', $uid)->first();
×
457
                                }
458
                                if (is_null($data)) {
×
459
                                        $profile->wallet_open = 0;
×
460
                                        $profile->civic_wallet_open = 0;
×
461
                                        $profile->save();
×
462
                                        return redirect('/wallet/dashboard/hd');
×
463
                                }
464

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

467
                                $codes = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
468
                                $view->SALT = $codes['salt'];
×
469
                                $view->iv = $codes['iv'];
×
470

471
                                $view->public_addr = $data->public_addr;
×
472
                                $view->encrypted_seed = $data->encrypted_seed;
×
473
                                $view->fullname = Auth::user()->fullname;
×
474
                                $view->wallet_open = $data->id;
×
475

476
                                $isCivicWalletOpen = $civic_wallet && $data && $civic_wallet->id === $data->id;
×
477

478
                                if($isCivicWalletOpen){
×
479
                                        $profile->wallet_open = 0;
×
480
                                        $profile->civic_wallet_open = $civic_wallet->id;
×
481
                                        $view->is_civic_wallet = $isCivicWalletOpen;
×
482
                                }else{
483
                                        $profile->wallet_open = $data->id;
×
484
                                        $profile->civic_wallet_open = 0;
×
485
                                        $view->is_civic_wallet = 0;
×
486
                                }
487
                                $profile->save();
×
488

489
                                // Pass civic wallet address for HD discovery linking
490
                                $view->civic_addr = $civic_wallet ? $civic_wallet->public_addr : '';
×
491

492
                                // Pass ALL wallet encrypted seeds for multi-wallet discovery
493
                                // Some wallets were encrypted with legacy 1-round PBKDF2
494
                                $allWallets = [];
×
495
                                foreach ($wallets as $w) {
×
496
                                        if ($w->encrypted_seed && $w->public_addr) {
×
497
                                                $allWallets[] = [
×
498
                                                        'encrypted_seed' => $w->encrypted_seed,
×
499
                                                        'public_addr' => $w->public_addr,
×
500
                                                        'type' => 'hd',
×
501
                                                ];
×
502
                                        }
503
                                }
504
                                if ($civic_wallet && $civic_wallet->encrypted_seed) {
×
505
                                        $allWallets[] = [
×
506
                                                'encrypted_seed' => $civic_wallet->encrypted_seed,
×
507
                                                'public_addr' => $civic_wallet->public_addr,
×
508
                                                'type' => 'civic',
×
509
                                        ];
×
510
                                }
511
                                $view->all_wallets = json_encode($allWallets);
×
512

513
                                return $view;
×
514
                        }else{
515
                                return redirect('/wallet/dashboard/hd');
×
516
                        }
517

518
                } else {
519
                        return redirect('/login');
×
520
                }
521
        }
522

523

524
        // Show HD Wallet (Close)
525
        protected function showHDClose()
×
526
        {
527
                if (Auth::check()) {
×
528
                        $uid = Auth::user()->id;
×
529
                        $profile = Profile::where('userid', '=', $uid)->first();
×
530

531
                        if (!$profile) {
×
532
                                return redirect('/twofa');
×
533
                        } else {
534
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
535
                                        return redirect('/twofachallenge');
×
536
                                }
537
                        }
538
                        Log::info("set open wallet to zero");
×
539
                        $profile->wallet_open = 0;
×
540
                        $profile->civic_wallet_open = 0;
×
541
                        $profile->save();
×
542

543
                        // Render the close view so client-side JS can clear localStorage,
544
                        // then redirect via JS. Previously this was a server redirect which
545
                        // meant the close() JS function never ran and keys persisted.
546
                        $view = View::make('wallet.hd-close');
×
547
                        $view->wallet_open = 0;
×
548
                        return $view;
×
549

550
                } else {
551
                        return redirect('/login');
×
552
                }
553
        }
554

555

556
        protected function forgetWallet(Request $request)
×
557
        {
558
                if (Auth::check()) {
×
559
                        $uid = Auth::user()->id;
×
560
                        $walletid = $request->input('hdwallet_id');
×
561

562
                        // Civic wallet reset (only if no on-chain activity)
563
                        if ($request->input('civic_reset')) {
×
564
                                $hasActivity = Feed::where('userid', $uid)->whereIn('tag', ['GP', 'CT', 'ED'])->exists();
×
565
                                if ($hasActivity) {
×
566
                                        return response()->json(['error' => 'Cannot reset: on-chain civic activity exists'], 403);
×
567
                                }
568
                                $civic = CivicWallet::where('id', $walletid)->where('user_id', $uid)->first();
×
569
                                if ($civic) {
×
570
                                        $profile = Profile::where('userid', $uid)->first();
×
571
                                        if ($profile) {
×
572
                                                $profile->civic_wallet_open = 0;
×
573
                                                $profile->has_application = 0;
×
574
                                                $profile->save();
×
575
                                        }
576
                                        Citizen::where('userid', $uid)->delete();
×
577
                                        $civic->delete();
×
578
                                        return response()->json(['success' => 'Civic wallet reset successfully']);
×
579
                                }
580
                        }
581

582
                        // Regular HD wallet delete
583
                        $wallet = HDWallet::where('id', $walletid)->where('user_id', $uid)->firstOrFail();
×
584
                        $wallet->delete();
×
585

586
                        return response()->json(['success' => 'Wallet deleted successfully']);
×
587
                }
588
                return response()->json(['error' => 'Unauthorized'], 403);
×
589
        }
590

591

592
        public function postCreateWallet(Request $request)
1✔
593
        {
594
                if (Auth::check()) {
1✔
595
                        $uid = Auth::user()->id;
1✔
596
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
597
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->get();
1✔
598
                        $civic = CivicWallet::where('user_id', '=', $uid)->first();
1✔
599

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

604
                        // user must insert password.. no null accepted...
605

606
                        // 3 States of Wallets: 
607
                        // 1) NO civic + No wallets
608
                        // 2) Civic + No wallets
609
                        // 3) Civic + wallets
610
                        if($request->input('wallet_name') == "Imported")
1✔
611
                        {
612
                                Log::debug("imported wallets are not being stored ... yet");
×
613
                                $new_wallet = new HDWallet;
×
614
                                $new_wallet->encrypted_seed = "ADHOC";
×
615
                                $new_wallet->public_addr = $request->input('public_addr');
×
616
                                $new_wallet->backup = 1;
×
617
                                $new_wallet->user_id = $uid;
×
618
                                $new_wallet->wallet_type = $request->input('wallet_name');;
×
619
                                $new_wallet->save();
×
620
                                $profile->wallet_open = $new_wallet->id;
×
621
                                $profile->civic_wallet_open = 0;
×
622
                                $profile->save();
×
623
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
624
                        }
625
                        else if (!$civicExists && $profile->civic_wallet_open == 0 && $profile->wallet_open == 0) 
1✔
626
                        {
627
                                Log::debug("first wallet created has to be civic wallet");
1✔
628
                                $new_civic_wallet = new CivicWallet;
1✔
629
                                if(empty($request->input('password')))
1✔
630
                                        $new_civic_wallet->encrypted_seed = "UNSET";
1✔
631
                                else
632
                                        $new_civic_wallet->encrypted_seed = $request->input('password');
×
633
                                $new_civic_wallet->public_addr = $request->input('public_addr');
1✔
634

635
                                $new_civic_wallet->backup = 1;
1✔
636

637
                                $new_civic_wallet->user_id = $uid;
1✔
638
                                $new_civic_wallet->wallet_type = $request->input('wallet_name');
1✔
639
                                $new_civic_wallet->save();
1✔
640
                                
641
                                $profile->civic_wallet_open = $new_civic_wallet->id;
1✔
642
                                $profile->wallet_open = 0;
1✔
643
                                $profile->save();
1✔
644
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
1✔
645
                        }
646
                        else if ($civicExists || $profile->civic_wallet_open == 1) 
×
647
                        {
648
                            Log::debug("non-civic wallet being created");
×
649
                                $new_wallet = new HDWallet;
×
650

651
                                $encseed = $request->input('password');
×
652
                                if(empty($encseed))
×
653
                                {
654
                                        $new_wallet->encrypted_seed = "ADHOC";
×
655
                                }
656
                                else{
657
                                        $new_wallet->encrypted_seed = $request->input('password');
×
658
                                }
659

660
                                $new_wallet->public_addr = $request->input('public_addr');
×
661

662
                                $new_wallet->backup = 1;
×
663

664
                                $new_wallet->user_id = $uid;
×
665
                                $new_wallet->wallet_type = $request->input('wallet_name');
×
666
                                
667
                                $new_wallet->save();
×
668

669
                                $profile->wallet_open = $new_wallet->id;
×
670
                                $profile->civic_wallet_open = 0;
×
671
                                $profile->save();
×
672
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
673
                        }
674
                        else
675
                        {
676
                                Log::debug("no wallet entry created in local db cache");
×
677
                                return redirect('/wallet/dashboard/hd');
×
678
                        }
679
                        return redirect('/wallet/dashboard/hd');
680

681
                } else {
682

683
                        return redirect('/login');
×
684
                }
685
        }
686

687
        // GET
688
        // Open Pre-Existing Wallet
689
        public function getWallet(Request $request)
2✔
690
        {
691
                if (Auth::check()) {
2✔
692

693
                        $uid = Auth::user()->id;
2✔
694
                        $profile = Profile::where('userid', '=', $uid)->first();
2✔
695

696
                        // Try HD wallet first, then civic wallet
697
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->first();
2✔
698
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
2✔
699

700
                        if ($hd_wallet) {
2✔
701
                                $profile->wallet_open = $hd_wallet->id;
1✔
702
                        } elseif ($civic_wallet) {
1✔
703
                                $profile->civic_wallet_open = $civic_wallet->id;
1✔
704
                        }
705
                        $profile->save();
2✔
706

707
                        return redirect('wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Open!');
2✔
708
                } else {
709
                        return redirect('/login');
×
710
                }
711
        }
712

713
        public function failWallet()
1✔
714
        {
715

716

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

720

721
        // Logout of Wallet ONLY
722
        public function walletLogout()
1✔
723
        {
724
                if (Auth::check()) {
1✔
725

726
                        $uid = Auth::user()->id;
1✔
727
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
728
                        $profile->wallet_open = 0;
1✔
729
                        $profile->civic_wallet_open = 0;
1✔
730
                        $profile->save();
1✔
731
                        return redirect('/wallet/dashboard');
1✔
732
                }
733

734
        }
735

736

737

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

758
                        return $view;
×
759
                } else {
760
                        return redirect('/login');
×
761
                }
762
        }
763

764

765
        protected function showReports()
×
766
        {
767
                if (Auth::check()) {
×
768
                        $uid = Auth::user()->id;
×
769
                        $profile = Profile::where('userid', '=', $uid)->first();
×
770
                        if (!$profile) {
×
771
                                return redirect('/twofa');
×
772
                        } else {
773
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
774
                                        return redirect('/twofachallenge');
×
775
                                }
776
                        }
777
                                $user = Auth::user();
×
778
                                $citizen = $user->citizen;
×
779
                        $view = View::make('wallet.reports');
×
780
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
781
                        $view->user = $user;
×
782
                        $view->citizen = $citizen;
×
783
                        $view->profile = $profile;
×
784
                        return $view;
×
785
                } else {
786
                        return redirect('/login');
×
787
                }
788
        }
789

790

791

792
        protected function anchor()
×
793
        {
794

795
                if (Auth::check()) {
×
796
                        $uid = Auth::user()->id;
×
797
                        $profile = Profile::where('userid', '=', $uid)->first();
×
798
                        $wallet = HDWallet::where('user_id', '=', $uid)->first();
×
799

800
                        if (!$profile) {
×
801
                                return redirect('/twofa');
×
802
                        } else {
803
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
804
                                        return redirect('/twofachallenge');
×
805
                                }
806
                        }
807
                        $view = View::make('wallet.anchor');
×
808

809
                        if ($wallet) {
×
810
                                $view->public_address = $wallet['public_addr'];
×
811
                        } else {
812
                                $view->balance = 0;
×
813
                                $view->public_address = "";
×
814
                        }
815
                        return $view;
×
816
                } else {
817
                        return redirect('/login');
×
818
                }
819
        }
820

821
        protected function showCamera()
×
822
        {
823
                if (Auth::check()) {
×
824
                        $uid = Auth::user()->id;
×
825
                        $profile = Profile::where('userid', '=', $uid)->first();
×
826
                        if (!$profile) {
×
827
                                return redirect('/twofa');
×
828
                        } else {
829
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
830
                                        return redirect('/twofachallenge');
×
831
                                }
832
                        }
833
                                $user = Auth::user();
×
834
                                $citizen = $user->citizen;
×
835
                        $view = View::make('wallet.camera');
×
836
                        $view->email = Auth::user()->email;
×
837
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
838
                        $view->user = $user;
×
839
                        $view->citizen = $citizen;
×
840
                        $view->profile = $profile;
×
841

842
                        return $view;
×
843
                } else {
844
                        return redirect('/login');
×
845
                }
846
        }
847

848

849
}
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