예제 #1
0
 public function run()
 {
     $admin_access_permission = Permission::create(['name' => 'access-admin', 'display_name' => 'Access admin', 'description' => 'Access admin pages']);
     $owner_role = Role::create(array('name' => 'owner', 'display_name' => 'Owner', 'description' => 'Owner of the system', 'status' => Role::STATUS_HIDDEN));
     $owner_role->attachPermission($admin_access_permission);
     $admin_role = Role::create(array('name' => 'admin', 'display_name' => 'Administrator', 'description' => 'Manage operation of the system and important modules'));
     $admin_role->attachPermission($admin_access_permission);
     $tester_role = Role::create(array('name' => 'tester', 'display_name' => 'Tester', 'description' => 'Tester of the system', 'status' => Role::STATUS_HIDDEN));
     $tester_role->attachPermission($admin_access_permission);
     $user_role = Role::create(array('name' => 'user', 'display_name' => 'User', 'description' => 'Normal user'));
     // TODO: Add 1 administrator
     $owner = User::create(array('display_name' => 'Owner', 'name' => 'owner', 'email' => '*****@*****.**', 'password' => bcrypt(')^KM$bB-W7:Z@8eG'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true));
     $owner->attachRole($owner_role);
     $admin = User::create(array('display_name' => 'Administrator', 'name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true));
     $admin->attachRoles([$admin_role, $owner_role]);
     $tester = User::create(array('display_name' => 'Tester', 'name' => 'tester', 'email' => '*****@*****.**', 'password' => bcrypt('123456'), 'url_avatar' => appDefaultUserProfilePicture(), 'url_avatar_thumb' => appDefaultUserProfilePicture(), 'activation_code' => str_random(32), 'active' => true));
     $tester->attachRole($tester_role);
     $locales = ['en', 'vi'];
     $category = new Category();
     $category->type = Category::LINK;
     $data = ['en' => ['name' => 'Example link category', 'slug' => 'example-link-category', 'description' => 'Example link category'], 'vi' => ['name' => 'Chuyên mục liên kết ví dụ', 'slug' => 'chuyen-muc-lien-ket-vi-du', 'description' => 'Chuyên mục liên kết ví dụ']];
     foreach ($locales as $locale) {
         $transData = $data[$locale];
         $trans = $category->translateOrNew($locale);
         $trans->name = $transData['name'];
         $trans->slug = $transData['slug'];
         $trans->description = $transData['description'];
     }
     $category->save();
     $data = [['en' => ['name' => 'Author on Facebook', 'url' => 'https://www.facebook.com/linhntaim', 'description' => 'Author on Facebook'], 'vi' => ['name' => 'Hồ sơ tác giả trên Facebook', 'url' => 'https://www.facebook.com/linhntaim', 'description' => 'Hồ sơ tác giả trên Facebook']], ['en' => ['name' => 'Author\'s Personal Site', 'url' => 'http://linhntaim.com', 'description' => 'Author\'s Personal Site'], 'vi' => ['name' => 'Trang cá nhân của tác giả', 'url' => 'http://linhntaim.com', 'description' => 'Trang cá nhân của tác giả']], ['en' => ['name' => 'Katniss on Github', 'url' => 'https://github.com/linhntaim/katniss', 'description' => 'Katniss on Github'], 'vi' => ['name' => 'Katniss trên Github', 'url' => 'https://github.com/linhntaim/katniss', 'description' => 'Katniss trên Github']]];
     foreach ($data as $item) {
         $link = new Link();
         foreach ($locales as $locale) {
             $transData = $item[$locale];
             $trans = $link->translateOrNew($locale);
             $trans->name = $transData['name'];
             $trans->description = $transData['description'];
             $trans->url = $transData['url'];
         }
         $link->save();
         $link->categories()->attach($category->id);
     }
     ThemeWidget::create(['widget_name' => 'base_links', 'theme_name' => '', 'placeholder' => 'default_placeholder', 'constructing_data' => '{"category_id":"' . $category->id . '","en":{"name":"Widget named Base Links","description":""},"vi":{"name":"Ví dụ về Công cụ hiển thị Base Links","description":""}}', 'active' => true, 'order' => 1]);
     ThemeWidget::create(['widget_name' => 'extra_html', 'theme_name' => '', 'placeholder' => 'default_placeholder', 'constructing_data' => '{"en":{"name":"Widget named Extra HTML","description":"","content":"<p><strong>Lorem Ipsum<\\/strong><sup>&reg;<\\/sup> is simply dummy text of the <em>printing and typesetting industry<\\/em>. <span style=\\"color:#FFFF00\\"><span style=\\"background-color:#000000\\">Lorem Ipsum<\\/span><\\/span> has been the industry&#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <span style=\\"font-size:16px\\">Aldus PageMaker <\\/span>including versions of <em><strong><u>Lorem Ipsum<\\/u><\\/strong><\\/em>. <img alt=\\"smiley\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/assets\\/libraries\\/ckeditor-4.5.5\\/plugins\\/smiley\\/images\\/regular_smile.png\\" style=\\"height:23px; width:23px\\" title=\\"smiley\\"><\\/p>\\r\\n\\r\\n<p><img alt=\\"\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/files\\/user_2\\/katniss.png\\" style=\\"height:120px; width:120px\\"><\\/p>\\r\\n"},"vi":{"name":"V\\u00ed d\\u1ee5 v\\u1ec1 C\\u00f4ng c\\u1ee5 hi\\u1ec3n th\\u1ecb Extra HTML","description":"","content":"<p><strong>Lorem Ipsum<\\/strong><sup>&reg;<\\/sup> is simply dummy text of the <em>printing and typesetting industry<\\/em>. <span style=\\"color:#FFFF00\\"><span style=\\"background-color:#000000\\">Lorem Ipsum<\\/span><\\/span> has been the industry&#39;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like <span style=\\"font-size:16px\\">Aldus PageMaker <\\/span>including versions of <em><strong><u>Lorem Ipsum<\\/u><\\/strong><\\/em>. <img alt=\\"smiley\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/assets\\/libraries\\/ckeditor-4.5.5\\/plugins\\/smiley\\/images\\/regular_smile.png\\" style=\\"height:23px; width:23px\\" title=\\"smiley\\"><\\/p>\\r\\n\\r\\n<p><img alt=\\"\\" src=\\"http:\\/\\/katniss.linhntaim.com\\/files\\/user_2\\/katniss.png\\" style=\\"height:120px; width:120px\\"><\\/p>\\r\\n"}}', 'active' => true, 'order' => 2]);
 }
예제 #2
0
 public function getActivation($id, $activation_code)
 {
     // if user has logged in but has the id not equals $id, the activation will not process
     // due to the middleware 'guest' applied to this controller in the constructor
     $user = User::findOrFail($id);
     $active = $user->activation_code == $activation_code;
     if ($active) {
         $user->active = true;
         $user->save();
     }
     $this->theme->title(trans('pages.account_activate_title'));
     $this->theme->description(trans('pages.account_activate_title'));
     return view($this->themePage('auth.activate'), ['active' => $active, 'url' => $this->is_auth ? redirectUrlAfterLogin($this->auth_user) : homeUrl('auth/login')]);
 }
예제 #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     $user = User::findOrFail($id);
     $redirect_url = adminUrl('users');
     $rdr = $request->session()->pull(AppConfig::KEY_REDIRECT_URL, '');
     if (!empty($rdr)) {
         $redirect_url = $rdr;
     }
     if ($user->hasRole('owner')) {
         return redirect($redirect_url)->withErrors([trans('error._cannot_delete', ['reason' => trans('error.is_role_owner')])]);
     }
     return $user->delete() === true ? redirect($redirect_url) : redirect($redirect_url)->withErrors([trans('error.database_delete')]);
 }
예제 #4
0
function redirectUrlAfterLogin(User $user)
{
    $localeCode = $user->settings->locale;
    $redirect_url = homeUrl();
    $overwrite_url = session()->pull(AppConfig::KEY_REDIRECT_URL);
    if (!empty($overwrite_url)) {
        $redirect_url = $overwrite_url;
    } elseif ($user->can('access-admin')) {
        $redirect_url = adminUrl(null, [], $localeCode);
    }
    return $redirect_url;
}