Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Add default admin user
     if (!User::exists()) {
         User::create(['name' => 'DF Admin', 'email' => 'dfadmin@' . gethostname() . '.com', 'password' => 'Dream123!', 'is_sys_admin' => true, 'is_active' => true]);
         $this->command->info('Admin user seeded!');
     }
 }
Exemplo n.º 2
0
 public function testSysAdmin()
 {
     $user = \DreamFactory\Core\Models\User::find(1);
     Session::setUserInfoWithJWT($user);
     $permission = Session::getServicePermissions('system', '*');
     $this->assertEquals($permission, VerbsMask::NONE_MASK | VerbsMask::GET_MASK | VerbsMask::POST_MASK | VerbsMask::PUT_MASK | VerbsMask::PATCH_MASK | VerbsMask::DELETE_MASK);
     $nonAdminUser = \DreamFactory\Core\Models\User::create(['name' => 'John Doe', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => 'test1234', 'security_question' => 'Make of your first car?', 'security_answer' => 'mazda', 'is_active' => true]);
     Session::setUserInfoWithJWT($nonAdminUser);
     $permission = Session::getServicePermissions('system', '*');
     $this->assertEquals(VerbsMask::NONE_MASK, $permission);
 }
Exemplo n.º 3
0
 /**
  * Creates a non-admin user.
  *
  * @param array $data
  *
  * @return \DreamFactory\Core\Models\User
  * @throws \DreamFactory\Core\Exceptions\ForbiddenException
  * @throws \DreamFactory\Core\Exceptions\InternalServerErrorException
  * @throws \Exception
  */
 public function create(array $data)
 {
     $userService = Service::getCachedByName('user');
     if (!$userService['config']['allow_open_registration']) {
         throw new ForbiddenException('Open Registration is not enabled.');
     }
     $openRegEmailSvcId = $userService['config']['open_reg_email_service_id'];
     $openRegEmailTplId = $userService['config']['open_reg_email_template_id'];
     $openRegRoleId = $userService['config']['open_reg_role_id'];
     /** @type User $user */
     $user = User::create($data);
     if (!empty($openRegEmailSvcId)) {
         $this->sendConfirmation($user, $openRegEmailSvcId, $openRegEmailTplId);
     } else {
         if (!empty($data['password'])) {
             $user->password = $data['password'];
             $user->save();
         }
     }
     if (!empty($openRegRoleId)) {
         User::applyDefaultUserAppRole($user, $openRegRoleId);
     }
     return $user;
 }
Exemplo n.º 4
0
 /**
  * If does not exists, creates a shadow LDap user using user info provided
  * by the Ldap service provider and assigns default role to this user
  * for all apps in the system. If user already exists then updates user's
  * role for all apps and returns it.
  *
  * @param LdapUserContract $ldapUser
  *
  * @return User
  * @throws \Exception
  */
 public function createShadowADLdapUser(LdapUserContract $ldapUser)
 {
     $email = $ldapUser->getEmail();
     $serviceName = $this->getName();
     if (empty($email)) {
         $uid = $ldapUser->getUid();
         if (empty($uid)) {
             $uid = str_replace(' ', '', $ldapUser->getName());
         }
         $domain = $ldapUser->getDomain();
         $email = $uid . '+' . $serviceName . '@' . $domain;
     } else {
         list($emailId, $domain) = explode('@', $email);
         $email = $emailId . '+' . $serviceName . '@' . $domain;
     }
     $user = User::whereEmail($email)->first();
     if (empty($user)) {
         $data = ['name' => $ldapUser->getName(), 'first_name' => $ldapUser->getFirstName(), 'last_name' => $ldapUser->getLastName(), 'email' => $email, 'is_active' => true, 'adldap' => $this->getProviderName(), 'password' => $ldapUser->getPassword()];
         $user = User::create($data);
     }
     $defaultRole = $this->getDefaultRole();
     User::applyDefaultUserAppRole($user, $defaultRole);
     return $user;
 }
Exemplo n.º 5
0
 /**
  * If does not exists, creates a shadow OAuth user using user info provided
  * by the OAuth service provider and assigns default role to this user
  * for all apps in the system. If user already exists then updates user's
  * role for all apps and returns it.
  *
  * @param OAuthUserContract $OAuthUser
  *
  * @return User
  * @throws \Exception
  */
 public function createShadowOAuthUser(OAuthUserContract $OAuthUser)
 {
     $fullName = $OAuthUser->getName();
     @(list($firstName, $lastName) = explode(' ', $fullName));
     $email = $OAuthUser->getEmail();
     $serviceName = $this->getName();
     $providerName = $this->getProviderName();
     $accessToken = $OAuthUser->token;
     if (empty($email)) {
         $email = $OAuthUser->getId() . '+' . $serviceName . '@' . $serviceName . '.com';
     } else {
         list($emailId, $domain) = explode('@', $email);
         $email = $emailId . '+' . $serviceName . '@' . $domain;
     }
     $user = User::whereEmail($email)->first();
     if (empty($user)) {
         $data = ['name' => $fullName, 'first_name' => $firstName, 'last_name' => $lastName, 'email' => $email, 'is_active' => true, 'oauth_provider' => $providerName, 'password' => $accessToken];
         $user = User::create($data);
     }
     $defaultRole = $this->getDefaultRole();
     User::applyDefaultUserAppRole($user, $defaultRole);
     return $user;
 }
Exemplo n.º 6
0
 /**
  * This method is used for staging the overall
  * test environment. Which usually covers things like
  * running database migrations and seeders.
  *
  * In order to override and run this method on a child
  * class, you must set the static::$staged property to
  * false in the respective child class.
  */
 public function stage()
 {
     Artisan::call('migrate');
     Artisan::call('db:seed');
     Model::unguard();
     // Add default admin user
     if (!User::exists()) {
         User::create(['name' => 'DF Admin', 'email' => '*****@*****.**', 'password' => 'Dream123!', 'is_sys_admin' => true, 'is_active' => true]);
     }
 }