예제 #1
0
 private function registerUser($username, $data = NULL)
 {
     try {
         $gingerKey = sfConfig::get('app_portail_ginger_key');
         if ($gingerKey != "abc") {
             $ginger = new \Ginger\Client\GingerClient(sfConfig::get('app_portail_ginger_key'));
             $cotisants = $ginger->getUser($username);
         } else {
             $cotisants = new stdClass();
             $cotisants->mail = $username . "@etu.utc.fr";
             $cotisants->prenom = "Le";
             $cotisants->nom = "Testeur";
             $cotisants->type = "etu";
         }
         if (!$data) {
             $data = new sfGuardUser();
         }
         $data->setUsername($username);
         $data->setEmailAddress($cotisants->mail);
         $data->setFirstName($cotisants->prenom);
         $data->setLastName($cotisants->nom);
         $data->setIsActive(true);
         $data->save();
         $profile = new Profile();
         $profile->setUser($data);
         $profile->setDomain($cotisants->type);
         $profile->save();
         return $data;
     } catch (\Ginger\Client\ApiException $ex) {
         $this->setFlash('error', "Il n'a pas été possible de vous identifier. Merci de contacter simde@assos.utc.fr en précisant votre login et le code d'erreur " . $ex->getCode() . ".");
     }
     return false;
 }
예제 #2
0
 public function getProfile()
 {
     if (!$this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         throw new \LogicException("Can't get profile of a non-authenticated user.");
     }
     $user = $this->securityContext->getToken()->getUser();
     $repo = $this->em->getRepository('ZzPyroBundle:Profile');
     $profile = $repo->findOneByUser($user);
     if ($profile === null) {
         $profile = new Profile();
         $profile->setUser($user);
         $this->em->persist($profile);
     }
     return $profile;
 }
예제 #3
0
 /**
  * Create
  */
 public function anyCreate()
 {
     $user = new User();
     $profile = new Profile();
     // process POST
     if ($_POST) {
         // check for valid data
         // typecast to prevent error (if there are no profile fields)
         $userValidate = $user->fillValidateAdminCreate(Input::get("User"));
         $profileValidate = $profile->fillValidateAdminCreate((array) Input::get("Profile"));
         if ($userValidate and $profileValidate) {
             $user->save();
             $profile->setUser($user->id)->save();
             // set success and reload page
             Session::flash("success", $user);
             return Redirect::to(Request::path());
         }
     }
     return View::make("admin.create", array("user" => $user, "profile" => $profile));
 }
예제 #4
0
 /**
  * Register new user
  * @param User $user
  * @param Profile $profile
  * @return bool
  */
 protected function _register($user, $profile)
 {
     // set up user and profile
     $roleId = Role::USER;
     $status = User::STATUS_ACTIVE;
     if (Config::get("auth.emailActivation")) {
         $status = User::STATUS_INACTIVE;
         $user->generateToken();
     }
     $user->setDefaults($roleId, $status)->save();
     $profile->setUser($user->id)->save();
     // generate activation key and send email
     if (Config::get("auth.emailActivation")) {
         // send email
         $data["user"] = $user;
         $count = Mail::send(Config::get("auth.emailViewPath") . ".activate", $data, function ($message) use($user, $profile) {
             $message->to($user->email, $user->username)->subject("Activate your new account");
         });
     } else {
         Auth::login($user);
     }
 }
예제 #5
0
 function getUser()
 {
     if (is_null($this->UserID)) {
         return parent::getUser();
     }
     if (is_null(parent::getUser()) && $this->UserID) {
         parent::setUser(Outlet::getInstance()->load('User', $this->UserID));
     }
     return parent::getUser();
 }