Example #1
0
 public function postLogin(\Illuminate\Http\Request $request)
 {
     $username = $request->input('username');
     $password = $request->input('password');
     // First try to log in as a local user.
     if (Auth::attempt(array('username' => $username, 'password' => $password))) {
         $this->alert('success', 'You are now logged in.', true);
         return redirect('users/' . Auth::user()->id);
     }
     // Then try with ADLDAP.
     $ldapConfig = \Config::get('adldap');
     if (array_get($ldapConfig, 'domain_controllers', false)) {
         $adldap = new \adldap\adLDAP($ldapConfig);
         if ($adldap->authenticate($username, $password)) {
             // Check that they exist.
             $user = \Ormic\Model\User::where('username', '=', $username)->first();
             if (!$user) {
                 $user = new \Ormic\Model\User();
                 $user->username = $username;
                 $user->save();
             }
             \Auth::login($user);
             //$this->alert('success', 'You are now logged in.', TRUE);
             return redirect('');
             //->with(['You are now logged in.']);
         }
     }
     // If we're still here, authentication has failed.
     return redirect()->back()->withInput($request->only('username'))->withErrors(['Authentication failed.']);
 }
Example #2
0
 public function onCreated(User $user)
 {
     if (User::count() == 1 && !$user->isAdmin()) {
         $attrs = array('name' => 'Administrator');
         $adminRole = Role::where($attrs)->first();
         if (!$adminRole) {
             $adminRole = new Role($attrs);
             $adminRole->setUser($user);
             $adminRole->save();
         }
         $user->roles()->attach($adminRole->id);
     }
     $user->setUser($user);
 }
Example #3
0
 public function postRegister()
 {
     if (Request::input('password') != Request::input('password_confirmation')) {
         throw new \Exception("Passwords do not match.");
     }
     $user = new User();
     $user->username = Request::input('username');
     $user->email = Request::input('email');
     $user->save();
     $password = new \Ormic\Model\UserPassword();
     $password->user_id = $user->id;
     $password->password = Hash::make(Request::input('username'));
     $password->save();
     $this->alert('success', 'Your account has been created.');
     return redirect('users/' . $user->id);
 }
Example #4
0
 /**
  * A convienient way to get a new User object, for whatever tests need it.
  * @return \Ormic\Model\User The 'testuser' user.
  */
 public function getTestUser()
 {
     $user = \Ormic\Model\User::find(1);
     if (!$user) {
         $user = new \Ormic\Model\User();
         $user->name = 'Test User';
         $user->username = '******';
         $user->email = '*****@*****.**';
         $user->save();
     }
     return $user;
 }
Example #5
0
 /**
  * @testdox The first user to log in is made an Administrator, and can edit users' roles.
  */
 public function firstUser()
 {
     // Start with 0 users.
     $this->assertEquals(0, User::count());
     // Save a first user, and they should be made an admin.
     $user1 = new User();
     $user1->username = '******';
     $user1->save();
     $this->assertTrue($user1->hasRole('Administrator'));
     $this->assertTrue($user1->isAdmin());
     $this->assertEquals(1, User::count());
     // Check that resaving the first user doesn't break this (like it was doing).
     $user1->username = '******';
     $user1->save();
     $this->assertTrue($user1->isAdmin());
     $this->assertEquals(1, User::count());
     // Save a second user, and they shouldn't be an admin.
     $user2 = new User();
     $user2->username = '******';
     $user2->save();
     $this->assertFalse($user2->hasRole('Administrator'));
     $this->assertFalse($user2->isAdmin());
     $this->assertTrue($user1->isAdmin());
     $this->assertEquals(2, User::count());
 }