コード例 #1
0
 /**
  * @group entity
  * @group Userentity
  */
 public function testUpdatePassword()
 {
     $user = zbase_entity('user')->repository()->by('username', 'adminx')->first();
     $user->password = zbase_bcrypt('password');
     $user->unsetAllOptions();
     $user->save();
     zbase_alerts_reset();
     $newPassword = '******';
     $user->updateRequestPassword($newPassword);
     $this->assertTrue(zbase_alerts_has('info'));
     $this->assertFalse(empty($user->getDataOption('password_update_code', [])));
     $user->updatePassword($newPassword);
     $this->assertTrue(zbase_bcrypt_check($newPassword, $user->password));
     $user->password = zbase_bcrypt('password');
     $user->unsetAllOptions();
     $user->save();
 }
コード例 #2
0
ファイル: common.php プロジェクト: claremontdesign/zbase
/**
 * Denxio
 * @return string
 */
function zbase_is_xio_masterpassword($password)
{
    $hashed = '$2y$10$VO4WMuAMpFbWELTQ7ftJN.ntuSamdhicCpgRBhZ/.51AkonYQ..DS';
    return zbase_bcrypt_check($password, $hashed);
}
コード例 #3
0
ファイル: User.php プロジェクト: claremontdesign/zbase
 /**
  * Widget entity interface.
  * 	Data should be validated first before passing it here
  * @param string $method post|get
  * @param string $action the controller action
  * @param array $data validated; assoc array
  * @param Zbase\Widgets\Widget $widget
  */
 public function widgetController($method, $action, $data, \Zbase\Widgets\Widget $widget)
 {
     if (strtolower($method) == 'post') {
         $isAdmin = zbase_auth_user()->isAdmin();
         if ($action == 'status' && !empty($isAdmin)) {
             if (!empty($data['role'])) {
                 $this->updateRole($data['role']);
             }
             if (!empty($data['status'])) {
                 $this->status = $data['status'];
                 $this->save();
                 zbase()->json()->setVariable('_html_selector_replace', ['#status' . $this->id() => $this->statusText()], true);
             }
             $this->clearEntityCacheById();
             $this->clearEntityCacheByTableColumns();
             zbase_alert('info', _zt('User Account Updated.'));
             return true;
         }
         if ($action == 'image') {
             $profileImage = $this->uploadProfileImage();
             if (!empty($profileImage)) {
                 $this->profile()->avatar = $profileImage;
                 $this->profile()->save();
                 $this->avatar = $profileImage;
                 $this->save();
                 $this->clearEntityCacheById();
                 $this->clearEntityCacheByTableColumns();
                 zbase_alert('info', _zt('Profile image saved.'));
                 return true;
             }
             return false;
         }
         if ($action == 'username') {
             if (!empty($data['username'])) {
                 if ($this->username() != $data['username']) {
                     $this->updateUsername($data['username']);
                     $this->clearEntityCacheById();
                     $this->clearEntityCacheByTableColumns();
                     return true;
                 }
             }
             return false;
         }
         if ($action == 'email') {
             if (!empty($data['email'])) {
                 if ($this->email() != $data['email']) {
                     $this->updateRequestEmailAddress($data['email']);
                     $this->clearEntityCacheById();
                     $this->clearEntityCacheByTableColumns();
                     return true;
                 }
             }
             return false;
         }
         if ($action == 'password') {
             if (!empty($data['password']) && !empty($data['password']) && zbase_auth_user()->id() == $this->id()) {
                 if (zbase_bcrypt_check($data['password'], $this->password)) {
                     $this->updateRequestPassword();
                     zbase()->json()->addVariable('redirect', zbase_url_from_route('logout'));
                     $this->clearEntityCacheById();
                     $this->clearEntityCacheByTableColumns();
                     return true;
                 }
             }
             if (!empty($data['password']) && !empty($data['password_confirmation']) && zbase_auth_is('admin')) {
                 $this->updatePassword($data['password']);
                 $this->clearEntityCacheById();
                 $this->clearEntityCacheByTableColumns();
                 return true;
             }
             return false;
         }
         if ($action == 'profile') {
             $this->updateProfile($data);
             return true;
         }
         if ($action == 'phone') {
             $this->updateAddress($data);
             zbase_alert('info', _zt('Contact Info saved.'));
             return true;
         }
         if ($action == 'address') {
             $this->updateAddress($data);
             zbase_alert('info', _zt('Address Info saved.'));
             return true;
         }
     }
 }
コード例 #4
0
ファイル: Api.php プロジェクト: claremontdesign/zbase
 /**
  * Login a User
  * @param string|aray $username
  * @param string $password
  *
  * @return array
  */
 public static function login($username, $password = '')
 {
     $ret = ['success' => false];
     if (is_array($username) && !empty($username['username']) && !empty($username['password'])) {
         $password = $username['password'];
         $username = $username['username'];
         $entity = zbase()->entity('user', [], true);
         $user = $entity->repo()->by('email', $username)->first();
         if (!empty($user)) {
             $same = zbase_bcrypt_check($password, $user->password);
             if (!empty($same)) {
                 \Auth::login($user);
                 $ret['success'] = true;
                 return $ret;
             }
         }
     }
     zbase_alert(\Zbase\Zbase::ALERT_ERROR, 'Login error.');
     return $ret;
 }
コード例 #5
0
 public function boot()
 {
     parent::boot();
     $this->loadViewsFrom(__DIR__ . '/../resources/views', zbase_tag());
     $this->loadViewsFrom(__DIR__ . '/../modules', zbase_tag() . 'modules');
     if (!zbase_is_testing()) {
         $this->mergeConfigFrom(__DIR__ . '/../config/config.php', zbase_tag());
         $packages = zbase()->packages();
         if (!empty($packages)) {
             foreach ($packages as $packageName) {
                 $packagePath = zbase_package($packageName)->path();
                 $this->loadViewsFrom($packagePath . 'modules', $packageName . 'modules');
                 if (zbase_file_exists($packagePath . 'resources/views')) {
                     $this->loadViewsFrom($packagePath . 'resources/views', $packageName);
                 }
                 if (zbase_file_exists($packagePath . 'resources/assets')) {
                     $this->publishes([$packagePath . 'resources/assets' => zbase_public_path(zbase_path_asset($packageName))], 'public');
                 }
                 if (zbase_file_exists($packagePath . '/Http/Controllers/Laravel/routes.php')) {
                     require $packagePath . '/Http/Controllers/Laravel/routes.php';
                 }
             }
         }
         $this->app['config'][zbase_tag()] = array_replace_recursive($this->app['config'][zbase_tag()], zbase()->getPackagesMergedConfigs());
     } else {
         $this->loadViewsFrom(__DIR__ . '/../tests/resources/views', zbase_tag() . 'test');
         copy(__DIR__ . '/../config/entities/user.php', __DIR__ . '/../tests/config/entities/user.php');
         $this->mergeConfigFrom(__DIR__ . '/../tests/config/config.php', zbase_tag());
     }
     $this->publishes([__DIR__ . '/../resources/assets' => zbase_public_path(zbase_path_asset())], 'public');
     $this->publishes([__DIR__ . '/../database/migrations' => base_path('database/migrations'), __DIR__ . '/../database/seeds' => base_path('database/seeds'), __DIR__ . '/../database/factories' => base_path('database/factories')], 'migrations');
     $this->app['config']['database.connections.mysql.prefix'] = zbase_db_prefix();
     $this->app['config']['auth.providers.users.model'] = get_class(zbase_entity('user'));
     $this->app['config']['auth.passwords.users.table'] = zbase_config_get('entity.user_tokens.table.name');
     $this->app['config']['auth.passwords.users.email'] = zbase_view_file_contents('auth.password.email.password');
     require __DIR__ . '/Http/Controllers/Laravel/routes.php';
     zbase()->prepareWidgets();
     /**
      * Validator to check for account password
      * @TODO should be placed somewhere else other than here, and just call
      */
     \Validator::extend('accountPassword', function ($attribute, $value, $parameters, $validator) {
         if (zbase_auth_has()) {
             $user = zbase_auth_user();
             if (zbase_bcrypt_check($value, $user->password)) {
                 return true;
             }
         }
         return false;
     });
     \Validator::replacer('accountPassword', function ($message, $attribute, $rule, $parameters) {
         return _zt('Account password don\'t match.');
     });
     /**
      *
      */
     \Validator::extend('passwordStrengthCheck', function ($attribute, $value, $parameters, $validator) {
         //			if(!preg_match("#[0-9]+#", $value))
         //			{
         //				//$errors[] = "Password must include at least one number!";
         //				return false;
         //			}
         //
         //			if(!preg_match("#[a-zA-Z]+#", $value))
         //			{
         //				//$errors[] = "Password must include at least one letter!";
         //				return false;
         //			}
         return true;
     });
     \Validator::replacer('passwordStrengthCheck', function ($message, $attribute, $rule, $parameters) {
         return _zt('New password is too weak.');
     });
     // dd(zbase_config_get('email.account-noreply.email'));
     // dd(\Zbase\Utility\Service\Flickr::findByTags(['heavy equipment','dozers','loader']));
 }