Ejemplo n.º 1
0
Archivo: sign.php Proyecto: anqh/core
 /**
  * Register with code
  *
  * @param  Model_Invitation  $invitation
  */
 public function _join(Model_Invitation $invitation)
 {
     $user = new Model_User();
     $user->email = $invitation->email;
     // Handle post
     $errors = array();
     if ($_POST && !Arr::get($_POST, 'signup')) {
         $post = Arr::extract($_POST, array('username', 'password', 'password_confirm'));
         $validation = new Validation($post);
         $validation->rule('password_confirm', 'matches', array(':validation', 'password', 'password_confirm'));
         try {
             $user->username = $post['username'];
             $user->password = $post['password'];
             $user->created = time();
             $user->save($validation);
             // Delete used invitation
             $invitation->delete();
             // Login user
             $user->add_role('login');
             Visitor::instance()->login($user, $_POST['password']);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $user->password = $user->password_confirm = null;
             $errors = $e->array->errors('validation');
         }
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_register($user, $errors, $invitation->code));
 }
Ejemplo n.º 2
0
Archivo: sign.php Proyecto: anqh/anqh
 /**
  * Register with code
  *
  * @param  Model_Invitation  $invitation
  * @param  array             $external
  * @param  string            $provider
  */
 public function _join(Model_Invitation $invitation = null, array $external = null, $provider = null)
 {
     $user = new Model_User();
     if ($invitation) {
         $user->email = $invitation->email;
     } else {
         if ($external) {
             $user->email = Arr::get($external, 'email');
             $user->name = Arr::get($external, 'name');
             $user->username = Arr::get($external, 'username', $user->name);
             $user->avatar_url = 'https://graph.facebook.com/' . $external['id'] . '/picture';
             $user->picture = 'https://graph.facebook.com/' . $external['id'] . '/picture?type=large';
             if ($location = Arr::get($external, 'location')) {
                 $user->location = $location->name;
                 $user->city_name = $location->name;
             }
             if ($gender = Arr::get($external, 'gender')) {
                 switch ($gender) {
                     case 'male':
                         $user->gender = 'm';
                         break;
                     case 'female':
                         $user->gender = 'f';
                         break;
                 }
             }
             if ($birthday = Arr::get($external, 'birthday')) {
                 $user->dob = $birthday;
             }
         }
     }
     // Handle post
     $errors = array();
     if ($_POST && !Arr::get($_POST, 'signup')) {
         $post = Arr::extract($_POST, array('username', 'password', 'password_confirm'));
         try {
             $user->username = $post['username'];
             $user->password_kohana = $post['password'];
             $user->created = time();
             $user->save();
             // Delete used invitation
             if ($invitation) {
                 $invitation->delete();
             }
             // Connect accounts
             if ($external && $provider) {
                 $consumer = new OAuth2_Consumer($provider);
                 $token = $consumer->get_token();
                 $external_user_id = $external['id'];
                 if ($token && $external_user_id) {
                     $external = new Model_User_External();
                     $external->set_fields(array('token' => $token['access_token'], 'user_id' => $user->id, 'external_user_id' => $external_user_id, 'created' => time(), 'expires' => time() + (int) $token['expires'], 'provider' => $provider));
                     $external->save();
                 }
             }
             // Login user
             $user->add_role('login');
             Visitor::instance()->login($user, $_POST['password']);
             $this->request->redirect(URL::user($user));
         } catch (Validation_Exception $e) {
             $user->password_kohana = $user->password_confirm = null;
             $errors = $e->array->errors('validation');
         }
     }
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_register($user, $errors, $invitation->code));
 }