Ejemplo n.º 1
0
 public function postTrabalhoassociado()
 {
     $credentials = array('email' => Input::get('email'), 'password' => Input::get('password'));
     $usertype = UserTypes::find(Input::get('usertype'));
     $course = Courses::find(Input::get('course'));
     if (Auth::user()->attempt($credentials)) {
         if ($inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id)) {
             $array = array('msg_success' => Lang::get('messages.login_welcome'), 'usertype' => $usertype, 'inscription' => $inscription);
             return Redirect::to('/autenticacao/trabalhoactualizacaoassociado/')->with($array);
         } else {
             $inscription = new Inscriptions();
             $inscription->id_course = $course->id;
             $inscription->id_user = Auth::user()->user()->id;
             $inscription->id_usertype = $usertype->id;
             $inscription->save();
             $array = array('inscription' => $inscription);
             return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
         }
     } else {
         $associate = Associates::getByEmail($credentials['email']);
         //var_dump($associate[0]);
         /*
         			echo "Tipeado: " . $credentials['password'] . '<br>';
         
         			die(md5($credentials['password']) . '<br>'. $associate[0]->password);*/
         if (!empty($associate[0])) {
             $associate = $associate[0];
             if ($associate->password == md5($credentials['password'])) {
                 $user_finded = User::where('email', '=', $credentials['email'])->take(1)->get();
                 $user = null;
                 if (!empty($user_finded[0])) {
                     $user = $user_finded[0];
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                 } else {
                     $user = new User();
                     $user->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $user->name = $associate->nombre_completo;
                     } else {
                         $user->name = "User without name";
                     }
                     $user->status = 'publish';
                     $user->type = 'associate';
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                 }
                 $associate->user = $user->id;
                 $associate->save();
                 Auth::user()->login($user);
                 if ($inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id)) {
                     $array = array('msg_success' => Lang::get('messages.login_welcome'), 'usertype' => $usertype, 'inscription' => $inscription);
                     return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                 } else {
                     $inscription = new Inscriptions();
                     $inscription->id_course = $course->id;
                     $inscription->id_user = Auth::user()->user()->id;
                     $inscription->id_usertype = $usertype->id;
                     $inscription->save();
                     $array = array('inscription' => $inscription);
                     return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                 }
             } else {
                 $associate = ORGAssociates::getByEmail($credentials['email']);
                 if (!empty($associate[0])) {
                     $associate = $associate[0];
                     if ($associate->senha == md5($credentials['password'])) {
                         $user = new User();
                         $user->email = $associate->email;
                         if ($associate->nombre_completo != null) {
                             $user->name = $associate->nombre_completo;
                         } else {
                             $user->name = "User without name";
                         }
                         $user->status = 'publish';
                         $user->type = 'associate';
                         $user->password = Hash::make($credentials['password']);
                         $user->save();
                         $assoc = new Associates();
                         $assoc->associate = $associate->id_asociado;
                         $assoc->user = $user->id;
                         $assoc->email = $associate->email;
                         if ($associate->nombre_completo != null) {
                             $assoc->name = $associate->nombre_completo;
                         } else {
                             $assoc->name = "User without name";
                         }
                         $assoc->cpf = $associate->cpf;
                         $assoc->password = $associate->senha;
                         $assoc->status = 'publish';
                         $assoc->type = 'associate';
                         $assoc->save();
                         Auth::user()->login($user);
                         if ($inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id)) {
                             $array = array('msg_success' => Lang::get('messages.login_welcome'), 'usertype' => $usertype, 'inscription' => $inscription);
                             return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                         } else {
                             $inscription = new Inscriptions();
                             $inscription->id_course = $course->id;
                             $inscription->id_user = Auth::user()->user()->id;
                             $inscription->id_usertype = $usertype->id;
                             $inscription->save();
                             $array = array('inscription' => $inscription);
                             return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                         }
                     } else {
                         $array = array('course' => $course, 'usertype' => $usertype, 'contents' => FrontendCourseController::getOrderedContent($course->coursesections));
                         return View::make('auth.error')->with($array);
                     }
                 } else {
                     $array = array('course' => $course, 'usertype' => $usertype, 'contents' => FrontendCourseController::getOrderedContent($course->coursesections));
                     return View::make('auth.error')->with($array);
                 }
                 $array = array('course' => $course, 'usertype' => $usertype, 'contents' => FrontendCourseController::getOrderedContent($course->coursesections));
                 return View::make('auth.error')->with($array);
             }
         } else {
             $associate = ORGAssociates::getByEmail($credentials['email']);
             if (!empty($associate[0])) {
                 $associate = $associate[0];
                 if ($associate->senha == md5($credentials['password'])) {
                     $user = new User();
                     $user->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $user->name = $associate->nombre_completo;
                     } else {
                         $user->name = "User without name";
                     }
                     $user->status = 'publish';
                     $user->type = 'associate';
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                     $assoc = new Associates();
                     $assoc->associate = $associate->id_asociado;
                     $assoc->user = $user->id;
                     $assoc->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $assoc->name = $associate->nombre_completo;
                     } else {
                         $assoc->name = "User without name";
                     }
                     $assoc->cpf = $associate->cpf;
                     $assoc->password = $associate->senha;
                     $assoc->status = 'publish';
                     $assoc->type = 'associate';
                     $assoc->save();
                     Auth::user()->login($user);
                     if ($inscription = Inscriptions::hasInscription(Auth::user()->user()->id, $course->id)) {
                         $array = array('msg_success' => Lang::get('messages.login_welcome'), 'usertype' => $usertype, 'inscription' => $inscription);
                         return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                     } else {
                         $inscription = new Inscriptions();
                         $inscription->id_course = $course->id;
                         $inscription->id_user = Auth::user()->user()->id;
                         $inscription->id_usertype = $usertype->id;
                         $inscription->save();
                         $array = array('inscription' => $inscription);
                         return Redirect::to('/autenticacao/trabalhoactualizacaoassociado')->with($array);
                     }
                 } else {
                     $array = array('course' => $course, 'usertype' => $usertype, 'contents' => FrontendCourseController::getOrderedContent($course->coursesections));
                     return View::make('auth.error')->with($array);
                 }
             } else {
                 $array = array('course' => $course, 'usertype' => $usertype, 'contents' => FrontendCourseController::getOrderedContent($course->coursesections));
                 return View::make('auth.error')->with($array);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function postAuth()
 {
     $credentials = array('email' => Input::get('email'), 'password' => Input::get('password'), 'type' => 'associate');
     $course = Courses::find(Input::get('course'));
     if (Auth::user()->attempt($credentials)) {
         if ($payment = ORGAssociateAnnuities::hasAnnuity(Auth::user()->user())) {
             return Redirect::to(self::$route . '/acusado');
         } else {
             return Redirect::to(self::$route . '/pagamento');
         }
     } else {
         $associate = Associates::getByEmail($credentials['email']);
         if (!empty($associate[0])) {
             $associate = $associate[0];
             if ($associate->password == md5($credentials['password'])) {
                 $user_finded = User::where('email', '=', $credentials['email'])->take(1)->get();
                 $user = null;
                 if (!empty($user_finded[0])) {
                     $user = $user_finded[0];
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                 } else {
                     $user = new User();
                     $user->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $user->name = $associate->nombre_completo;
                     } else {
                         $user->name = "User without name";
                     }
                     $user->status = 'publish';
                     $user->type = 'associate';
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                     $associate->user = $user->id;
                     $associate->save();
                 }
                 Auth::user()->login($user);
                 if ($payment = ORGAssociateAnnuities::hasAnnuity(Auth::user()->user())) {
                     return Redirect::to(self::$route . '/acusado');
                 } else {
                     return Redirect::to(self::$route . '/pagamento');
                 }
             } else {
                 $associate = ORGAssociates::getByEmail($credentials['email']);
                 if (!empty($associate[0])) {
                     $associate = $associate[0];
                     if ($associate->senha == md5($credentials['password'])) {
                         $user = new User();
                         $user->email = $associate->email;
                         if ($associate->nombre_completo != null) {
                             $user->name = $associate->nombre_completo;
                         } else {
                             $user->name = "User without name";
                         }
                         $user->status = 'publish';
                         $user->type = 'associate';
                         $user->password = Hash::make($credentials['password']);
                         $user->save();
                         $assoc = new Associates();
                         $assoc->associate = $associate->id_asociado;
                         $assoc->user = $user->id;
                         $assoc->email = $associate->email;
                         if ($associate->nombre_completo != null) {
                             $assoc->name = $associate->nombre_completo;
                         } else {
                             $assoc->name = "User without name";
                         }
                         $assoc->cpf = $associate->cpf;
                         $assoc->password = $associate->senha;
                         $assoc->status = 'publish';
                         $assoc->type = 'associate';
                         $assoc->save();
                         Auth::user()->login($user);
                         if ($payment = ORGAssociateAnnuities::hasAnnuity(Auth::user()->user())) {
                             return Redirect::to(self::$route . '/acusado');
                         } else {
                             return Redirect::to(self::$route . '/pagamento');
                         }
                     } else {
                         return Redirec::to(self::$route . '/error');
                     }
                 } else {
                     return Redirec::to(self::$route . '/error');
                 }
                 return Redirec::to(self::$route . '/error');
             }
         } else {
             $associate = ORGAssociates::getByEmail($credentials['email']);
             if (!empty($associate[0])) {
                 $associate = $associate[0];
                 if ($associate->senha == md5($credentials['password'])) {
                     $user = new User();
                     $user->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $user->name = $associate->nombre_completo;
                     } else {
                         $user->name = "User without name";
                     }
                     $user->status = 'publish';
                     $user->type = 'associate';
                     $user->password = Hash::make($credentials['password']);
                     $user->save();
                     $assoc = new Associates();
                     $assoc->associate = $associate->id_asociado;
                     $assoc->user = $user->id;
                     $assoc->email = $associate->email;
                     if ($associate->nombre_completo != null) {
                         $assoc->name = $associate->nombre_completo;
                     } else {
                         $assoc->name = "User without name";
                     }
                     $assoc->cpf = $associate->cpf;
                     $assoc->password = $associate->senha;
                     $assoc->status = 'publish';
                     $assoc->type = 'associate';
                     $assoc->save();
                     Auth::user()->login($user);
                     if ($payment = ORGAssociateAnnuities::hasAnnuity(Auth::user()->user())) {
                         return Redirect::to(self::$route . '/acusado');
                     } else {
                         return Redirect::to(self::$route . '/pagamento');
                     }
                 } else {
                     return Redirec::to(self::$route . '/error');
                 }
             } else {
                 return Redirec::to(self::$route . '/error');
             }
         }
     }
 }