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

marscoin / martianrepublic / 23749891416

30 Mar 2026 02:25PM UTC coverage: 8.467% (+3.2%) from 5.241%
23749891416

push

github

Martian Congress
fix: resolve all 10 PHPStan errors + add 37 new tests

Fixes:
- DashboardController: undefined $user/$citizen in showReports/showCamera
- AiHelperController: env() → config() for cached config safety
- BADS models: add return type hints so Larastan resolves relations
- Ballots model: add return type hints for proposal/user relations
- ErrorTriageMail: fix regex delimiter and add unicode flag
- services.php: add openrouter config block

New test suites (37 tests, 97 assertions):
- AcademyTest: 10 article page loads + 404 handling
- ForumTest: categories, threads, posts, ordering, proposal linkage
- CongressTest: ballot relations, pendingForUser, controller methods
- InstrumentTest: chain of trust, calibration, attestations, soft delete
- AiHelperTest: validation, error triage mail, severity extraction

Total: 79 tests, 161 assertions, 0 PHPStan errors

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

14 of 21 new or added lines in 8 files covered. (66.67%)

1257 existing lines in 18 files now uncovered.

445 of 5256 relevant lines covered (8.47%)

1.06 hits per line

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

10.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 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
                                $view = View::make('wallet.hello2fa');
×
77
                                $view->qrcode_image = NULL;
×
78
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
79
                                $google2fa_secret = $profile->twofakey;
×
80
                                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
81

82

83

84
                                if ($valid) {
×
85
                                        $profile->twofaset = 1;
×
86
                                        $profile->save();
×
87
                                        $view->isvalid = "Success";
×
88
                                        return redirect('wallet/dashboard')->with('success', 'Two-factor authentication enabled! Your account is now secured.');
×
89
                                } else {
90
                                        $view->isvalid = "Failed";
×
91
                                }
92

93

94

95
                                return $view;
×
96
                        } else {
97
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
98

99
                                if (!$profile) {
×
100
                                        $key = $google2fa->generateSecretKey();
×
101
                                        $g2faUrl = $google2fa->getQRCodeUrl(
×
102
                                                'marscoinwallet',
×
103
                                                $email,
×
104
                                                $key
×
105
                                        );
×
106

107

108

109
                                        $profile = new Profile;
×
110
                                        $profile->userid = $uid;
×
111
                                        $profile->twofaset = 0;
×
112
                                        $profile->twofakey = $key;
×
113
                                        $profile->save();
×
114
                                        $writer = new Writer(
×
115
                                                new ImageRenderer(
×
116
                                                        new RendererStyle(300),
×
117
                                                        new ImagickImageBackEnd()
×
118
                                                )
×
119
                                        );
×
120

121
                                        $view = View::make('wallet.hello2fa');
×
122
                                        $view->isvalid = NULL;
×
123
                                        $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
124
                                        return $view;
×
125
                                } else if ($profile && $profile->twofaset == 0) {
×
126

127

128
                                        $key = $google2fa->generateSecretKey();
×
129
                                        $g2faUrl = $google2fa->getQRCodeUrl(
×
130
                                                'marscoinwallet',
×
131
                                                $email,
×
132
                                                $key
×
133
                                        );
×
134

135
                                        $profile->userid = $uid;
×
136
                                        $profile->twofakey = $key;
×
137
                                        $profile->save();
×
138

139
                                        $writer = new Writer(
×
140
                                                new ImageRenderer(
×
141
                                                        new RendererStyle(300),
×
142
                                                        new ImagickImageBackEnd()
×
143
                                                )
×
144
                                        );
×
145
                                        $view = View::make('wallet.hello2fa');
×
146
                                        $view->isvalid = NULL;
×
147
                                        $view->qrcode_image = base64_encode($writer->writeString($g2faUrl));
×
148

149
                                        return $view;
×
150
                                }
151
                                // else
152
                                // {
153
                                //         return redirect('wallet/dashboard');
154
                                // }
155
                        }
156
                } else {
157
                        return redirect('/login');
×
158
                }
159
        }
160

161

162
        protected function show2FAChallenge(Request $request)
×
163
        {
164
                if (Auth::check()) {
×
165
                        $email = Auth::user()->email;
×
166
                        $uid = Auth::user()->id;
×
167
                        $google2fa = app(Google2FA::class);
×
168
                        $secret = $request->input('secret');
×
169

170

171

172
                        if ($secret) {
×
173
                                $profile = Profile::where('userid', '=', Auth::user()->id)->first();
×
174
                                $google2fa_secret = $profile->twofakey;
×
175
                                $valid = $google2fa->verifyKey($google2fa_secret, $secret);
×
176
                                if ($valid) {
×
177

178
                                        $profile->openchallenge = 0;
×
179
                                        $profile->save();
×
180

181
                                        return redirect('wallet/dashboard');
×
182
                                } else {
183
                                        $view = View::make('wallet.challenge2fa');
×
184
                                        return $view;
×
185
                                }
186
                        } else {
187
                                $view = View::make('wallet.challenge2fa');
×
188
                                return $view;
×
189
                        }
190
                } else {
191
                        return redirect('/login');
×
192
                }
193
        }
194

195

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

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

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

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

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

UNCOV
267
                        $view->transactions = array();
×
268

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

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

286
        // Wallet history
287

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

UNCOV
297
                $view = View::make('wallet.create');
×
UNCOV
298
                $data = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
299
                $view->SALT = $data['salt'];
×
UNCOV
300
                $view->iv = $data['iv'];
×
301
                return $view;
×
302
        }
303

304
        // Show HD Wallet (Not Open)
305
        // /wallet/dashboard/hd
306
        protected function listHDWallet(Request $request)
×
307
        {
308
                if (Auth::check()) {
×
309
                        $uid = Auth::user()->id;
×
310
                        $profile = Profile::where('userid', '=', $uid)->first();
×
311

312
                        $key = $request->input('key');
×
UNCOV
313
                        if($key == "none")
×
314
                        {
UNCOV
315
                                Log::debug("Something went wrong with key storage");
×
316
                                $profile->wallet_open = 0;
×
317
                                $profile->civic_wallet_open = 0;
×
UNCOV
318
                                $profile->save();
×
319
                                return redirect('/wallet/dashboard');
×
320
                        }
321

322
                        //if wallet currently open, redirect to hd-open
UNCOV
323
                        if($profile->wallet_open > 0){
×
324
                                return redirect('/wallet/dashboard/hd-open');
×
325
                        }
UNCOV
326
                        if($profile->civic_wallet_open > 0){
×
327
                                return redirect('/wallet/dashboard/hd-open');
×
328
                        }
329

330
                        // list of all user wallets.
UNCOV
331
                        $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
332

333
                        // only one civic wallet ever...
UNCOV
334
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
335

336
                        // get balance of wallets.
337
                        foreach($wallets as $wallet)
×
338
                        {
339
                                $wallet->balance = AppHelper::getMarscoinBalance($wallet->public_addr);
×
340
                        }
341

342
                        // handle redirects...
343
                        if (!$profile) {
×
344
                                return redirect('/twofa');
×
345
                        } else {
UNCOV
346
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
347
                                        return redirect('/twofachallenge');
×
348
                                }
349
                        }
350
                        if ($profile->wallet_open >= 1 && !is_null($wallets)) {
×
UNCOV
351
                                return redirect('/wallet/dashboard/hd-open');
×
352
                        }
353

354
                        $view = View::make('wallet.hd');
×
355
                        
356

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

366
                                $view->general_public = $profile->general_public;
×
367
                                $view->citizen = $profile->citizen;
×
368
                                $view->applied = $profile->has_application;
×
369
                                $view->wallet_open = $profile->civic_wallet_open;
×
370
                        }
371

372

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

UNCOV
390
                        $data = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
391
                        $view->SALT = $data['salt'];
×
UNCOV
392
                        $view->iv = $data['iv'];
×
393
                        return $view;
×
394
                } else {
395
                        return redirect('/login');
×
396
                }
397
        }
398

399
        // Show HD Wallet (Open)
400
        // /wallet/dashboard/hd-open
UNCOV
401
        protected function showHDOpen(Request $request)
×
402
        {
403
                if (Auth::check()) {
×
UNCOV
404
                        $uid = Auth::user()->id;
×
UNCOV
405
                        $profile = Profile::where('userid', '=', $uid)->first();
×
406
                        $wallets = HDWallet::where('user_id', '=', $uid)->get();
×
UNCOV
407
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
408

UNCOV
409
                        if (!$profile) {
×
410
                                return redirect('/twofa');
×
411
                        } else {
UNCOV
412
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
413
                                        return redirect('/twofachallenge');
×
414
                                }
415
                        }
416
                        $data = json_decode($request->input("wallet"));
×
417

418
                        if ($data || ($wallets || $civic_wallet)) {
×
419
                                // Fetch wallet info from profile if this is not a newly unlocked wallet
420
                                if(is_null($data)){
×
UNCOV
421
                                        $data = HDWallet::where('id', '=', $profile->wallet_open)->first();
×
422
                                }
423
                                if(is_null($data)){
×
UNCOV
424
                                        $data = CivicWallet::where('user_id', '=', $uid)->first();
×
425
                                }
426
                                if (is_null($data)) {
×
427
                                        $profile->wallet_open = 0;
×
UNCOV
428
                                        $profile->civic_wallet_open = 0;
×
429
                                        $profile->save();
×
430
                                        return redirect('/wallet/dashboard/hd');
×
431
                                }
432

UNCOV
433
                                $view = View::make('wallet.hd-open');
×
434

UNCOV
435
                                $codes = json_decode(file_get_contents("/home/mars/constitution/marswallet.json"), true);
×
436
                                $view->SALT = $codes['salt'];
×
437
                                $view->iv = $codes['iv'];
×
438

439
                                $view->public_addr = $data->public_addr;
×
UNCOV
440
                                $view->encrypted_seed = $data->encrypted_seed;
×
441
                                $view->fullname = Auth::user()->fullname;
×
442
                                $view->wallet_open = $data->id;
×
443

UNCOV
444
                                $isCivicWalletOpen = $civic_wallet && $data && $civic_wallet->id === $data->id;
×
445

UNCOV
446
                                if($isCivicWalletOpen){
×
447
                                        $profile->wallet_open = 0;
×
UNCOV
448
                                        $profile->civic_wallet_open = $civic_wallet->id;
×
449
                                        $view->is_civic_wallet = $isCivicWalletOpen;
×
450
                                }else{
UNCOV
451
                                        $profile->wallet_open = $data->id;
×
UNCOV
452
                                        $profile->civic_wallet_open = 0;
×
453
                                        $view->is_civic_wallet = 0;
×
454
                                }
UNCOV
455
                                $profile->save();
×
456

457
                                // Pass civic wallet address for HD discovery linking
UNCOV
458
                                $view->civic_addr = $civic_wallet ? $civic_wallet->public_addr : '';
×
459

UNCOV
460
                                return $view;
×
461
                        }else{
462
                                return redirect('/wallet/dashboard/hd');
×
463
                        }
464

465
                } else {
466
                        return redirect('/login');
×
467
                }
468
        }
469

470

471
        // Show HD Wallet (Close)
472
        protected function showHDClose()
×
473
        {
474
                if (Auth::check()) {
×
475
                        $uid = Auth::user()->id;
×
UNCOV
476
                        $profile = Profile::where('userid', '=', $uid)->first();
×
477

UNCOV
478
                        if (!$profile) {
×
UNCOV
479
                                return redirect('/twofa');
×
480
                        } else {
481
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
UNCOV
482
                                        return redirect('/twofachallenge');
×
483
                                }
484
                        }
UNCOV
485
                        Log::info("set open wallet to zero");
×
486
                        $profile->wallet_open = 0;
×
UNCOV
487
                        $profile->civic_wallet_open = 0;
×
488
                        $profile->save();
×
489

490
                        // Render the close view so client-side JS can clear localStorage,
491
                        // then redirect via JS. Previously this was a server redirect which
492
                        // meant the close() JS function never ran and keys persisted.
493
                        $view = View::make('wallet.hd-close');
×
UNCOV
494
                        $view->wallet_open = 0;
×
495
                        return $view;
×
496

497
                } else {
UNCOV
498
                        return redirect('/login');
×
499
                }
500
        }
501

502

503
        protected function forgetWallet(Request $request)
×
504
        {
505
                if (Auth::check()) {
×
506
                        $uid = Auth::user()->id;
×
507
                        $walletid = $request->input('hdwallet_id');
×
508

509
                        // Civic wallet reset (only if no on-chain activity)
UNCOV
510
                        if ($request->input('civic_reset')) {
×
511
                                $hasActivity = Feed::where('userid', $uid)->whereIn('tag', ['GP', 'CT', 'ED'])->exists();
×
UNCOV
512
                                if ($hasActivity) {
×
513
                                        return response()->json(['error' => 'Cannot reset: on-chain civic activity exists'], 403);
×
514
                                }
UNCOV
515
                                $civic = CivicWallet::where('id', $walletid)->where('user_id', $uid)->first();
×
UNCOV
516
                                if ($civic) {
×
UNCOV
517
                                        $profile = Profile::where('userid', $uid)->first();
×
UNCOV
518
                                        if ($profile) {
×
UNCOV
519
                                                $profile->civic_wallet_open = 0;
×
UNCOV
520
                                                $profile->has_application = 0;
×
521
                                                $profile->save();
×
522
                                        }
523
                                        Citizen::where('userid', $uid)->delete();
×
524
                                        $civic->delete();
×
525
                                        return response()->json(['success' => 'Civic wallet reset successfully']);
×
526
                                }
527
                        }
528

529
                        // Regular HD wallet delete
530
                        $wallet = HDWallet::where('id', $walletid)->where('user_id', $uid)->firstOrFail();
×
531
                        $wallet->delete();
×
532

533
                        return response()->json(['success' => 'Wallet deleted successfully']);
×
534
                }
UNCOV
535
                return response()->json(['error' => 'Unauthorized'], 403);
×
536
        }
537

538

539
        public function postCreateWallet(Request $request)
1✔
540
        {
541
                if (Auth::check()) {
1✔
542
                        $uid = Auth::user()->id;
1✔
543
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
544
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->get();
1✔
545
                        $civic = CivicWallet::where('user_id', '=', $uid)->first();
1✔
546

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

551
                        // user must insert password.. no null accepted...
552

553
                        // 3 States of Wallets: 
554
                        // 1) NO civic + No wallets
555
                        // 2) Civic + No wallets
556
                        // 3) Civic + wallets
557
                        if($request->input('wallet_name') == "Imported")
1✔
558
                        {
559
                                Log::debug("imported wallets are not being stored ... yet");
×
560
                                $new_wallet = new HDWallet;
×
UNCOV
561
                                $new_wallet->encrypted_seed = "ADHOC";
×
562
                                $new_wallet->public_addr = $request->input('public_addr');
×
563
                                $new_wallet->backup = 1;
×
UNCOV
564
                                $new_wallet->user_id = $uid;
×
565
                                $new_wallet->wallet_type = $request->input('wallet_name');;
×
UNCOV
566
                                $new_wallet->save();
×
UNCOV
567
                                $profile->wallet_open = $new_wallet->id;
×
568
                                $profile->civic_wallet_open = 0;
×
UNCOV
569
                                $profile->save();
×
UNCOV
570
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
571
                        }
572
                        else if (!$civicExists && $profile->civic_wallet_open == 0 && $profile->wallet_open == 0) 
1✔
573
                        {
574
                                Log::debug("first wallet created has to be civic wallet");
1✔
575
                                $new_civic_wallet = new CivicWallet;
1✔
576
                                if(empty($request->input('password')))
1✔
577
                                        $new_civic_wallet->encrypted_seed = "UNSET";
1✔
578
                                else
UNCOV
579
                                        $new_civic_wallet->encrypted_seed = $request->input('password');
×
580
                                $new_civic_wallet->public_addr = $request->input('public_addr');
1✔
581

582
                                $new_civic_wallet->backup = 1;
1✔
583

584
                                $new_civic_wallet->user_id = $uid;
1✔
585
                                $new_civic_wallet->wallet_type = $request->input('wallet_name');
1✔
586
                                $new_civic_wallet->save();
1✔
587
                                
588
                                $profile->civic_wallet_open = $new_civic_wallet->id;
1✔
589
                                $profile->wallet_open = 0;
1✔
590
                                $profile->save();
1✔
591
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
1✔
592
                        }
UNCOV
593
                        else if ($civicExists || $profile->civic_wallet_open == 1) 
×
594
                        {
UNCOV
595
                            Log::debug("non-civic wallet being created");
×
UNCOV
596
                                $new_wallet = new HDWallet;
×
597

UNCOV
598
                                $encseed = $request->input('password');
×
UNCOV
599
                                if(empty($encseed))
×
600
                                {
UNCOV
601
                                        $new_wallet->encrypted_seed = "ADHOC";
×
602
                                }
603
                                else{
604
                                        $new_wallet->encrypted_seed = $request->input('password');
×
605
                                }
606

607
                                $new_wallet->public_addr = $request->input('public_addr');
×
608

UNCOV
609
                                $new_wallet->backup = 1;
×
610

UNCOV
611
                                $new_wallet->user_id = $uid;
×
612
                                $new_wallet->wallet_type = $request->input('wallet_name');
×
613
                                
UNCOV
614
                                $new_wallet->save();
×
615

616
                                $profile->wallet_open = $new_wallet->id;
×
UNCOV
617
                                $profile->civic_wallet_open = 0;
×
UNCOV
618
                                $profile->save();
×
UNCOV
619
                                return redirect('/wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Opened!');
×
620
                        }
621
                        else
622
                        {
UNCOV
623
                                Log::debug("no wallet entry created in local db cache");
×
UNCOV
624
                                return redirect('/wallet/dashboard/hd');
×
625
                        }
626
                        return redirect('/wallet/dashboard/hd');
627

628
                } else {
629

630
                        return redirect('/login');
×
631
                }
632
        }
633

634
        // GET
635
        // Open Pre-Existing Wallet
636
        public function getWallet(Request $request)
2✔
637
        {
638
                if (Auth::check()) {
2✔
639

640
                        $uid = Auth::user()->id;
2✔
641
                        $profile = Profile::where('userid', '=', $uid)->first();
2✔
642

643
                        // Try HD wallet first, then civic wallet
644
                        $hd_wallet = HDWallet::where('user_id', '=', $uid)->first();
2✔
645
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
2✔
646

647
                        if ($hd_wallet) {
2✔
648
                                $profile->wallet_open = $hd_wallet->id;
1✔
649
                        } elseif ($civic_wallet) {
1✔
650
                                $profile->civic_wallet_open = $civic_wallet->id;
1✔
651
                        }
652
                        $profile->save();
2✔
653

654
                        return redirect('wallet/dashboard/hd-open')->with('message', 'Wallet Successfully Open!');
2✔
655
                } else {
656
                        return redirect('/login');
×
657
                }
658
        }
659

660
        public function failWallet()
1✔
661
        {
662

663

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

667

668
        // Logout of Wallet ONLY
669
        public function walletLogout()
1✔
670
        {
671
                if (Auth::check()) {
1✔
672

673
                        $uid = Auth::user()->id;
1✔
674
                        $profile = Profile::where('userid', '=', $uid)->first();
1✔
675
                        $profile->wallet_open = 0;
1✔
676
                        $profile->civic_wallet_open = 0;
1✔
677
                        $profile->save();
1✔
678
                        return redirect('/wallet/dashboard');
1✔
679
                }
680

681
        }
682

683

684

685
        protected function showProfile()
×
686
        {
UNCOV
687
                if (Auth::check()) {
×
688
                        $uid = Auth::user()->id;
×
689
                        $profile = Profile::where('userid', '=', $uid)->first();
×
690
                        if (!$profile) {
×
691
                                return redirect('/twofa');
×
692
                        } else {
693
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
694
                                        return redirect('/twofachallenge');
×
695
                                }
696
                        }
697
                        $user = Auth::user();
×
UNCOV
698
                        $citizen = $user->citizen;
×
UNCOV
699
                        $view = View::make('wallet.profile');
×
700
                        $view->network = AppHelper::getMarscoinNetworkInfo();
×
UNCOV
701
                        $view->user = $user;
×
702
                        $view->citizen = $citizen;
×
703
                        $view->profile = $profile;
×
704

705
                        return $view;
×
706
                } else {
UNCOV
707
                        return redirect('/login');
×
708
                }
709
        }
710

711

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

737

738

UNCOV
739
        protected function anchor()
×
740
        {
741

UNCOV
742
                if (Auth::check()) {
×
UNCOV
743
                        $uid = Auth::user()->id;
×
UNCOV
744
                        $profile = Profile::where('userid', '=', $uid)->first();
×
UNCOV
745
                        $wallet = HDWallet::where('user_id', '=', $uid)->first();
×
746

UNCOV
747
                        if (!$profile) {
×
UNCOV
748
                                return redirect('/twofa');
×
749
                        } else {
UNCOV
750
                                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
×
UNCOV
751
                                        return redirect('/twofachallenge');
×
752
                                }
753
                        }
UNCOV
754
                        $view = View::make('wallet.anchor');
×
755

UNCOV
756
                        if ($wallet) {
×
UNCOV
757
                                $view->public_address = $wallet['public_addr'];
×
758
                        } else {
UNCOV
759
                                $view->balance = 0;
×
UNCOV
760
                                $view->public_address = "";
×
761
                        }
UNCOV
762
                        return $view;
×
763
                } else {
UNCOV
764
                        return redirect('/login');
×
765
                }
766
        }
767

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

UNCOV
789
                        return $view;
×
790
                } else {
UNCOV
791
                        return redirect('/login');
×
792
                }
793
        }
794

795

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