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

marscoin / martianrepublic / 23800574218

31 Mar 2026 01:44PM UTC coverage: 9.347% (+0.07%) from 9.277%
23800574218

push

github

Martian Congress
fix: null citizen crash on /citizen/id/:address (user 20612)

Accessing a citizen ID page for an address without a citizen record
caused a 500 — $martian was null but $martian->userid was accessed.
Now returns 404 when citizen record doesn't exist.

Caught by AI Error Triage system.

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

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

511 of 5467 relevant lines covered (9.35%)

1.54 hits per line

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

30.25
/app/Http/Controllers/Citizen/IdentityController.php
1
<?php
2
namespace App\Http\Controllers\Citizen;
3

4
use App\Http\Controllers\Controller;
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\DB;
7
use Illuminate\Support\Facades\Auth;
8
use App\Models\Profile;
9
use App\Models\Feed;
10
use App\Models\User;
11
use App\Models\Proposals;
12
use App\Models\HDWallet;
13
use App\Models\CivicWallet;
14
use App\Models\Citizen;
15
use Illuminate\Support\Facades\View;
16
use App\Includes\jsonRPCClient;
17
use App\Includes\AppHelper;
18
use App\Exceptions\Handler;
19
use Exception;
20
use Carbon\Carbon;
21
use Illuminate\Support\Facades\Cache;
22

23

24
class IdentityController extends Controller
25
{
26

27
        /**
28
         * Setup the layout used by the controller.
29
         *
30
         * @return void
31
         */
32

33
        public function __construct()
2✔
34
        {
35
        }
2✔
36

37

38
        // The Gateway: citizen onboarding wizard
39
        public function showJoin()
×
40
        {
41
                if (!Auth::check()) return redirect('/login');
×
42
                $uid = Auth::user()->id;
×
43
                $profile = Profile::where('userid', $uid)->first();
×
44
                if (!$profile) return redirect('/twofa');
×
45

46
                $civic_wallet = CivicWallet::where('user_id', $uid)->first();
×
47
                if (!$civic_wallet) return redirect('/wallet/dashboard/hd');
×
48

49
                $citcache = Citizen::where('userid', $uid)->first();
×
50
                $view = View::make('citizen.join');
×
51
                $view->citcache = $citcache ? $citcache->toArray() : [];
×
52
                $view->public_address = $civic_wallet->public_addr;
×
53
                return $view;
×
54
        }
55

56
        //Get all public registrations and display table
57
        //
58
    public function showAll()
2✔
59
        {
60
                if (!Auth::check()) {
2✔
61
                        return redirect('/login');
1✔
62
                }
63

64
                $view = View::make('citizen.registry');
1✔
65

66
                // Shared data - cached registry lists
67
                $view->everyPublic = Cache::remember('registry_every_public', 300, function () {
1✔
68
                        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', ['GP', 'GP', 'GP', 6462, 7601]);
1✔
69
                });
1✔
70

71
                $view->everyCitizen = Cache::remember('registry_every_citizen', 300, function () {
1✔
72
                        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', ['CT', 'CT', 'CT', 6462]);
1✔
73
                });
1✔
74

75
                $view->everyApplicant = Cache::remember('registry_every_applicant', 300, function () {
1✔
76
                        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', [1, 6462]);
1✔
77
                });
1✔
78

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

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

112
                return $view;
1✔
113

114
                
115
        }
116

117

118

119
        public function printout()
×
120
        {
121
                if (Auth::check()) {
×
122
                        $uid = Auth::user()->id;
×
123
                        $profile = Profile::where('userid', '=', $uid)->first();
×
124
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
125
                        $view = View::make('citizen.printout');
×
126
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
127
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
128
                        
129
                        if ($civic_wallet) {
×
130
                                $view->public_address = $civic_wallet['public_addr'];
×
131
                        } else {
132
                                $view->balance = 0;
×
133
                                $view->public_address = "";
×
134
                        }
135
                        return $view;
×
136
                }else{
137
            return redirect('/login');
×
138
        }
139
        }
140

141

142
        public function printout2()
×
143
        {
144
                if (Auth::check()) {
×
145
                        $uid = Auth::user()->id;
×
146
                        $profile = Profile::where('userid', '=', $uid)->first();
×
147
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
148
                        $view = View::make('citizen.themes.printout2');
×
149
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
150
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
151
                        
152
                        if ($civic_wallet) {
×
153
                                $view->public_address = $civic_wallet['public_addr'];
×
154
                        } else {
155
                                $view->balance = 0;
×
156
                                $view->public_address = "";
×
157
                        }
158
                        return $view;
×
159
                }else{
160
            return redirect('/login');
×
161
        }
162
        }
163

164

165

166
        public function printout3()
×
167
        {
168
                if (Auth::check()) {
×
169
                        $uid = Auth::user()->id;
×
170
                        $profile = Profile::where('userid', '=', $uid)->first();
×
171
                        $civic_wallet = CivicWallet::where('user_id', '=', $uid)->first();
×
172
                        $view = View::make('citizen.themes.printout3');
×
173
                        $citcache = Citizen::where('userid', '=', $uid)->first();
×
174
                        $view->fullname = $citcache->firstname . " " . $citcache->lastname;
×
175
                        
176
                        if ($civic_wallet) {
×
177
                                $view->public_address = $civic_wallet['public_addr'];
×
178
                        } else {
179
                                $view->balance = 0;
×
180
                                $view->public_address = "";
×
181
                        }
182
                        return $view;
×
183
                }else{
184
            return redirect('/login');
×
185
        }
186
        }
187

188

189

190

191
        //Get profile view of another Martian Citizen
192
        //
193
    public function showId($address)
×
194
        {
195
                
196
                if (Auth::check()) {
×
197
                        $uid = Auth::user()->id;
×
198
                        //Martian user we are looking at
199
                        $martian = Citizen::where('public_address', '=', $address)->first();
×
NEW
200
                        if (!$martian) {
×
NEW
201
                                abort(404, 'Citizen not found');
×
202
                        }
203
                        $martian_profile = Profile::where('userid', '=', $martian->userid)->first();
×
204
                        $martian_proposals = Proposals::where('user_id', '=', $martian->userid)->count();
×
205
                        $myprofile = Profile::where('userid', '=', $uid)->first();
×
206

207
                        if (!$myprofile) {
×
208
                                return redirect('/twofa');
×
209
                        } else {
210
                                if ($myprofile->openchallenge == 1 || is_null($myprofile->openchallenge)) {
×
211
                                        return redirect('/twofachallenge');
×
212
                                }
213
                        }
214
                        $view = View::make('citizen.martian');
×
215
                        $view->wallet_open = $myprofile->civic_wallet_open;
×
216

217

218
                        $view->isCitizen = $martian_profile->citizen;
×
219
                        $view->endorsements = $martian_profile->endorse_cnt;
×
220
                        $view->proposals = $martian_proposals;
×
221
                        $view->isGP  = $martian_profile->general_public;
×
222
                        $view->mePublic = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "GP")->first();
×
223
                        $view->meCitizen = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "CT")->first();
×
224
                        $view->endorsed = Feed::where('userid', '=', $martian->userid)->where('tag', '=', "ED")->count();
×
225

226

227
                        $view->citcache = $martian;
×
228

229
                        return $view;
×
230

231

232
                }else{
233
            return redirect('/login');
×
234
        }
235

236
                
237
        }
238

239

240

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