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

marscoin / martianrepublic / 24513633245

16 Apr 2026 01:42PM UTC coverage: 10.997% (+0.002%) from 10.995%
24513633245

push

github

Martian Congress
fix: Resolve multiple Sentry-reported production crashes (#12, #13, #14, #15)

- QRLogin: Remove strict string type on $qrCodeImage to prevent Livewire
  rehydration crash when client sends array; add try-catch + defensive cast
  on QrCode::generate() result (#13)
- WalletStatus: Defensive cast on getMarscoinBalance() return values —
  falls back to 0 if API returns non-numeric; guard $balance in blade
  @script block against array type (#12)
- Congress dashboard: Remove dead hardcoded fetch() to pebas with dummy
  test address that was causing crawlers to discover phantom URL and
  trigger 500s on /api/mars/balance
- Citizen profile: Guard $mePublic access with null check — fixes crash
  for early users (pre-2021) with GP flag but no Feed record (#14)
- Citizen showId: Add default null for optional $address parameter —
  redirects to /citizen/all instead of crashing (#15)

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

2 of 12 new or added lines in 3 files covered. (16.67%)

665 of 6047 relevant lines covered (11.0%)

1.56 hits per line

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

28.46
/app/Http/Controllers/Citizen/IdentityController.php
1
<?php
2

3
namespace App\Http\Controllers\Citizen;
4

5
use App\Http\Controllers\Controller;
6
use App\Includes\AppHelper;
7
use App\Models\Citizen;
8
use App\Models\CivicWallet;
9
use App\Models\Feed;
10
use App\Models\Profile;
11
use App\Models\Proposal;
12
use App\Models\User;
13
use Carbon\Carbon;
14
use Illuminate\Support\Facades\Auth;
15
use Illuminate\Support\Facades\Cache;
16
use Illuminate\Support\Facades\DB;
17
use Illuminate\Support\Facades\View;
18

19
class IdentityController extends Controller
20
{
21
    /**
22
     * Setup the layout used by the controller.
23
     *
24
     * @return void
25
     */
26
    public function __construct() {}
3✔
27

28
    // The Gateway: citizen onboarding wizard
29
    public function showJoin()
×
30
    {
31
        if (! Auth::check()) {
×
32
            return redirect('/login');
×
33
        }
34
        $uid = Auth::user()->id;
×
35
        $profile = Profile::where('userid', $uid)->first();
×
36
        if (! $profile) {
×
37
            return redirect('/twofa');
×
38
        }
39

40
        $civic_wallet = CivicWallet::where('user_id', $uid)->first();
×
41
        if (! $civic_wallet) {
×
42
            return redirect('/wallet/dashboard/hd');
×
43
        }
44

45
        $citcache = Citizen::where('userid', $uid)->first();
×
46
        $view = View::make('citizen.join');
×
47
        $view->citcache = $citcache ? $citcache->toArray() : [];
×
48
        $view->public_address = $civic_wallet->public_addr;
×
49

50
        return $view;
×
51
    }
52

53
    // Get all public registrations and display table
54
    //
55
    public function showAll()
3✔
56
    {
57
        if (! Auth::check()) {
3✔
58
            return redirect('/login');
2✔
59
        }
60

61
        $view = View::make('citizen.registry');
1✔
62

63
        // Shared data - cached registry lists
64
        $view->everyPublic = Cache::remember('registry_every_public', 300, function () {
1✔
65
            return DB::select('SELECT u.*, p.*, c.*, ( SELECT f.txid FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1) AS txid, ( SELECT f.mined FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1) AS mined FROM users u JOIN profile p ON u.id = p.userid JOIN citizen c ON u.id = c.userid WHERE EXISTS ( SELECT 1 FROM feed f WHERE f.userid = u.id AND f.tag = ?) AND u.id NOT IN (?, ?) ORDER BY mined DESC LIMIT 100', ['GP', 'GP', 'GP', 6462, 7601]);
1✔
66
        });
1✔
67

68
        $view->everyCitizen = Cache::remember('registry_every_citizen', 300, function () {
1✔
69
            return DB::select('SELECT u.*, p.*, c.*, ( SELECT f.txid FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1 ) AS txid, ( SELECT f.mined FROM feed f WHERE f.userid = u.id AND f.tag = ? ORDER BY f.id DESC LIMIT 1 ) AS mined FROM users u JOIN profile p ON u.id = p.userid JOIN citizen c ON u.id = c.userid WHERE EXISTS ( SELECT 1 FROM feed f WHERE f.userid = u.id AND f.tag = ? ) AND u.id NOT IN (?) ORDER BY mined DESC LIMIT 100', ['CT', 'CT', 'CT', 6462]);
1✔
70
        });
1✔
71

72
        $view->everyApplicant = Cache::remember('registry_every_applicant', 300, function () {
1✔
73
            return DB::select('SELECT profile.userid, users.fullname, citizen.*, civic_wallet.public_addr AS address FROM users, profile, civic_wallet, citizen WHERE profile.userid = users.id AND users.id = civic_wallet.user_id AND citizen.userid = users.id AND profile.has_application = ? AND users.id NOT IN (?) ORDER BY citizen.created_at DESC LIMIT 100', [1, 6462]);
1✔
74
        });
1✔
75

76
        if (Auth::check()) {
1✔
77
            $uid = Auth::user()->id;
1✔
78
            $profile = Profile::where('userid', '=', $uid)->first();
1✔
79
            $wallet = CivicWallet::where('user_id', '=', $uid)->first();
1✔
80
            $citcache = Citizen::where('userid', '=', $uid)->first();
1✔
81
            if (! $profile) {
1✔
82
                return redirect('/twofa');
×
83
            } else {
84
                if ($profile->openchallenge == 1 || is_null($profile->openchallenge)) {
1✔
85
                    return redirect('/twofachallenge');
×
86
                }
87
            }
88
            $view->wallet_open = $profile->civic_wallet_open;
1✔
89
            $view->isCitizen = $profile->citizen;
1✔
90
            $view->citcache = $citcache;
1✔
91
            $view->isGP = $profile->general_public;
1✔
92
            $view->mePublic = Feed::where('userid', '=', $uid)->where('tag', '=', 'GP')->first();
1✔
93
            $view->meCitizen = Feed::where('userid', '=', $uid)->where('tag', '=', 'CT')->first();
1✔
94
            $view->feed = Feed::where('userid', '=', $uid)->whereNotNull('mined')->whereNotIn('tag', ['GP', 'CT'])->orderBy('created_at', 'desc')->get();
1✔
95
            $view->endorsed = [];
1✔
96
            $view->recentActivityCount = Feed::where('userid', $uid)->where('mined', '>=', Carbon::now()->subDay())->count();
1✔
97

98
            if ($wallet) {
1✔
99
                $view->balance = AppHelper::getMarscoinBalance($wallet['public_addr']);
1✔
100
                $view->public_address = $wallet['public_addr'];
1✔
101
                $view->endorsed = Feed::where('message', '=', $wallet['public_addr'])->where('tag', '=', 'ED')->get();
1✔
102
            } else {
103
                $view->balance = 0;
×
104
                $view->public_address = '';
×
105
            }
106
        }
107
        // Auth check at top of function ensures we never reach here unauthenticated
108

109
        return $view;
1✔
110

111
    }
112

113
    public function printout()
×
114
    {
115
        if (Auth::check()) {
×
116
            $uid = Auth::user()->id;
×
117
            $profile = Profile::where('userid', '=', $uid)->first();
×
118
            $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
119
            $view = View::make('citizen.printout');
×
120
            $citcache = Citizen::where('userid', '=', $uid)->first();
×
121
            $view->fullname = $citcache->firstname.' '.$citcache->lastname;
×
122

123
            if ($civic_wallet) {
×
124
                $view->public_address = $civic_wallet['public_addr'];
×
125
            } else {
126
                $view->balance = 0;
×
127
                $view->public_address = '';
×
128
            }
129

130
            return $view;
×
131
        } else {
132
            return redirect('/login');
×
133
        }
134
    }
135

136
    public function printout2()
×
137
    {
138
        if (Auth::check()) {
×
139
            $uid = Auth::user()->id;
×
140
            $profile = Profile::where('userid', '=', $uid)->first();
×
141
            $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
142
            $view = View::make('citizen.themes.printout2');
×
143
            $citcache = Citizen::where('userid', '=', $uid)->first();
×
144
            $view->fullname = $citcache->firstname.' '.$citcache->lastname;
×
145

146
            if ($civic_wallet) {
×
147
                $view->public_address = $civic_wallet['public_addr'];
×
148
            } else {
149
                $view->balance = 0;
×
150
                $view->public_address = '';
×
151
            }
152

153
            return $view;
×
154
        } else {
155
            return redirect('/login');
×
156
        }
157
    }
158

159
    public function printout3()
×
160
    {
161
        if (Auth::check()) {
×
162
            $uid = Auth::user()->id;
×
163
            $profile = Profile::where('userid', '=', $uid)->first();
×
164
            $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
165
            $view = View::make('citizen.themes.printout3');
×
166
            $citcache = Citizen::where('userid', '=', $uid)->first();
×
167
            $view->fullname = $citcache->firstname.' '.$citcache->lastname;
×
168

169
            if ($civic_wallet) {
×
170
                $view->public_address = $civic_wallet['public_addr'];
×
171
            } else {
172
                $view->balance = 0;
×
173
                $view->public_address = '';
×
174
            }
175

176
            return $view;
×
177
        } else {
178
            return redirect('/login');
×
179
        }
180
    }
181

182
    // Get profile view of another Martian Citizen
183
    //
NEW
184
    public function showId($address = null)
×
185
    {
NEW
186
        if (! $address) {
×
NEW
187
            return redirect('/citizen/all');
×
188
        }
189

190
        if (Auth::check()) {
×
191
            $uid = Auth::user()->id;
×
192
            // Martian user we are looking at
193
            $martian = Citizen::where('public_address', '=', $address)->first();
×
194
            if (! $martian) {
×
195
                abort(404, 'Citizen not found');
×
196
            }
197
            $martian_profile = Profile::where('userid', '=', $martian->userid)->first();
×
198
            $martian_proposals = Proposal::where('user_id', '=', $martian->userid)->count();
×
199
            $myprofile = Profile::where('userid', '=', $uid)->first();
×
200

201
            if (! $myprofile) {
×
202
                return redirect('/twofa');
×
203
            } else {
204
                if ($myprofile->openchallenge == 1 || is_null($myprofile->openchallenge)) {
×
205
                    return redirect('/twofachallenge');
×
206
                }
207
            }
208
            $view = View::make('citizen.martian');
×
209
            $view->wallet_open = $myprofile->civic_wallet_open;
×
210

211
            $view->isCitizen = $martian_profile->citizen;
×
212
            $view->endorsements = $martian_profile->endorse_cnt;
×
213
            $view->proposals = $martian_proposals;
×
214
            $view->isGP = $martian_profile->general_public;
×
215
            $view->mePublic = Feed::where('userid', '=', $martian->userid)->where('tag', '=', 'GP')->first();
×
216
            $view->meCitizen = Feed::where('userid', '=', $martian->userid)->where('tag', '=', 'CT')->first();
×
217
            $view->endorsed = Feed::where('userid', '=', $martian->userid)->where('tag', '=', 'ED')->count();
×
218

219
            $view->citcache = $martian;
×
220

221
            return $view;
×
222

223
        } else {
224
            return redirect('/login');
×
225
        }
226

227
    }
228
}
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