示例#1
0
 public function accountIsActive($code)
 {
     $user = User::where('activation_code', '=', $code)->first();
     // GET IP ADDRESS
     $userIpAddress = new CaptureIp();
     $user->signup_confirmation_ip_address = $userIpAddress->getClientIp();
     $user->active = 1;
     $user->activation_code = '';
     if ($user->save()) {
         \Auth::login($user);
     }
     return true;
 }
示例#2
0
 public function accountIsActive($code)
 {
     // CHECK IF ACTIVATION CODE MATCHES THE ONE WE SENT
     $user = User::where('activation_code', '=', $code)->first();
     // GET IP ADDRESS
     $userIpAddress = new CaptureIp();
     $user->signup_confirmation_ip_address = $userIpAddress->getClientIp();
     // SET THE USER TO ACTIVE
     $user->active = 1;
     // CLEAR THE ACTIVATION CODE
     $user->activation_code = '';
     // SAVE THE USER
     if ($user->save()) {
         \Auth::login($user);
     }
     return true;
 }
 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);
 }
 /**
  * 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!');
     }
 }