當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::assignRole方法代碼示例

本文整理匯總了PHP中app\models\User::assignRole方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::assignRole方法的具體用法?PHP User::assignRole怎麽用?PHP User::assignRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\User的用法示例。


在下文中一共展示了User::assignRole方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handle

 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name');
     $this->user->email = $this->request->input('email');
     $this->user->password = bcrypt($this->request->input('password'));
     $role = Role::whereName(Role::getAdministratorName())->firstOrFail();
     if ($this->user->save()) {
         $this->user->assignRole($role);
         return true;
     }
     return false;
 }
開發者ID:stevebauman,項目名稱:administration,代碼行數:17,代碼來源:Finish.php

示例2: register

 public function register($data)
 {
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->save();
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
 }
開發者ID:andela-sakande,項目名稱:auth-with-roles,代碼行數:12,代碼來源:UserRepository.php

示例3: postRegister

 public function postRegister()
 {
     $user = new User();
     $user->name = Input::get('name');
     $user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));
     $user->save();
     //Assign Role
     $role = Role::whereName('customer')->first();
     $user->assignRole($role);
     return redirect('auth/login');
 }
開發者ID:hendrilara,項目名稱:laravel5.1-User-Role,代碼行數:12,代碼來源:AuthController.php

示例4: register

 public function register($data)
 {
     $confirmation_code = sha1(mt_rand());
     $user = new User();
     $user->email = $data['email'];
     $user->first_name = ucfirst($data['first_name']);
     $user->last_name = ucfirst($data['last_name']);
     $user->password = Hash::make($data['password']);
     $user->confirmation_code = $confirmation_code;
     $user->save();
     //Save Profile
     $user->profile()->save(new Profile());
     //Assign Role
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
     //Data
     $data = ['first_name' => $user->first_name, 'confirmation_code' => $confirmation_code, 'subject' => 'Please Verify Email Address', 'email' => $user->email];
     //Send Verification Email
     //        $this->userMailer->verify($user->email, $data);
 }
開發者ID:suchayj,項目名稱:easymanage,代碼行數:20,代碼來源:UserRepository.php

示例5: getSocialHandle

 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $social_user = null;
     //CHECK IF USERS EMAIL ADDRESS IS ALREADY IN DATABASE
     $user_check = User::where('email', '=', $user->email)->first();
     if (!empty($user_check)) {
         $social_user = $user_check;
     } else {
         $same_social_id = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         // CHECK IF NEW SOCIAL MEDIA USER
         if (empty($same_social_id)) {
             $new_social_user = new User();
             $new_social_user->email = $user->email;
             $name = explode(' ', $user->name);
             if ($user->email) {
                 $new_social_user->name = $user->email;
             } else {
                 $new_social_user->name = $name[0];
             }
             $new_social_user->first_name = $name[0];
             // CHECK FOR LAST NAME
             if (isset($name[1])) {
                 $new_social_user->last_name = $name[1];
             }
             $new_social_user->active = '1';
             $the_activation_code = str_random(60) . $user->email;
             $new_social_user->activation_code = $the_activation_code;
             // GET IP ADDRESS
             $userIpAddress = new CaptureIp();
             $new_social_user->signup_sm_ip_address = $userIpAddress->getClientIp();
             // SAVE THE USER
             $new_social_user->save();
             // GET SOCIAL MEDIA LOGIN DATA
             $social_data = new Social();
             $social_data->social_id = $user->id;
             $social_data->provider = $provider;
             $new_social_user->social()->save($social_data);
             // GET GRAVATAR
             $new_social_user->gravatar = Gravatar::get($user->email);
             // ADD ROLE
             $role = Role::whereName('user')->first();
             $new_social_user->assignRole($role);
             $social_user = $new_social_user;
             // LINK TO PROFILE TABLE
             $profile = new Profile();
             $social_user->profile()->save($profile);
         } else {
             //Load this existing social user
             $social_user = $same_social_id->user;
         }
     }
     $this->auth->login($social_user, true);
     if ($this->auth->user()->hasRole('user')) {
         //return redirect()->route('user.home');
         return redirect('dashboard');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('dashboard');
         //return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }
開發者ID:gabrieljaime,項目名稱:laravel-admin-master,代碼行數:63,代碼來源:AuthController.php

示例6: handleLdapUserWasAuthenticated

 /**
  * Attaches roles depending on the users active directory group.
  *
  * @param User       $user
  * @param AdldapUser $adldapUser
  *
  * @return void
  */
 protected function handleLdapUserWasAuthenticated(User $user, AdldapUser $adldapUser)
 {
     if ($adldapUser->inGroup('Help Desk')) {
         $admin = Role::whereName(Role::getAdministratorName())->first();
         // If we have the administrator role and the user isn't
         // already a member, then we'll assign them the role.
         if ($admin instanceof Role && !$user->hasRole($admin)) {
             $user->assignRole($admin);
         }
     }
     $user->from_ad = true;
     $user->save();
 }
開發者ID:stevebauman,項目名稱:ithub,代碼行數:21,代碼來源:AuthController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(StoreUserRequest $request)
 {
     // get the current user record
     $user = new User();
     // update name and email addr
     $user->first_name = $request->input('first_name');
     $user->last_name = $request->input('last_name');
     $user->email = $request->input('email');
     $user->save();
     // prepare success message
     $message = 'User with id "' . $user->id . '" added';
     // create list of instruments
     $instruments = Instrument::all();
     // which instrument was assigned in the form?
     foreach ($instruments as $instrument) {
         if ($request->has(str_replace(' ', '_', $instrument->name))) {
             $user->assignInstrument($instrument);
         } else {
             $user->removeInstrument($instrument);
         }
     }
     // get list of possible user roles
     $roles = Role::all();
     // which role was assigned in the form?
     foreach ($roles as $role) {
         if ($request->has(str_replace(' ', '_', $role->name))) {
             $user->assignRole($role);
         } else {
             $user->removeRole($role);
         }
     }
     return \Redirect::route($this->view_all_idx)->with(['status' => $message]);
 }
開發者ID:matthiku,項目名稱:cSpot,代碼行數:39,代碼來源:UserController.php

示例8: getSocialHandle

 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = $name[0];
             $newSocialUser->last_name = $name[1];
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             $role = Role::whereName('user')->first();
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect()->route('user.home');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }
開發者ID:alsofronie,項目名稱:laravel-social-email-authentication,代碼行數:40,代碼來源:AuthController.php

示例9: getSocialHandle

 /**
  * Provider used the "callback URL" and now we process the returned information
  */
 public function getSocialHandle(Request $request, $provider, AppMailer $mailer)
 {
     Log::info($request->ip() . ' - getSocialHandle - User gave consent to register using ' . $provider);
     $social = Socialite::driver($provider);
     $user = $social->user();
     $code = Input::get('code');
     if (!$code) {
         return redirect('login')->with('status', 'danger')->with('message', 'You did not share your profile data with c-SPOT.');
     }
     if (!$user->email) {
         return redirect('login')->with('status', 'danger')->with('message', 'You did not share your email with c-SPOT. You need to visit your ' . $provider . ' App Settings and remove c-SPOT, than you can come back here and login again. Or you can create a new account.');
     }
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             // As there is no combination of this social id and provider,
             // we create a new one
             $newSocialUser = new User();
             // the email address as provided by the service provider
             $newSocialUser->email = $user->email;
             // perhaps the email contains a name?
             $emailName = explode('@', $user->email)[0];
             if (strlen($user->name) < 3) {
                 $user->name = str_replace('.', ' ', $emailName);
             }
             // the name is hopefully a full name with first- and lastname
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = $name[0];
             $newSocialUser->last_name = count($name) > 1 ? $name[1] : $name[0];
             // save the new user
             $newSocialUser->save();
             // Add role
             $role = Role::whereName('user')->first();
             $newSocialUser->assignRole($role);
             // create record in the social table
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     Log::info($request->ip() . ' - getSocialHandle - trying to do social-sign in');
     $mailer->notifyAdmin($socialUser, 'User confirmed via ' . $provider);
     // $this->auth->login($socialUser, true);
     Auth::login($socialUser, true);
     // write last login field in users table
     Auth::user()->update(['last_login' => Carbon::now()]);
     return redirect()->intended($this->redirectPath());
 }
開發者ID:matthiku,項目名稱:cSpot,代碼行數:61,代碼來源:RegisterController.php

示例10: getSocialHandle

 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $code = Input::get('code');
     if (!$code) {
         return redirect()->route('auth.login')->with('status', 'danger')->with('message', 'You did not share your profile data with our socail app.');
     }
     if (!$user->email) {
         return redirect()->route('auth.login')->with('status', 'danger')->with('message', 'You did not share your email with our social app. You need to visit App Settings and remove our app, than you can come back here and login again. Or you can create new account.');
     }
     $socialUser = null;
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = $name[0];
             $newSocialUser->last_name = $name[1];
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             $role = Role::whereName('user')->first();
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect()->route('user.home');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect()->route('admin.home');
     }
     return \App::abort(500);
 }
開發者ID:Riyazkhan1989,項目名稱:laravel-social-email-authentication,代碼行數:47,代碼來源:AuthController.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $create_new_validator = $this->create_new_validator($request->all());
     if ($create_new_validator->fails()) {
         $this->throwValidationException($request, $create_new_validator);
     } else {
         $activation_code = str_random(60) . $request->input('email');
         $user = new User();
         $user->email = $request->input('email');
         $user->name = $request->input('name');
         $user->first_name = $request->input('first_name');
         $user->last_name = $request->input('last_name');
         $userAccessLevel = $request->input('user_level');
         $user->password = bcrypt($request->input('password'));
         // GET ACTIVATION CODE
         $user->activation_code = $activation_code;
         $user->active = '1';
         // GET IP ADDRESS
         $userIpAddress = new CaptureIp();
         $user->admin_ip_address = $userIpAddress->getClientIp();
         // SAVE THE USER
         $user->save();
         // ADD ROLE
         $user->assignRole($userAccessLevel);
         // CREATE PROFILE LINK TO TABLE
         $profile = new Profile();
         $profileInputs = Input::only('location', 'bio', 'twitter_username', 'github_username');
         $profile->fill($profileInputs);
         $user->profile()->save($profile);
         // THE SUCCESSFUL RETURN
         return redirect('edit-users')->with('status', 'Successfully created user!');
     }
 }
開發者ID:jeremykenedy,項目名稱:laravel-auth,代碼行數:39,代碼來源:UsersManagementController.php


注:本文中的app\models\User::assignRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。