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

marscoin / martianrepublic / 23771307754

30 Mar 2026 10:43PM UTC coverage: 9.364% (-0.03%) from 9.39%
23771307754

push

github

Martian Congress
feat: multi-wallet discovery — decrypt all seeds with both PBKDF2 rounds

Users may have multiple wallets encrypted with different mnemonics AND
different PBKDF2 round counts (100,000 current vs 1 legacy). Discovery
now:

1. Controller passes all wallet encrypted seeds to the view
2. After primary mnemonic discovery, tries decrypting each other
   wallet seed with both 100k-round and 1-round PBKDF2
3. If a different mnemonic is found, derives addresses from it
4. Scans those addresses against marscoind via scantxoutset
5. Adds any found funds to the discovery results

Fixes: HD wallets created during the legacy 1-round PBKDF2 era were
invisible because the app only decrypted the civic wallet seed.

Also cleaned up test pages (bip32-compare, mnemonic-test, etc).

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

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

1 existing line in 1 file now uncovered.

511 of 5457 relevant lines covered (9.36%)

1.54 hits per line

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

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

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

503
                } else {
504
                        return redirect('/login');
×
505
                }
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
                        return $view;
×
534

535
                } else {
536
                        return redirect('/login');
×
537
                }
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
                                        return response()->json(['success' => 'Civic wallet reset successfully']);
×
564
                                }
565
                        }
566

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

571
                        return response()->json(['success' => 'Wallet deleted successfully']);
×
572
                }
573
                return response()->json(['error' => 'Unauthorized'], 403);
×
574
        }
575

576

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

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

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

591
                        // 3 States of Wallets: 
592
                        // 1) NO civic + No wallets
593
                        // 2) Civic + No wallets
594
                        // 3) Civic + wallets
595
                        if($request->input('wallet_name') == "Imported")
1✔
596
                        {
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
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
609
                        }
610
                        else if (!$civicExists && $profile->civic_wallet_open == 0 && $profile->wallet_open == 0) 
1✔
611
                        {
612
                                Log::debug("first wallet created has to be civic wallet");
1✔
613
                                $new_civic_wallet = new CivicWallet;
1✔
614
                                if(empty($request->input('password')))
1✔
615
                                        $new_civic_wallet->encrypted_seed = "UNSET";
1✔
616
                                else
617
                                        $new_civic_wallet->encrypted_seed = $request->input('password');
×
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
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
1✔
630
                        }
631
                        else if ($civicExists || $profile->civic_wallet_open == 1) 
×
632
                        {
633
                            Log::debug("non-civic wallet being created");
×
634
                                $new_wallet = new HDWallet;
×
635

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

645
                                $new_wallet->public_addr = $request->input('public_addr');
×
646

647
                                $new_wallet->backup = 1;
×
648

649
                                $new_wallet->user_id = $uid;
×
650
                                $new_wallet->wallet_type = $request->input('wallet_name');
×
651
                                
652
                                $new_wallet->save();
×
653

654
                                $profile->wallet_open = $new_wallet->id;
×
655
                                $profile->civic_wallet_open = 0;
×
656
                                $profile->save();
×
657
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
658
                        }
659
                        else
660
                        {
661
                                Log::debug("no wallet entry created in local db cache");
×
662
                                return redirect('/wallet/dashboard/hd');
×
663
                        }
664
                        return redirect('/wallet/dashboard/hd');
665

666
                } else {
667

668
                        return redirect('/login');
×
669
                }
670
        }
671

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

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

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

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

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

698
        public function failWallet()
1✔
699
        {
700

701

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

705

706
        // Logout of Wallet ONLY
707
        public function walletLogout()
1✔
708
        {
709
                if (Auth::check()) {
1✔
710

711
                        $uid = Auth::user()->id;
1✔
712
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
713
                        $profile->wallet_open = 0;
1✔
714
                        $profile->civic_wallet_open = 0;
1✔
715
                        $profile->save();
1✔
716
                        return redirect('/wallet/dashboard');
1✔
717
                }
718

719
        }
720

721

722

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

743
                        return $view;
×
744
                } else {
745
                        return redirect('/login');
×
746
                }
747
        }
748

749

750
        protected function showReports()
×
751
        {
752
                if (Auth::check()) {
×
753
                        $uid = Auth::user()->id;
×
754
                        $profile = Profile::where('userid', '=', $uid)->first();
×
755
                        if (!$profile) {
×
756
                                return redirect('/twofa');
×
757
                        } else {
758
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
759
                                        return redirect('/twofachallenge');
×
760
                                }
761
                        }
762
                                $user = Auth::user();
×
763
                                $citizen = $user->citizen;
×
764
                        $view = View::make('wallet.reports');
×
765
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
766
                        $view->user = $user;
×
767
                        $view->citizen = $citizen;
×
768
                        $view->profile = $profile;
×
769
                        return $view;
×
770
                } else {
771
                        return redirect('/login');
×
772
                }
773
        }
774

775

776

777
        protected function anchor()
×
778
        {
779

780
                if (Auth::check()) {
×
781
                        $uid = Auth::user()->id;
×
782
                        $profile = Profile::where('userid', '=', $uid)->first();
×
783
                        $wallet = HDWallet::where('user_id', '=', $uid)->first();
×
784

785
                        if (!$profile) {
×
786
                                return redirect('/twofa');
×
787
                        } else {
788
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
789
                                        return redirect('/twofachallenge');
×
790
                                }
791
                        }
792
                        $view = View::make('wallet.anchor');
×
793

794
                        if ($wallet) {
×
795
                                $view->public_address = $wallet['public_addr'];
×
796
                        } else {
797
                                $view->balance = 0;
×
798
                                $view->public_address = "";
×
799
                        }
800
                        return $view;
×
801
                } else {
802
                        return redirect('/login');
×
803
                }
804
        }
805

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

827
                        return $view;
×
828
                } else {
829
                        return redirect('/login');
×
830
                }
831
        }
832

833

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