Esempio n. 1
0
 public function findByUserNameOrCreate($userData)
 {
     $user = SocialUser::where('provider_id', '=', $userData->id)->first();
     if (!$user) {
         $user = SocialUser::create(['provider_id' => $userData->id, 'name' => $userData->name, 'username' => $userData->nickname, 'email' => $userData->email, 'avatar' => $userData->avatar]);
     }
     $this->checkIfUserNeedsUpdating($userData, $user);
     return $user;
 }
 public function RegisterUser()
 {
     $UserData = Input::all();
     $Length = 50;
     $Token = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $Length);
     $UserData['verify_token'] = $Token;
     $Password_Raw = $this->request->input('password');
     $UserData['password_raw'] = $Password_Raw;
     $UserData['gcm_id'] = '';
     if ($this->request->input('gcm_id')) {
         $Length = 6;
         $OTP = substr(str_shuffle("023456789ABCDEFGHJKLMNOPQRSTUVWXYZ"), 0, $Length);
         $UserData['otp'] = $OTP;
         $UserData['gcm_id'] = $this->request->input('gcm_id');
         MobileUser::create($UserData);
         $PushMessage = "{'Type' : 'OTP', 'Code' : '.{$OTP}.'}";
         $Message = array("price" => urldecode($PushMessage));
         $this->PushNotification($this->request->input('gcm_id'), $Message);
         return 1;
         exit;
     }
     if ($this->request->input('facebook_id')) {
         $validation = Validator::make($UserData, SocialUser::$RegisterRule);
     } else {
         $validation = Validator::make($UserData, User::$RegisterRule);
     }
     if ($validation->passes()) {
         #If the Validation passes
         if ($this->request->input('facebook_id')) {
             $UserData['quickblox_id'] = '';
             SocialUser::create($UserData);
         } else {
             User::create($UserData);
         }
         #Creating the User
         $Email = $this->request->input('email');
         $UserName = $this->request->input('firstname');
         if ($this->request->input('facebook_id')) {
             Mail::send([], array('UserName' => $UserName, 'Email' => $Email, 'Token' => $Token), function ($message) use($UserName, $Email, $Token) {
                 #Getting content from the Mail Template and Triggering the Email to the User with Activation Code
                 $MailContent = MailTemplate::find(2);
                 $MailBody = $MailContent->content;
                 $MailBody = str_replace("{{username}}", $UserName, $MailBody);
                 $MailBody = str_replace("{{link}}", $Token, $MailBody);
                 $message->setBody($MailBody, 'text/html');
                 $message->to($Email);
                 $message->subject($MailContent->subject);
             });
             #Returning Success
             return 'success';
         } else {
             Mail::send([], array('UserName' => $UserName, 'Email' => $Email, 'Token' => $Token), function ($message) use($UserName, $Email, $Token) {
                 #Getting content from the Mail Template and Triggering the Email to the User with Activation Code
                 $MailContent = MailTemplate::find(1);
                 $MailBody = $MailContent->content;
                 $MailBody = str_replace("{{username}}", $UserName, $MailBody);
                 $MailBody = str_replace("{{link}}", $Token, $MailBody);
                 $message->setBody($MailBody, 'text/html');
                 $message->to($Email);
                 $message->subject($MailContent->subject);
             });
             #Returning Success
             return 'success';
         }
     } else {
         #If the Validation fails send the
         return $validation->messages();
     }
 }