Esempio n. 1
0
 /**
  * Handle a login request to the application.
  * Requires $this->usernameField, password, remember request fields.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function login(Request $request)
 {
     $this->validate($request, [$this->usernameField => 'required', 'password' => 'required']);
     // Check whether this controller is using ThrottlesLogins trait
     $throttles = in_array(ThrottlesLogins::class, class_uses_recursive(get_class($this)));
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->sendLockoutResponse($request);
     }
     $credentials = $request->only($this->usernameField, 'password');
     // Try to authenticate using username or NIM
     if (Auth::attempt(['username' => $request[$this->usernameField], 'password' => $request['password']], $request->has('remember')) || Auth::attempt(['nim' => $request[$this->usernameField], 'password' => $request['password']], $request->has('remember'))) {
         // Authentication successful
         if ($throttles) {
             $this->clearLoginAttempts($request);
         }
         return redirect()->intended($this->redirectLogin);
     }
     // If the login attempt was unsuccessful we will increment the number of attempts
     // to login and redirect the user back to the login form. Of course, when this
     // user surpasses their maximum number of attempts they will get locked out.
     if ($throttles) {
         $this->incrementLoginAttempts($request);
     }
     $failedLoginMessage = Lang::has('auth.failed') ? Lang::get('auth.failed') : 'These credentials do not match our records.';
     return redirect()->back()->withInput($request->only($this->usernameField, 'remember'))->withErrors([$this->usernameField => $failedLoginMessage]);
 }
Esempio n. 2
0
 /**
  * Return a modules.
  *
  * @return \Illuminate\Support\Collection
  */
 public function get(Module $module)
 {
     $moduleName = $module->getName();
     if (Lang::has("{$moduleName}::module.title")) {
         $module->localname = Lang::get("{$moduleName}::module.title");
     } else {
         $module->localname = $module->getStudlyName();
     }
     if (Lang::has("{$moduleName}::module.description")) {
         $module->description = Lang::get("{$moduleName}::module.description");
     }
     $package = $this->packageVersion->getPackageInfo("societycms/module-{$moduleName}");
     if (isset($package->name) && strpos($package->name, '/')) {
         $module->vendor = explode('/', $package->name)[0];
     }
     $module->version = isset($package->version) ? $package->version : 'N/A';
     $module->versionUrl = '#';
     $module->isCore = $this->isCoreModule($module);
     if (isset($package->source->url)) {
         $packageUrl = str_replace('.git', '', $package->source->url);
         $module->versionUrl = $packageUrl . '/tree/' . $package->dist->reference;
     }
     $module->license = $package->license;
     return $module;
 }
Esempio n. 3
0
 /**
  * Get a string from language file.
  *
  * @param  string  $string
  * @param  string  $default
  * @param  array   $parameters
  * @return mixed
  */
 function t($string, $default = null, $parameters = [])
 {
     if (Lang::has($string)) {
         return Lang::get($string, $parameters);
     }
     return $default;
 }
Esempio n. 4
0
 public function testDefaultPlaceholderTextsAreDefined()
 {
     $types = ['asset', 'location', 'link', 'text', 'html', 'feature', 'library', 'linkset', 'slideshow', 'timestamp'];
     foreach ($types as $type) {
         $langKey = "boomcms::chunks.{$type}.default";
         $this->assertTrue(Lang::has($langKey), $type);
     }
 }
Esempio n. 5
0
 public function has($message, $package = '')
 {
     $found = Lang::has($message);
     if ($package != '') {
         $found = $found || Lang::has($package . '::' . $message);
     }
     return $found || Lang::has('translation::' . $message);
 }
Esempio n. 6
0
 /**
  *  Funtion to set ObjectTrans variable
  *
  * @access  public
  * @param   array   $parameters
  * @param   string  $objectTrans
  * @return  string
  */
 public static function getObjectTransValue($parameters, $objectTrans)
 {
     if (Lang::has($parameters['package'] . '::pulsar.' . $objectTrans)) {
         return $parameters['package'] . '::pulsar.' . $objectTrans;
     } elseif (Lang::has('pulsar::pulsar.' . $objectTrans)) {
         return 'pulsar::pulsar.' . $objectTrans;
     }
 }
Esempio n. 7
0
 /**
  * Evalutes column name
  *
  * @param $key
  * @return mixed
  */
 public function key($key)
 {
     if (Lang::has('strings.' . $key)) {
         return Lang::get('strings.' . $key);
     } else {
         return $key;
     }
 }
Esempio n. 8
0
 public function has($key, $locale = null)
 {
     if (Lang::has($this->namespaced($key, true), $locale)) {
         return true;
     } else {
         return Lang::has($this->namespaced($key), $locale);
     }
 }
Esempio n. 9
0
 public static function options()
 {
     $options = [];
     foreach (Config::get('boomcms.settingsManagerOptions') as $name => $type) {
         $langPrefix = "boomcms::settings-manager.{$name}.";
         $options[] = ['name' => $name, 'label' => Lang::get("{$langPrefix}_label"), 'type' => $type, 'value' => Settings::get($name), 'info' => Lang::has("{$langPrefix}_info") ? Lang::get("{$langPrefix}_info") : ''];
     }
     usort($options, function ($a, $b) {
         return $a['label'] < $b['label'] ? -1 : 1;
     });
     return $options;
 }
Esempio n. 10
0
 /**
  * Create localizated Route
  * 
  * @param string $name [ get, post, put, delete, patch ]
  * @param array $args
  * @return \Illuminate\Routing\Router
  */
 public function __call($name, $args)
 {
     $methods = ['get', 'post', 'put', 'delete', 'patch'];
     if (in_array($name, $methods)) {
         list($uri, $as, $uses, $locale) = $args;
         if (Lang::has($uri)) {
             $uri = Lang::get($uri, [], $locale);
         }
         if ($locale) {
             $as = "{$locale}.{$as}";
         }
         return $this->app['router']->{$name}($uri, ['as' => $as, 'uses' => $uses]);
     }
 }
Esempio n. 11
0
 public function check($controller_suffix = 'Controller')
 {
     $routeAction = Route::currentRouteAction();
     preg_match_all('/([a-z0-9A-Z]+\\\\)?(\\w+)@(\\w+)/', $routeAction, $matchs);
     $controller_full = $matchs[2][0];
     //类名
     $controller = str_replace($controller_suffix, '', $controller_full);
     $action = $matchs[3][0];
     //方法名
     //不需要认证的模块,则放行
     if (isset($this->config['AUTH_LOGIN_NO'][$controller]) && ($this->config['AUTH_LOGIN_NO'][$controller] == '*' || in_array($action, $this->config['AUTH_LOGIN_NO'][$controller]))) {
         return true;
     }
     //没有登陆跳转到登陆页面
     if (!$this->checkLogin()) {
         //todo
         return $this->noLogin();
     }
     $power = $this->getRolePower(Session::get($this->config['AUTH_SESSION_PREFIX'] . 'role_id'));
     //临时的,记得删除-1 todo
     //$power = -1;
     if ($power == -1) {
         return true;
     } else {
         $privilege = Lang::has('privilege') ? Lang::get('privilege') : array();
         $controller = str_replace('Controller', '', $controller);
         if ($privilege) {
             if (isset($privilege[$controller]['power_rule']['module_hidden'])) {
                 if ($privilege[$controller]['power_rule']['module_hidden'] == 0) {
                     if (isset($privilege[$controller][$action])) {
                         if (isset($privilege[$controller]['power_rule'][$action]) && $privilege[$controller]['power_rule'][$action] == 1) {
                             return true;
                         } else {
                             if (isset($power[$controller][$action]) && $power[$controller][$action] == -1) {
                                 return true;
                             }
                         }
                     } else {
                         //没有设置$privilege[$controller][$action]一律通过
                         return true;
                     }
                 } elseif ($privilege[$controller]['power_rule']['module_hidden'] == 1) {
                     return true;
                 }
             }
         }
     }
     return $this->noPower();
 }
Esempio n. 12
0
 /**
  * Get the page navigation by working.
  *
  * @return array
  */
 protected function sendGet()
 {
     $model = $this->model;
     $pages = $model::where('show_nav', '=', true)->get(['nav_title', 'slug', 'icon'])->toArray();
     foreach ($pages as $key => $page) {
         $pages[$key]['slug'] = 'pages/' . $page['slug'];
         if (Lang::has('navigation.' . $page['nav_title'])) {
             $pages[$key]['title'] = trans('navigation.' . $page['nav_title']);
         } else {
             $pages[$key]['title'] = $page['nav_title'];
         }
         unset($pages[$key]['nav_title']);
     }
     return $pages;
 }
 /**
  * Create a list based on localisation
  *
  * @param string $prefix The localization prefix/file
  * @param string $key The key column in the resulting array
  * @param string $value The value column in the resulting array
  * @return Array The array containing the list
  *
  * @author Zaïd Sadhoe <*****@*****.**>
  */
 public static function listTranslated($prefix = '', $key = 'id', $value = 'name')
 {
     $results = self::lists($value, $key);
     foreach ($results as $key => &$value) {
         if (Lang::has($prefix . $key)) {
             $value = Lang::get($prefix . $key);
         } else {
             if (Lang::has($prefix . $value)) {
                 $value = Lang::get($prefix . $value);
             }
         }
     }
     asort($results);
     return $results;
 }
 /**
  * Get a translated string for an error page.
  * Either a specific one if defined or a generic if not.
  *
  * @param       $key
  * @param       $code
  * @param array $options
  *
  * @return string
  */
 public static function getPageText($key, $code, $options = [])
 {
     $cSpecificKey = "pretty-error-page-customized::{$code}.{$key}";
     $cGenericKey = "pretty-error-page-customized::generic.{$key}";
     $specificKey = "pretty-error-page::{$code}.{$key}";
     $genericKey = "pretty-error-page::generic.{$key}";
     if (Lang::has($cSpecificKey)) {
         return Lang::get($cSpecificKey, $options);
     } else {
         if (Lang::has($cGenericKey)) {
             return Lang::get($cGenericKey, $options);
         } else {
             if (Lang::has($specificKey)) {
                 return Lang::get($specificKey, $options);
             }
         }
     }
     return Lang::get($genericKey, $options);
 }
Esempio n. 15
0
 /**
  * Get the login lockout error message.
  *
  * @param  int  $seconds
  * @return string
  */
 protected function getLockoutErrorMessage($seconds)
 {
     return Lang::has('auth.throttle') ? Lang::get('auth.throttle', ['seconds' => $seconds]) : 'Too many login attempts. Account Blocked, an email has been sent to ' . Input::get('email') . " to reset password";
 }
 /**
  * Get the label title for a form field, first by using the provided one
  * or titleizing the field name.
  *
  * @param  string $label
  * @param  string $name
  *
  * @return string
  */
 protected function getLabelTitle($label, $name, $options)
 {
     if (is_null($label) && Lang::has("forms.{$name}")) {
         return Lang::get("forms.{$name}");
     }
     $label = $label ?: Str::title($name);
     if (isset($options['required'])) {
         $label = sprintf('%s %s', $label, $this->getLabelRequiredMark());
     }
     return $label;
 }
Esempio n. 17
0
 protected function getEmailSubject()
 {
     return Lang::has('admin::passwords.subject') ? Lang::get('admin::passwords.subject') : 'Your Password Reset Link';
 }
 /**
  * @return string
  */
 protected function getAccessDeniedMessage()
 {
     return Lang::has('auth.access-denied') ? Lang::get('auth.access-denied') : "You don't have permission to access the requested resource.";
 }
Esempio n. 19
0
 /**
  * Get message from a range of different file/key combinations
  *
  * @param  string $filename
  * @param  string $key
  * @return string
  */
 private function getMessage($filename, $key)
 {
     $messageset = $this->getParameters('messageset');
     // If we have a matching key in messageset it wins
     if (array_get($messageset, $key)) {
         return array_get($messageset, $key);
     }
     $fileKey = $this->languageKey ? $this->languageKey . '.' . $key : $key;
     // We have a couple of options where messages could be retrieved by default,
     // try: Model.php and model.php, as well as Model_Model.php and Model/Model.php
     $messages = [$filename . $fileKey, Str::lower($filename) . $fileKey, str_replace('_', '/', $filename) . $fileKey, Str::lower(str_replace('_', '/', $filename)) . $fileKey];
     // Cycle through messages trying to find one that is valid
     foreach ($messages as $message) {
         if (Lang::has($message)) {
             return Lang::get($message);
         }
     }
     return "";
 }
Esempio n. 20
0
 /**
  * Redirect the user after determining they are locked out.
  *
  * @param  Request  $request
  * @return \Illuminate\Http\RedirectResponse
  */
 protected function sendLockoutResponse(Request $request)
 {
     $seconds = (int) Cache::get($this->getLoginLockExpirationKey($request)) - time();
     $message = Lang::has('passwords.throttle') ? Lang::get('passwords.throttle', ['seconds' => $seconds]) : 'Too many login attempts. Please try again in ' . $seconds . ' seconds.';
     return redirect($this->loginPath())->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $message]);
 }
Esempio n. 21
0
 public static function getDetailInfoGame($gameDetail)
 {
     $game = [];
     if (isset($gameDetail['link'])) {
         foreach ($gameDetail['link'] as $link) {
             $attributes = $link['@attributes'];
             $label = $attributes['value'];
             if (Lang::has('mechanics.' . $attributes['value'])) {
                 $label = trans('mechanics.' . $attributes['value']);
             }
             $game['detail'][$attributes['type']][] = ['value' => $label, 'id' => $attributes['id']];
         }
     }
     if (isset($gameDetail['poll'])) {
         foreach ($gameDetail['poll'] as $poll) {
             if (isset($poll['@attributes']) && $poll['@attributes']['name'] == 'suggested_numplayers') {
                 $game['poll'][$poll['@attributes']['name']]['votes']['num'] = $poll['@attributes']['totalvotes'];
                 if (isset($poll['results'])) {
                     $arrayByPlayers = [];
                     foreach ($poll['results'] as $results) {
                         if (isset($results['@attributes']['numplayers'])) {
                             $key = $results['@attributes']['numplayers'];
                             if (isset($results['result'])) {
                                 foreach ($results['result'] as $typeResult) {
                                     $type = $typeResult['@attributes']['value'];
                                     $numVotes = $typeResult['@attributes']['numvotes'];
                                     $arrayByPlayers[$key][$type] = $numVotes;
                                 }
                             }
                         }
                     }
                     $game['poll'][$poll['@attributes']['name']]['votes']['results'] = $arrayByPlayers;
                 }
                 // Post process best/recommanded
                 $maxBest = $maxRecommended = $bestKey = $recommendedKey = 0;
                 if ($arrayByPlayers) {
                     foreach ($arrayByPlayers as $nbPlayer => $results) {
                         if ($results['Best'] > $maxBest) {
                             $bestKey = $nbPlayer;
                             $maxBest = $results['Best'];
                         }
                         if ($results['Recommended'] > $maxRecommended) {
                             $recommendedKey = $nbPlayer;
                             $maxRecommended = $results['Recommended'];
                         }
                     }
                     $game['poll']['process_suggested_numplayers']['best'] = $bestKey;
                     $game['poll']['process_suggested_numplayers']['recommended'] = $recommendedKey;
                 }
             }
         }
     }
     return $game;
 }
Esempio n. 22
0
 public function getTaxRuleShoppingCart()
 {
     return new TaxRuleShoppingCart(Lang::has($this->translation_104) ? trans($this->translation_104) : $this->name_104, $this->tax_rate_103, $this->priority_104, $this->sort_order_104);
 }
Esempio n. 23
0
 /**
  * Get the failed login message.
  *
  * @param $message
  *
  * @return string
  */
 protected function getFailedLoginMessage($message)
 {
     if (strlen($message) > 0) {
         return $message;
     }
     return Lang::has('auth.failed') ? Lang::get('auth.failed') : 'These credentials do not match our records.';
 }
Esempio n. 24
0
 /**
  * Get the successful login message.
  *
  * @return string
  */
 protected function getSuccessfulLoginMessage()
 {
     return Lang::has('auth.success') ? Lang::get('auth.success') : 'Authentication was successful.';
 }
Esempio n. 25
0
 public function getPlaceholderText()
 {
     if ($this->placeholderText) {
         return $this->placeholderText;
     }
     return Lang::has("boomcms::chunks.{$this->getType()}.{$this->slotname}") ? Lang::get("boomcms::chunks.{$this->getType()}.{$this->slotname}") : Lang::get("boomcms::chunks.{$this->getType()}.default");
 }
/**
 * If using the return method, it will return an array of the variable
 */
function lang($text = false, $vars = null, $value = null, $group = null, $locale = null, $force_add = false)
{
    $original_locale = Lang::getLocale();
    $params['value'] = $value ? $value : 0;
    $params['vars'] = $vars ? $vars : [];
    $params['locale'] = $locale ? $locale : $original_locale;
    $params['group'] = $group ? $group : 'general';
    $params['dynamic'] = false;
    if (preg_match('/dynamic_/', $params['group'])) {
        $params['group'] = preg_replace('/dynamic_/', '', $params['group']);
        $params['dynamic'] = true;
    }
    $hash = md5($text) . sha1($text);
    $file_namespace = 'dbtranslator';
    if (preg_match('/\\|/', $text)) {
        $choose = true;
    } else {
        $choose = false;
    }
    $config = config('db-translator');
    /**
     * Before anything lets change the locale to the intl locale
     */
    App::setLocale($params['locale']);
    /**
     * This will check the existence of the translation on the locale given, not the default
     */
    if (!$force_add) {
        if (Lang::has($file_namespace . '::' . $params['group'] . '.' . $hash)) {
            if ($choose) {
                $text = trans_choice($file_namespace . '::' . $params['group'] . '.' . $hash, $params['value'], $params['vars']);
                App::setLocale($original_locale);
                return $text;
            } else {
                $text = trans($file_namespace . '::' . $params['group'] . '.' . $hash, $params['vars']);
                App::setLocale($original_locale);
                return $text;
            }
        } else {
            /**
             * If we are using the database translations
             */
            if ($config['use_database']) {
                if (!Intl::whereText($text)->whereGroup($params['group'])->get()->count()) {
                    $intl = new Intl();
                    $intl->text = $text;
                    $intl->group = $params['group'];
                    $intl->md5sha1 = $hash;
                    $intl->dynamic = $params['dynamic'];
                    $intl->save();
                }
            } else {
                /**
                 * first we will check if the translation exists under the fallback language
                 */
                App::setLocale($config['default_locale']);
                if (!Lang::has($file_namespace . '::' . $params['group'] . '.' . $hash)) {
                    // if we don't find it, we should include the file for the original locale
                    // change it with the new array, and save it.
                    /**
                     * Determine if the file exists
                     */
                    if (Storage::disk($config['storage_driver'])->exists($config['default_locale'] . '/' . $params['group'] . '.php')) {
                        $lang_array = (require base_path('resources/lang/vendor/dbtranslator/' . $config['default_locale'] . '/' . $params['group'] . '.php'));
                        if (!isset($lang_array[$hash])) {
                            $lang_array[$hash] = $text;
                            $file = "<?php\n        return [\r\n";
                            foreach ($lang_array as $k => $v) {
                                $file .= "    \"" . $k . "\" => \"" . str_replace('"', '\\"', $v) . "\",\r\n";
                            }
                            $file .= "];";
                            Storage::disk($config['storage_driver'])->put($config['default_locale'] . '/' . $params['group'] . '.php', $file);
                        }
                    } else {
                        $file = "<?php\n    return [\r\n";
                        $file .= "    \"" . $hash . "\" => \"" . str_replace('"', '\\"', $text) . "\",\r\n";
                        $file .= "];";
                        Storage::disk($config['storage_driver'])->put($config['default_locale'] . '/' . $params['group'] . '.php', $file);
                    }
                }
                App::setLocale($params['locale']);
            }
            // now we will process the string
            if ($choose) {
                $params['vars']['count'] = $params['value'];
                $ms = new MessageSelector();
                $text = $ms->choose($text, $params['value'], $params['locale']);
                $params['vars'] = (new Collection($params['vars']))->sortBy(function ($value, $key) {
                    return mb_strlen($key) * -1;
                });
                foreach ($params['vars'] as $key => $value) {
                    $text = str_replace(':' . $key, $value, $text);
                }
                App::setLocale($original_locale);
                return $text;
            } else {
                if (count($params['vars'])) {
                    $params['vars'] = (new Collection($params['vars']))->sortBy(function ($value, $key) {
                        return mb_strlen($key) * -1;
                    });
                    foreach ($params['vars'] as $key => $value) {
                        $text = str_replace(':' . $key, $value, $text);
                    }
                }
                App::setLocale($original_locale);
                return $text;
            }
        }
    } else {
        if ($config['use_database']) {
            if (!Intl::whereText($text)->whereGroup($params['group'])->get()->count()) {
                $intl = new Intl();
                $intl->text = $text;
                $intl->group = $params['group'];
                $intl->md5sha1 = $hash;
                $intl->dynamic = $params['dynamic'];
                $intl->save();
            }
        }
    }
}
Esempio n. 27
0
 /**
  * Get the login lockout error message.
  *
  * @param  int  $seconds
  * @return string
  */
 protected function getLockoutErrorMessage($seconds)
 {
     return Lang::has('auth.throttle') ? Lang::get('auth.throttle', ['seconds' => $seconds]) : 'Too many login attempts. Please try again in ' . $seconds . ' seconds.';
 }
Esempio n. 28
0
 /**
  * Get the failed login message.
  *
  * @return string
  */
 protected function getFailedLoginMessage()
 {
     return Lang::has('auth.failed') ? Lang::get('auth.failed') : 'Ces informations d\'identification ne correspondent a aucun compte';
 }
 /**
  * Get the failed login message.
  *
  * @return string
  */
 protected function getFailedLoginMessage()
 {
     return Lang::has('auth.failed') ? Lang::get('auth.failed') : 'These credentials do not match our records.';
 }
Esempio n. 30
0
 /**
  * Get the label title for a form field, first by using the provided one
  * or titleizing the field name.
  *
  * @param  string  $label
  * @param  string  $name
  * @return string
  */
 protected function getLabelTitle($label, $name)
 {
     if (is_null($label) && Lang::has("form.{$name}")) {
         return Lang::get("form.{$name}");
     }
     return $label ?: Str::title($name);
 }