示例#1
0
 public static function boot()
 {
     parent::boot();
     // Attach event handler, on deleting of the user
     User::deleting(function ($user) {
         // for each post that the user has modified set the modified by user to null
         foreach ($user->modifiedPosts as $modifiedPost) {
             $modifiedPost->update_user_id = null;
             $modifiedPost->update();
         }
         /*
                     to keep a cascading delete when using softDeletes we must remove the related models here
         */
         $children = ['comments', 'sections', 'views', 'messages', 'sentMessages', 'activity', 'givenComments'];
         Log::info("Deleting User {$user->username} - {$user->id}");
         foreach ($children as $child) {
             if ($user->{$child}()) {
                 // we need to call delete on the grandchilden to
                 // trigger their delete() events - seems dumb
                 if (get_class($user->{$child}) === 'Illuminate\\Database\\Eloquent\\Collection') {
                     foreach ($user->{$child} as $grandchild) {
                         Log::info(" - removing grandchildren of user->{$child}");
                         $grandchild->delete();
                     }
                 } else {
                     Log::info(" - removing user->{$child}");
                     $user->{$child}->delete();
                 }
             }
         }
     });
 }
 /**
  * A basic test example.
  *
  * @return void
  */
 public function testUserCanClearMentions()
 {
     /* GIVEN that we have
        a logged in user
        a topic in a section
        a post in the topic made by another user
        */
     $faker = \Faker\Factory::create();
     $user = factory(User::class)->create();
     $originalUserID = $user->id;
     $author = factory(User::class)->create();
     $section = factory(Section::class)->create(['parent_id' => null, 'user_id' => $user->id]);
     $topic = factory(Topic::class)->create(['section_id' => $section->id]);
     $post = factory(Post::class)->create(['topic_id' => $topic->id, 'user_id' => $author->id]);
     // the user should not see the clear all mentions link
     $this->actingAs($user)->visit('/section/' . $section->id)->dontSee('Clear All Mentions');
     // WHEN the user is mentioned in the topic by the other user
     // \Nexus\Helpers\MentionHelper::addMention($user, $post);
     $user->addMention($post);
     // reloading the model here because otherwise the related
     $user = User::find($originalUserID);
     // THEN user now sees the 'clear all notifications menu'
     $this->actingAs($user)->visit('/section/' . $section->id)->see('Clear All Mentions');
     // WHEN the user selects the 'clear all notifications menu
     $this->actingAs($user)->press('Clear All Mentions');
     // updating the test's view of $user
     $user = User::find($originalUserID);
     // THEN the user doesn't see the clear all mentions option
     $this->actingAs($user)->visit('/section/' . $section->id)->dontSee('Clear all Mentions');
 }
 public static function makeMentions(\Nexus\Post $post)
 {
     $users = self::identifyMentions($post->text);
     foreach ($users as $username) {
         $user = \Nexus\User::where('username', $username)->first();
         if ($user) {
             $user->addMention($post);
         }
     }
 }
示例#4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // we are assuming that the sysop is always the first user
     $this->info('Creating administrator, default section and first topic...');
     $user = \Nexus\User::first();
     if (!$user) {
         $this->info("Please enter in values for the administrator account. Don't worry You can change this later.");
         $username = $this->ask('Username');
         $email = $this->ask('Email Address');
         $password = $this->ask('Password');
         $administrator = new \Nexus\User();
         $administrator->username = $username;
         $administrator->name = 'Administrator';
         $administrator->email = $email;
         $administrator->password = \Hash::make($password);
         $administrator->administrator = true;
         try {
             $administrator->save();
         } catch (\Exception $e) {
             $this->error('Failed to add administrator ' . $e);
         }
     } else {
         $this->error('There is already a user account');
     }
     $section = \Nexus\Section::first();
     if (!$section) {
         $this->info("Please enter in values for the main menu. Don't worry You can change this later.");
         $title = $this->ask('Title');
         $mainmenu = new \Nexus\Section();
         $mainmenu->title = $title;
         $mainmenu->user_id = $administrator->id;
         try {
             $mainmenu->save();
         } catch (\Exception $e) {
             $this->error('Failed to add main menu ' . $e);
         }
     } else {
         $this->error('There is already a main menu');
     }
     $topic = \Nexus\Topic::first();
     if (!$topic) {
         $this->info("Please enter in values for the first topic. Don't worry You can change this later.");
         $title = $this->ask('Title');
         $firstTopic = new \Nexus\Topic();
         $firstTopic->title = $title;
         $firstTopic->section_id = $mainmenu->id;
         try {
             $firstTopic->save();
         } catch (\Exception $e) {
             $this->error('Failed to add first topic ' . $e);
         }
     } else {
         $this->error('There is already a topic');
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Looking for Duplicates...');
     $users = \Nexus\User::all();
     foreach ($users as $user) {
         $sortedViews = $user->views->sortBy('topic_id');
         $previousView = null;
         foreach ($sortedViews as $view) {
             if ($previousView) {
                 if ($view->topic_id === $previousView->topic_id) {
                     $this->info("Cur\t" . $view);
                     $this->info("Pre\t" . $previousView . "\n");
                     $view->delete();
                     $view = null;
                 }
             }
             $previousView = $view;
         }
     }
 }
示例#6
0
// authentication
if (config('nexus.allow_registrations') == true) {
    Route::get('auth/register', 'Auth\\AuthController@getRegister');
    Route::post('auth/register', 'Auth\\AuthController@postRegister');
}
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Route::post('auth/login', 'Auth\\AuthController@postLogin');
Route::get('auth/logout', 'Auth\\AuthController@getLogout');
// API
Route::get('api/notifications', ['middleware' => 'auth', function () {
    return Auth::user()->notificationCount();
}])->name('api.notificationCount');
Route::post('api/users', function (Request $request) {
    $input = $request->all();
    $username = $input['query'];
    $data = \Nexus\User::select('username')->where('username', "LIKE", "%{$username}%")->orderBy('username', 'asc')->get()->toArray();
    return response()->json($data);
})->name('api.users');
Route::post('api/nxcode', 'Nexus\\PostController@previewPost');
// Interface partials
Route::get('interface/toolbar', ['middleware' => 'auth', function () {
    return response()->view('_toolbar');
}])->name('interface.toolbar');
// Password reset link request routes...
Route::get('password/email', 'Auth\\PasswordController@getEmail');
Route::post('password/email', 'Auth\\PasswordController@postEmail');
// Password reset routes...
Route::get('password/reset/{token}', 'Auth\\PasswordController@getReset');
Route::post('password/reset', 'Auth\\PasswordController@postReset');
// users
Route::resource('users', 'Nexus\\UserController');
示例#7
0
 private function migrateUsers()
 {
     $this->info('Importing Users');
     $errorCount = 0;
     if (!\Nexus\User::first()) {
         $count = \DB::select('select count(user_id) as count from usertable')[0]->count;
         $this->line("Found {$count} users ");
         $bar = $this->output->createProgressBar($count);
         $classicUsers = \DB::table('usertable')->get();
         foreach ($classicUsers as $classicUser) {
             $newUser = new \Nexus\User();
             $newUser->id = $classicUser->user_id;
             $newUser->username = $classicUser->user_name;
             $newUser->popname = $classicUser->user_popname;
             $newUser->about = $classicUser->user_comment;
             $newUser->location = $classicUser->user_town;
             if ($classicUser->user_sysop === 'y') {
                 $newUser->administrator = true;
             } else {
                 $newUser->administrator = false;
             }
             $newUser->totalVisits = $classicUser->user_totalvisits;
             $newUser->totalPosts = $classicUser->user_totaledits;
             $newUser->favouriteMovie = $classicUser->user_film;
             $newUser->favouriteMusic = $classicUser->user_band;
             if ($classicUser->user_hideemail === 'no') {
                 $newUser->private = false;
             } else {
                 $newUser->private = true;
             }
             $newUser->ipaddress = $classicUser->user_ipaddress;
             $lastLogin = \DB::table('whoison')->select('timeon')->where('user_id', $classicUser->user_id)->first();
             if ($lastLogin) {
                 $newUser->latestLogin = $lastLogin->timeon;
             }
             if ($classicUser->user_status === 'Invalid') {
                 $newUser->banned = true;
             }
             // avoid reusing email addresses
             $emailUses = \DB::table('usertable')->select('user_id')->where('user_email', $classicUser->user_email)->get();
             $count = count($emailUses);
             if ($count > 1) {
                 $newUser->email = $classicUser->user_name . '@fakeemail.com';
             } else {
                 $newUser->email = $classicUser->user_email;
             }
             $newUser->password = $classicUser->user_password;
             if ($classicUser->user_realname != "") {
                 $newUser->name = $classicUser->user_realname;
             } else {
                 $newUser->name = "Unknown";
             }
             try {
                 $newUser->save();
             } catch (\Exception $e) {
                 $errorCount++;
                 \Log::error('Nexus:upgrade - Failed to add user ' . $e);
             }
             $bar->advance();
         }
         $bar->finish();
         if ($errorCount) {
             $this->error("\nEncountered {$errorCount} errors. See log for details");
         }
         $this->info("\nUsers Complete\n");
         unset($classicUsers);
     } else {
         $this->error('Upgrade: found existing users - skipping Users');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update($user_name, Requests\User\UpdateRequest $request)
 {
     $user = \Nexus\User::where('username', $user_name)->firstOrFail();
     $input = $request->all();
     if ($input['password'] != '') {
         // to prevent setting password to an empty string https://trello.com/c/y1WAxwfb
         $input['password'] = \Hash::make($input['password']);
     } else {
         unset($input['password']);
     }
     $user->update($input);
     \Nexus\Helpers\FlashHelper::showAlert('Profile Updated!', 'success');
     return redirect('/users/' . $user_name);
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'name' => 'New User']);
 }