/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'active' => 1, 'level' => 3, 'avatar' => 'avatar.png', 'remember_token' => $data['_token']]); if ($user) { $user->roles()->attach(3); event(new SendRegisterationConfirmationEmail($user)); return $user; } else { abort('503'); } }
/** * Confirm a user's email address. * * @param string $token * @return mixed */ public function confirmEmail($id) { $this->middleware('guest'); $user = User::where('id', $id)->firstOrFail(); if (!$user) { session()->put('error', 'your account still not activated .. please check with the administrator'); return redirect()->home(); } $user->active = 1; $user->save(); session()->flash('success', 'You are now confirmed. Please login.'); return redirect()->home(); }
/** * return all books for sepcific user */ public function testGetAllBooksForSpecificUser() { $user = User::find(1)->with('roles'); print_r($user->roles()->name); //die('end of test'); //print_r('now the user is : '. $user->username . 'and user role is : '. $user->roles()->name); // $user = factory(User::class)->create(); // $role = factory(Role::class)->create(['name' => 'admin']); // $user->roles()->attach($role); // $book = factory(Book::class)->create(); // $book->user()->attach($user); // dd($book); }
/** * Shows a message thread * * @param $id * @return mixed */ public function show($id) { $this->getPageTitle('message.show'); try { $thread = $this->thread->findOrFail($id); } catch (ModelNotFoundException $e) { Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.'); return redirect()->action('Backend\\MessagesController@show', $id); } // don't show the current user in list $userId = Auth::user()->id; $usersList = User::whereNotIn('id', $thread->participantsUserIds($userId))->get()->lists('name', 'id'); $thread->markAsRead($userId); return view('backend.modules.messenger.show', compact('thread', 'usersList')); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['name_en' => $data['name_en'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'active' => 1]); }
public function run() { DB::table('role_user')->truncate(); DB::table('permission_role')->truncate(); DB::table('roles')->truncate(); DB::table('permissions')->truncate(); $admin = new Role(); // 1 $admin->name = 'Admin'; $admin->display_name = "Administrator"; $admin->level = 10; $admin->save(); $editor = new Role(); // 2 $editor->name = 'Editor'; $editor->display_name = "Editor"; $editor->level = 5; $editor->save(); $userRole = new Role(); // 3 $userRole->name = 'Author'; $userRole->display_name = "Author"; $userRole->level = 1; $userRole->save(); $user = User::where('email', '=', '*****@*****.**')->first(); //$user->roles()->attach($admin->id); $user1 = User::where('email', '=', '*****@*****.**')->first(); //$user1->attachRole($editor); $user2 = User::where('email', '=', '*****@*****.**')->first(); //$user2->attachRole($userRole); /*$manageRoles = new Permission(); $manageRoles->name = 'Users'; $manageRoles->display_name = "Users Managment"; $manageRoles->description = ""; //$manageRoles->route = "roles"; $manageRoles->save(); $createRoles = new Permission(); $createRoles->name = 'Roles'; $createRoles->display_name = "Create roles"; $createRoles->description = ""; //$createRoles->route = "roles/create"; $createRoles->save();*/ $permissions = ['Users', 'Roles', 'Permissions', 'Books', 'Chapters', 'Comments', 'Messages', 'Contactus', 'Categories', 'Blogs', 'Galleries', 'Ads', 'Slider', 'Conditions', 'Newsletter', 'user_create', 'user_edit', 'user_change', 'user_delete', 'role_create', 'role_edit', 'role_change', 'role_delete', 'permission_create', 'permission_edit', 'permission_change', 'permission_delete', 'category_create', 'category_edit', 'book_create', 'book_edit', 'book_delete', 'book_change', 'chapter_create', 'chapter_edit', 'chapter_delete', 'chapter_change', 'preview_create', 'preview_delete', 'message_create', 'message_edit', 'message_delete', 'message_change', 'blog_create', 'blog_edit', 'blog_delete', 'blog_change', 'gallery_create', 'gallery_edit', 'gallery_delete', 'gallery_change', 'ad_create', 'ad_edit', 'ad_delete', 'ad_change', 'slider_create', 'slider_edit', 'condition_edit', 'newsletter_create', 'newsletter_delete']; foreach ($permissions as $permission) { $updateRoles = new Permission(); $updateRoles->name = $permission; $updateRoles->display_name = $permission; $updateRoles->save(); } /*$createUsers = new Permission(); $createUsers->name = 'create_users'; $createUsers->display_name = "Create users"; $createUsers->description = ""; $createUsers->route = "users/create"; $createUsers->save(); $updateUsers = new Permission(); $updateUsers->name = 'update_users'; $updateUsers->display_name = "Update users"; $updateUsers->description = ""; $updateUsers->route = "users/{users}/edit"; $updateUsers->save(); $destroyUsers = new Permission(); $destroyUsers->name = 'delete_users'; $destroyUsers->display_name = "Delete users"; $destroyUsers->description = ""; $destroyUsers->route = "users/{users}"; $destroyUsers->save(); $managePerms = new Permission(); $managePerms->name = 'manage_permissions'; $managePerms->display_name = "Manage permissions"; $managePerms->description = ""; $managePerms->route = "permissions"; $managePerms->save(); $createPerms = new Permission(); $createPerms->name = 'create_permissions'; $createPerms->display_name = "Create permissions"; $createPerms->description = ""; $createPerms->route = "permissions/create"; $createPerms->save(); $updatePerms = new Permission(); $updatePerms->name = 'update_permissions'; $updatePerms->display_name = "Update permissions"; $updatePerms->description = ""; $updatePerms->route = "permissions/{permissions}/edit"; $updatePerms->save(); $destroyPerms = new Permission(); $destroyPerms->name = 'delete_permissions'; $destroyPerms->display_name = "Delete permissions"; $destroyPerms->description = ""; $destroyPerms->route = "permissions/{permissions}"; $destroyPerms->save(); $admin->attachPermissions([$manageRoles, $createRoles, $updateRoles, $destroyRoles, $manageUsers, $createUsers, $updateUsers, $destroyUsers, $managePerms, $createPerms, $updatePerms, $destroyPerms]); //$admin->perms()->sync([$manageRoles->id, $manageUsers->id, $managePerms->id]); Eloquent basic $editor->attachPermissions([$managePerms, $createPerms, $updatePerms, $destroyPerms]);*/ }
public function run() { DB::table('role_user')->truncate(); DB::table('permission_role')->truncate(); DB::table('roles')->truncate(); DB::table('permissions')->truncate(); $admin = new Role(); // 1 $admin->name = 'admin'; $admin->display_name = "Administrator"; $admin->level = 10; $admin->save(); $editor = new Role(); // 2 $editor->name = 'editor'; $editor->display_name = "Editor"; $editor->level = 5; $editor->save(); $userRole = new Role(); // 3 $userRole->name = 'user'; $userRole->display_name = "User"; $userRole->level = 1; $userRole->save(); $user = User::where('email', '=', '*****@*****.**')->first(); $user->attachRole($admin); //$user->roles()->attach($admin->id); Eloquent basic $user1 = User::where('email', '=', '*****@*****.**')->first(); $user1->attachRole($editor); $user2 = User::where('email', '=', '*****@*****.**')->first(); $user2->attachRole($userRole); $manageRoles = new Permission(); $manageRoles->name = 'manage_roles'; $manageRoles->display_name = "Manage roles"; $manageRoles->description = ""; $manageRoles->route = "roles"; $manageRoles->save(); $createRoles = new Permission(); $createRoles->name = 'create_roles'; $createRoles->display_name = "Create roles"; $createRoles->description = ""; $createRoles->route = "roles/create"; $createRoles->save(); $updateRoles = new Permission(); $updateRoles->name = 'update_roles'; $updateRoles->display_name = "Update roles"; $updateRoles->description = ""; $updateRoles->route = "roles/{roles}/edit"; $updateRoles->save(); $destroyRoles = new Permission(); $destroyRoles->name = 'delete_roles'; $destroyRoles->display_name = "Delete roles"; $destroyRoles->description = ""; $destroyRoles->route = "roles/{roles}"; $destroyRoles->save(); $manageUsers = new Permission(); $manageUsers->name = 'manage_users'; $manageUsers->display_name = "Manager users"; $manageUsers->description = ""; $manageUsers->route = "users"; $manageUsers->save(); $createUsers = new Permission(); $createUsers->name = 'create_users'; $createUsers->display_name = "Create users"; $createUsers->description = ""; $createUsers->route = "users/create"; $createUsers->save(); $updateUsers = new Permission(); $updateUsers->name = 'update_users'; $updateUsers->display_name = "Update users"; $updateUsers->description = ""; $updateUsers->route = "users/{users}/edit"; $updateUsers->save(); $destroyUsers = new Permission(); $destroyUsers->name = 'delete_users'; $destroyUsers->display_name = "Delete users"; $destroyUsers->description = ""; $destroyUsers->route = "users/{users}"; $destroyUsers->save(); $managePerms = new Permission(); $managePerms->name = 'manage_permissions'; $managePerms->display_name = "Manage permissions"; $managePerms->description = ""; $managePerms->route = "permissions"; $managePerms->save(); $createPerms = new Permission(); $createPerms->name = 'create_permissions'; $createPerms->display_name = "Create permissions"; $createPerms->description = ""; $createPerms->route = "permissions/create"; $createPerms->save(); $updatePerms = new Permission(); $updatePerms->name = 'update_permissions'; $updatePerms->display_name = "Update permissions"; $updatePerms->description = ""; $updatePerms->route = "permissions/{permissions}/edit"; $updatePerms->save(); $destroyPerms = new Permission(); $destroyPerms->name = 'delete_permissions'; $destroyPerms->display_name = "Delete permissions"; $destroyPerms->description = ""; $destroyPerms->route = "permissions/{permissions}"; $destroyPerms->save(); $admin->attachPermissions([$manageRoles, $createRoles, $updateRoles, $destroyRoles, $manageUsers, $createUsers, $updateUsers, $destroyUsers, $managePerms, $createPerms, $updatePerms, $destroyPerms]); //$admin->perms()->sync([$manageRoles->id, $manageUsers->id, $managePerms->id]); Eloquent basic $editor->attachPermissions([$managePerms, $createPerms, $updatePerms, $destroyPerms]); }
<?php /* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(App\Src\User\User::class, function (Faker\Generator $faker) { return ['name' => $faker->name, 'email' => $faker->email, 'role' => $faker->randomElement(['admin', 'user']), 'password' => Hash::make('admin'), 'remember_token' => str_random(10)]; }); $factory->define(App\Src\Invoice\Invoice::class, function (Faker\Generator $faker) { return ['user_id' => \App\Src\User\User::all()->random()->id, 'ref' => $faker->randomDigit(1, 50) . '-' . date('m-Y'), 'from' => $faker->name, 'to' => $faker->name, 'project' => $faker->word(6), 'po' => $faker->numberBetween(0, 30), 'project_date' => $faker->dateTimeThisYear(), 'project_manager' => $faker->name, 'payment_method' => $faker->randomElement(['cheque', 'transfer']), 'due_date' => $faker->dateTimethisYear(), 'total_no' => $faker->numberBetween(10, 200), 'total_words' => $faker->word(5), 'due_now' => $faker->dateTimeThisYear(), 'notes' => $faker->paragraph(2), 'signed_by' => $faker->name]; }); $factory->define(App\Src\Quotation\Quotation::class, function (Faker\Generator $faker) { return ['user_id' => \App\Src\User\User::all()->random()->id, 'ref' => $faker->randomDigit(1, 50) . '-' . date('m-Y'), 'attention' => $faker->name, 'client' => $faker->name, 'project' => $faker->word(3), 'body' => $faker->paragraph(2), 'price' => $faker->numberBetween(10, 200), 'email' => $faker->email]; });
public function handleProviderGoogleCallback() { $userSocilite = Socialite::with('google')->user(); $data = ['name' => $userSocilite->name, 'email' => $userSocilite->email, 'password' => $userSocilite->token]; $user = User::where('email', '=', $userSocilite->email)->first(); if ($user) { Auth::login($user); return redirect('home')->with(['success', trans('messages.success.login')]); } else { if ($this->create($data)) { $user->roles()->attach(3); $user = User::where('email', '=', $userSocilite->email)->first(); Auth::login($user, true); return redirect('home')->with(['success', trans('messages.success.login')]); } return redirect('home')->with(['error', trans('messages.error.login')]); } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'role' => 'user']); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); $this->dispatch(new AssignAdminRoleForNewUserByDefault($user->id)); return $user; }