Example #1
0
 public function show()
 {
     if ($this->params()->name) {
         $this->user = User::where(['name' => $this->params()->name])->first();
     } else {
         $this->user = User::find($this->params()->id);
     }
     if (!$this->user) {
         $this->redirectTo("/404");
     } else {
         if ($this->user->id == current_user()->id) {
             $this->set_title('My profile');
         } else {
             $this->set_title($this->user->name . "'s profile");
         }
     }
     if (current_user()->is_mod_or_higher()) {
         # RP: Missing feature.
         // $this->user_ips = $this->user->user_logs->order('created_at DESC').pluck('ip_addr').uniq
         $this->user_ips = array_unique(UserLog::where(['user_id' => $this->user->id])->order('created_at DESC')->take()->getAttributes('ip_addr'));
     }
     $tag_types = CONFIG()->tag_types;
     foreach (array_keys($tag_types) as $k) {
         if (!preg_match('/^[A-Z]/', $k) || $k == 'General' || $k == 'Faults') {
             unset($tag_types[$k]);
         }
     }
     $this->tag_types = $tag_types;
     $this->respondTo(array('html'));
 }
Example #2
0
 public function log($ip)
 {
     return Rails::cache()->fetch(['type' => 'user_logs', 'id' => $this->id, 'ip' => $ip], ['expires_in' => '10 minutes'], function () use($ip) {
         Rails::cache()->fetch(['type' => 'user_logs', 'id' => 'all'], ['expires_in' => '1 day'], function () {
             # RP: Missing relation method "deleteAll()"
             return UserLog::where('created_at < ?', date('Y-m-d 0:0:0', strtotime('-3 days')))->take()->each('destroy');
         });
         # RP: Missing feature.
         $log_entry = UserLog::where(['ip_addr' => $ip, 'user_id' => $this->id])->firstOrInitialize();
         $log_entry->created_at = date('Y-m-d H:i:s');
         return $log_entry->save();
     });
 }