PHP User::attachRole Examples

PHP User::attachRole - 9 examples found. These are the top rated real world PHP examples of User::attachRole extracted from open source projects. You can rate examples to help us improve the quality of examples.
 public function storeUser()
 {
     $validator = Validator::make($data = Input::all(), User::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $user = new User();
     $user->username = $data['username'];
     $user->email = $data['email'];
     $user->password = $data['password'];
     $user->password_confirmation = $data['password_confirmation'];
     if (isset($data['tipe'])) {
         $user->tipe = $data['tipe'];
         $user->nama = $data['nama'];
         $user->alamat = $data['alamat'];
         $user->telp = $data['telp'];
     }
     $user->confirmed = 1;
     $user->save();
     if ($data['role'] == '0') {
         $user->attachRole(Role::find(6));
     } elseif ($data['role'] == '1') {
         $user->attachRole(Role::find(3));
     } elseif ($data['role'] == '2') {
         $user->attachRole(Role::find(4));
         $outlet = new Outlet();
         $outlet->user_id = $user->id;
         $name = 'Outlet ' . $user->username . '';
         $outlet->name = $name;
         $outlet->save();
     }
     return Redirect::to('admin/users')->with('message', 'berhasil menambahkan user');
 }
Example #2
0
 public function run()
 {
     // create default user asset
     $asset = Asset::where('filename', '=', 'default.png')->first();
     if ($asset == NULL) {
         $asset = new Asset();
         $asset->filename = 'default.png';
         $asset->path = 'assets/content/users';
         $asset->save();
     }
     $admin = Role::where('name', '=', 'Admin')->first();
     // create default roles
     if ($admin == NULL) {
         $admin = new Role();
         $admin->name = 'Admin';
         $admin->save();
     }
     $adminUser = User::where('username', '=', 'admin')->first();
     if ($adminUser != NULL) {
         echo "Admin User Already Exsit";
     } else {
         $adminUser = new User();
         $adminUser->username = 'admin';
         $adminUser->email = 'admin@admin.com';
         $adminUser->password = 'admin';
         $adminUser->password_confirmation = 'admin';
         $adminUser->confirmation_code = md5(uniqid(mt_rand(), true));
         if ($adminUser->save()) {
             $adminUser->attachRole($admin);
             echo "Admin User Created";
         }
     }
 }
 public function run()
 {
     $user = new User();
     $user->username = 'jd.hernandez@me.com';
     $user->email = 'jd.hernandez@me.com';
     $user->password = '@Password1';
     $user->password_confirmation = '@Password1';
     $user->confirmed = 1;
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     $user->save();
     $profile = new Profile();
     $profile->user_id = $user->id;
     $profile->firstname = 'David';
     $profile->lastname = 'Hernandez';
     $profile->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile->avatar = '/img/coach-avatar.jpg';
     $profile->save();
     if (!$user->id) {
         Log::info('Unable to create user ' . $user->username, (array) $user->errors());
     } else {
         Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
     }
     $user1 = new User();
     $user1->username = 'david.hernandez@plusconsulting.co';
     $user1->email = 'david.hernandez@plusconsulting.co';
     $user1->password = '@Password1';
     $user1->password_confirmation = '@Password1';
     $user1->confirmed = 1;
     $user1->confirmation_code = md5(uniqid(mt_rand(), true));
     $user1->save();
     $profile1 = new Profile();
     $profile1->user_id = $user1->id;
     $profile1->firstname = 'David';
     $profile1->lastname = 'Hernandez';
     $profile1->mobile = '(916)952-5736';
     $profile->dob = '09/24/1986';
     $profile1->avatar = '/img/coach-avatar.jpg';
     $profile1->save();
     if (!$user1->id) {
         Log::info('Unable to create user ' . $user1->username, (array) $user1->errors());
     } else {
         Log::info('Created user "' . $user1->username . '" <' . $user1->email . '>');
     }
     $admin = new Role();
     $admin->name = 'administrator';
     $admin->save();
     $club = new Role();
     $club->name = 'club owner';
     $club->save();
     $club2 = new Role();
     $club2->name = 'club administrator';
     $club2->save();
     $default = new Role();
     $default->name = 'default';
     $default->save();
     $user->attachRole($club);
     $user1->attachRole($default);
 }
Example #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $user = new User();
     $user->full_name = Input::get('full_name');
     $user->position = Input::get('position');
     $user->code = Input::get('code');
     $user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));
     $user->save();
     $role = Role::where('name', '=', 'user')->get()->first();
     $user->attachRole($role);
     Session::flash('message', 'Usuario Creado con Exito, Puede Ingresar a la App');
     return Redirect::to('/');
 }
Example #5
0
 public function postRegistration()
 {
     $rules = array('firstname' => 'required|min:2', 'email' => 'required|email|unique:users', 'password' => 'required|min:6|max:32');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to("login")->withErrors($validator)->withInput(Input::except(''));
     }
     $password = Input::get('password');
     $table = new User();
     $table->firstname = Input::get('firstname');
     $table->email = Input::get('email');
     $table->password = Hash::make($password);
     if ($table->save()) {
         $role = Role::where('name', '=', 'Customer')->first();
         $table->attachRole($role);
         Mail::send('mail.registration', ['firstname' => $table->firstname, 'login' => $table->email, 'password' => $password, 'setting' => Config::get('setting')], function ($message) {
             $message->to(Input::get('email'))->subject("Регистрация прошла успешно");
         });
         return Redirect::to(asset('page/spasibo-za-registratsiyu'))->with('success', trans("message.success"));
     }
     return Redirect::to("login")->with('error', trans('message.error'));
 }
Example #6
0
 public function postAdd()
 {
     $rules = array('firstname' => 'required|min:2', 'lastname' => 'required|min:2', 'email' => 'required|email|unique:users', 'password' => 'required|min:6|max:32|confirmed');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to("admin/user/add")->withErrors($validator)->withInput(Input::except(''));
     }
     $password = Input::get('password');
     $table = new User();
     $table->firstname = Input::get('firstname');
     $table->lastname = Input::get('lastname');
     $table->email = Input::get('email');
     $table->password = Hash::make($password);
     if ($table->save()) {
         $role = Role::where('name', '=', 'Admin')->first();
         $table->attachRole($role);
         Mail::send('mail.userAdd', ['firstname' => $table->firstname, 'lastname' => $table->lastname, 'login' => $table->email, 'password' => $password, 'setting' => Config::get('setting')], function ($message) {
             $message->to(Input::get('email'))->subject("Учетные данные пользователя");
         });
         return Redirect::to("admin/user")->with('success', trans("message.add", ['name' => 'Пользователь']));
     }
     return Redirect::to("login")->with('error', trans('message.error'));
 }
 public function run()
 {
     //create roles
     $admin = new Role();
     $admin->name = 'Admin';
     $admin->save();
     $member = new Role();
     $member->name = 'Member';
     $member->save();
     $user = new User();
     $user->username = 'admin';
     $user->fullname = 'Admin Handal';
     $user->email = 'admin@admin.com';
     $user->password = 'maumasukajasusah';
     $user->password_confirmation = 'maumasukajasusah';
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     if (!$user->save()) {
         print_r('Unable to create user ' . $user->username, (array) $user->errors());
         exit;
     } else {
         $user->attachRole($admin);
         echo 'Created user "' . $user->username . '" <' . $user->email . '>' . PHP_EOL;
     }
 }
 public function register()
 {
     $wantsJson = Request::wantsJson();
     $creds = GoogleSessionController::getCreds();
     $client = GoogleSessionController::getClient();
     $code = Input::get('code');
     if ($code) {
         // Exchange the OAuth 2.0 authorization code for user credentials.
         $client->authenticate($code);
         $token = json_decode($client->getAccessToken());
         $attributes = $client->verifyIdToken($token->id_token, $creds->client_id)->getAttributes();
         $oauth2 = new Google_Service_Oauth2($client);
         $google_user = $oauth2->userinfo->get();
         $email = $google_user->email;
         $username = explode("@", $email)[0];
         // return Response::json(['errors'=>$user->givenName]);
         if ($google_user->hd != 'ideo.com') {
             $errors = ['errors' => [Config::get('config.site_name') . ' is for IDEO only']];
             return $wantsJson ? Response::json($errors) : Redirect::to('register')->with($errors);
         }
         $user = new User();
         $user->username = $username;
         $user->email = $email;
         $password = Hash::make($username);
         // <-- temp...
         $user->firstname = $google_user->givenName;
         $user->lastname = $google_user->familyName;
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->google_token = json_encode($token);
         if ($user->save()) {
             // profile image
             $image_url = $google_user->picture;
             if ($image_url) {
                 $image_url_parts = explode('?', $image_url);
                 $image_url = $image_url_parts[0];
                 $id = $user->id;
                 $image_name = $username . '_' . $id . '.jpg';
                 $save_path = 'assets/content/users';
                 $userImage = new Asset();
                 $userImage->saveRemoteImage($image_url, $save_path, $image_name);
                 $userImage->save();
                 $user->profileImage()->save($userImage);
             }
             // Roles
             if ($username == 'tvanderlin') {
                 $adminRole = Role::where('name', '=', 'Admin')->first();
                 $user->attachRole($adminRole);
             } else {
                 $role = $role = Role::where('name', '=', 'Writer')->first();
                 if ($role) {
                     $user->attachRole($role);
                     $user->save();
                 }
             }
             $back_url = 'users/' . $username;
             Auth::login($user);
             return Redirect::to($back_url);
         } else {
             return $wantsJson ? Response::json(['errors' => $user->errors()->all()]) : Redirect::to('register')->with(['errors' => $user->errors()->all()]);
         }
         return Response::json(['data' => $token, 'attr' => $attributes, 'user' => $user]);
     }
     return $wantsJson ? Response::json(['errors' => ['Missing OAuth Code']]) : Redirect::to('register')->with(['errors' => $user->errors()->all()]);
 }
Example #9
0
 public function seedUsers()
 {
     $user_photos = File::files($this->seed_path);
     Asset::setFromSeed(true);
     foreach (User::all() as $user) {
         $user->delete();
     }
     $faker = Faker\Factory::create();
     $seeder = new LOFaker();
     $n = 50;
     // also creat admin users (kim & I)
     $admins = array(['username' => 'tvanderlin', 'firstname' => 'Todd', 'lastname' => 'Vanderlin', 'email' => 'tvanderlin@ideo.com'], ['username' => 'kmiller', 'firstname' => 'Kim', 'lastname' => 'Miller', 'email' => 'kmiller@ideo.com']);
     foreach ($admins as $data) {
         $data = (object) $data;
         $user = new User();
         $user->timestamps = false;
         $user->email = $data->email;
         $user->username = $data->username;
         $user->firstname = $data->firstname;
         $user->lastname = $data->lastname;
         $password = Hash::make($user->username);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $faker->dateTimeBetween('-3 years', 'now');
         $user->save();
         $role = Role::where('name', '=', 'Admin')->first();
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info('Creating *** Admin *** User: ' . $user->getName() . " [{$user->username}, {$user->email}]");
     }
     $this->info("\t");
     for ($i = 0; $i < $n; $i++) {
         $gender = array_random_item(['men', 'women']);
         $photo = array_random_item($user_photos);
         $role = Role::where('name', '=', 'Writer')->first();
         $joinDate = $faker->dateTimeBetween('-3 years', 'now');
         $user = new User();
         $user->timestamps = false;
         $user->email = 'fake_' . $faker->unique()->email;
         $user->firstname = $faker->firstname;
         $user->lastname = $faker->lastname;
         $user->username = preg_replace("/[^A-Za-z0-9 ]/", '', $faker->unique()->userName);
         $password = Hash::make($faker->password);
         $user->password = $password;
         $user->password_confirmation = $password;
         $user->confirmed = 1;
         $user->confirmation_code = md5($user->username . time('U'));
         $user->created_at = $user->updated_at = $joinDate;
         if ($user->save() == false) {
             $this->error($user->errors() . " " . $user->username);
         }
         $userImage = new Asset();
         $userImage->path = 'assets/content/users';
         $userImage->saveLocalFile($photo, $user->username . ".jpg", Asset::ASSET_TYPE_IMAGE);
         $userImage->save();
         $user->profileImage()->save($userImage);
         $user->profileImage->user()->associate($user);
         $user->save();
         $user->attachRole($role);
         $user->save();
         $this->info($user->id . ' Creating User: ' . $user->getName() . " [{$user->username}, {$user->email}]");
     }
     foreach (User::all() as $user) {
         Notification::fire($user, Notification::NOTIFICATION_HALP_WELCOME);
     }
 }