当前位置: 首页>>代码示例>>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;未经允许,请勿转载。