Esempio n. 1
0
 /**
  * @depends testRegisterUser
  */
 public function testName()
 {
     $this->assertEquals('Bob', self::$user->name());
     $this->assertEquals('Bob Loblaw', self::$user->name(true));
     $guest = new User(GUEST);
     $this->assertEquals('Guest', $guest->name());
     $notfound = new User(-100);
     $this->assertEquals('(not registered)', $notfound->name());
     self::$user->first_name = '';
     $this->assertEquals('*****@*****.**', self::$user->name());
 }
Esempio n. 2
0
 protected function postDeleteHook()
 {
     if ($this->_deleteEmail) {
         $this->_deleteUser->sendEmail('volunteer-hours-rejected', $this->_deleteEmail);
     }
     $this->_deleteUser->incrementStats($this->_delta);
 }
Esempio n. 3
0
 function volunteersLookupByUsername($req, $res)
 {
     $org = $this->getOrgForAdmin($req, $res);
     if (!is_object($org)) {
         return $org;
     }
     $username = $req->query('username');
     $user = User::findOne(['where' => ['username' => $username]]);
     if ($user && $org->getRoleOfUser($user) >= Volunteer::ROLE_AWAITING_APPROVAL) {
         return $res->redirect($org->manageUrl() . '/volunteers/' . $user->id());
     }
     $req->setParams(['usernameNotFound' => true]);
     return $this->volunteersBrowse($req, $res);
 }
Esempio n. 4
0
 public function testProfilePictureInstagram()
 {
     $user = new User();
     $user->instagram_id = 100;
     $user->profile_picture_preference = 'instagram';
     $this->assertEquals('instagram_profile_picture', $user->profilePicture(80));
 }
Esempio n. 5
0
 /**
  * Adds a volunteer to the organization. If the volunteer is not a
  * member yet, then a temporary account will be created. This
  * will send an e-mail to the user.
  *
  * @param string $emailOrUsername
  *
  * @return Volunteer|false invited volunteer
  */
 public function inviteVolunteer($emailOrUsername)
 {
     $user = false;
     $isEmail = true;
     if (Validate::is($emailOrUsername, 'email')) {
         $user = User::findOne(['where' => ['user_email' => $emailOrUsername]]);
         $isEmail = true;
     } else {
         $user = User::findOne(['where' => ['username' => $emailOrUsername]]);
     }
     // create temporary user
     if (!$user && $isEmail) {
         $user = User::createTemporary(['user_email' => $emailOrUsername, 'invited_by' => $this->id()]);
     }
     if (!$user) {
         return false;
     }
     $isTemporary = $user->isTemporary();
     $volunteer = new Volunteer([$user->id(), $this->id()]);
     if ($volunteer->exists()) {
         return $volunteer;
     }
     $volunteer = new Volunteer();
     $volunteer->grantAllPermissions();
     $volunteer->create(['uid' => $user->id(), 'organization' => $this->id(), 'application_shared' => true, 'active' => true, 'role' => Volunteer::ROLE_VOLUNTEER]);
     $base = $this->app['base_url'];
     $orgName = $this->name;
     $ctaUrl = $isTemporary ? $base . 'signup?user_email=' . $user->user_email : $base . 'profile';
     $user->sendEmail('volunteer-invite', ['subject' => "{$orgName} has invited you as a volunteer", 'orgname' => $orgName, 'cta_url' => $ctaUrl]);
     return $volunteer;
 }
 public function callback($req, $res)
 {
     if ($req->query('error_reason')) {
         return $res->redirect('/');
     }
     // generate forceLogin redirect_uri
     if ($req->query('forceLogin')) {
         $this->app['config']->set('instagram.redirect_uri', $this->app['config']->get('instagram.redirect_uri') . '?forceLogin=t');
     }
     $instagram = $this->app['instagram'];
     /* authenticate the user with the instagram API */
     $authenticatedUser = false;
     try {
         if ($instagram->Users->Authorize($req->query('code'))) {
             $authenticatedUser = $instagram->Users->getCurrentUser();
         }
     } catch (\Exception $e) {
         $this->app['logger']->error($e);
     }
     if (!$authenticatedUser) {
         $this->app['errors']->push(['context' => 'user.login', 'error' => 'invalid_token', 'message' => 'Instagram: Login error. Please try again.']);
         $usersController = new \app\users\Controller($this->app);
         return $usersController->loginForm($req, $res);
     }
     /* fetch the user's full profile */
     try {
         $user_profile = $instagram->Users->Info($authenticatedUser['id'])->data;
     } catch (\Exception $e) {
         $this->app['logger']->error($e);
         return $res->setCode(500);
     }
     /* log the user in or kick off signup */
     $currentUser = $this->app['user'];
     $iid = $user_profile['id'];
     // generate parameters to update profile
     $profileUpdateArray = ['id' => $iid, 'access_token' => $instagram->getAccessToken()];
     // instagram id matches existing user?
     $user = User::findOne(['where' => ['instagram_id' => $iid]]);
     if ($user) {
         // check if we are dealing with a temporary user
         if (!$user->isTemporary()) {
             if ($user->id() != $currentUser->id()) {
                 if ($req->query('forceLogin') || !$currentUser->isLoggedIn()) {
                     // log the user in
                     $this->app['auth']->signInUser($user->id(), 'instagram');
                 } else {
                     // inform the user that the instagram account they are trying to
                     // connect belongs to someone else
                     return new View('switchingAccounts/instagram.tpl', ['title' => 'Switch accounts?', 'otherUser' => $user, 'otherProfile' => $user->instagramProfile()]);
                 }
             }
             $profile = new InstagramProfile($iid);
             // create or update the profile
             if ($profile->exists()) {
                 $profile->set($profileUpdateArray);
             } else {
                 $profile = new InstagramProfile();
                 $profile->create($profileUpdateArray);
             }
             // refresh profile from API
             $profile->refreshProfile($user_profile);
             return $this->finalRedirect($req, $res);
         } else {
             // show finish signup screen
             $req->setSession('iid', $iid);
             return $res->redirect('/signup/finish');
         }
     }
     if ($currentUser->isLoggedIn()) {
         // add to current user's account
         $currentUser->set('instagram_id', $iid);
     } else {
         // save this for later
         $req->setSession('iid', $iid);
     }
     $profile = new InstagramProfile($iid);
     // create or update the profile
     if ($profile->exists()) {
         $profile->set($profileUpdateArray);
     } else {
         // create profile
         $profile = new InstagramProfile();
         $profile->create($profileUpdateArray);
     }
     // refresh profile from API
     $profile->refreshProfile($user_profile);
     // get outta here
     if ($currentUser->isLoggedIn()) {
         $this->finalRedirect($req, $res);
     } else {
         $res->redirect('/signup/finish');
     }
 }
 private function loginOrRegister($fbid, $user_profile, $req, $res)
 {
     $currentUser = $this->app['user'];
     $facebook = $this->app['facebook'];
     // get friend count
     $friendCount = 0;
     try {
         $friends = $facebook->api('me/friends');
         $friendCount = count((array) U::array_value($friends, 'data'));
     } catch (\FacebookApiException $e) {
         $this->app['logger']->error($e);
     }
     // generate parameters to update profile
     $profileUpdateArray = ['id' => $fbid, 'access_token' => $facebook->getAccessToken(), 'friends_count' => $friendCount];
     // fbid matches existing user?
     $user = User::findOne(['where' => ['facebook_id' => $fbid]]);
     if ($user) {
         // check if we are dealing with a temporary user
         if (!$user->isTemporary()) {
             if ($user->id() != $currentUser->id()) {
                 if ($req->query('forceLogin') || !$currentUser->isLoggedIn()) {
                     // log the user in
                     $this->app['auth']->signInUser($user->id(), 'facebook');
                 } else {
                     $logoutNextUrl = $this->app['base_url'] . 'facebook/connect?logout=t';
                     // inform the user that the facebook account they are trying to connect
                     // belongs to someone else
                     return new View('switchingAccounts/facebook', ['title' => 'Switch accounts?', 'otherUser' => $user, 'otherProfile' => $user->facebookProfile(), 'logoutUrl' => $facebook->getLogoutUrl(['next' => $logoutNextUrl])]);
                 }
             }
             $profile = new FacebookProfile($fbid);
             // create or update the profile
             if ($profile->exists()) {
                 $profile->set($profileUpdateArray);
             } else {
                 $profile = new FacebookProfile();
                 $profile->create($profileUpdateArray);
             }
             // refresh profile from API
             $profile->refreshProfile($user_profile);
             return $this->finalRedirect($req, $res);
         } else {
             // show finish signup screen
             $req->setSessoin('fbid', $fbid);
             return $res->redirect('/signup/finish');
         }
     }
     if ($currentUser->isLoggedIn()) {
         // add to current user's account
         $currentUser->set('facebook_id', $fbid);
     } else {
         // save this for later
         $req->setSession('fbid', $fbid);
     }
     $profile = new FacebookProfile($fbid);
     // create or update the profile
     if ($profile->exists()) {
         $profile->set($profileUpdateArray);
     } else {
         $profile = new FacebookProfile();
         $profile->create($profileUpdateArray);
     }
     // refresh profile from API
     $profile->refreshProfile($user_profile);
     // get outta here
     if ($currentUser->isLoggedIn()) {
         $this->finalRedirect($req, $res);
     } else {
         $res->redirect('/signup/finish');
     }
 }
Esempio n. 8
0
 public function sendVerifyEmail($req, $res)
 {
     // look up user
     $user = new User($req->params('id'));
     // check that the user is not verified
     if ($user->isVerified(false)) {
         return $res->setCode(404);
     }
     // send the e-mail
     $this->app['auth']->sendVerificationEmail($user);
     return new View('verifyEmailSent', ['title' => 'E-mail Verification Sent']);
 }
 /**
  * @depends testCreate
  */
 public function testUserName()
 {
     $user = new User(-2);
     $this->assertEquals('Test M. User', $user->name(true));
 }
Esempio n. 10
0
 public function finishSignupPost($req, $res)
 {
     $params = $req->request();
     $params['ip'] = $req->ip();
     if ($fbid = $req->session('fbid')) {
         $params['facebook_id'] = $fbid;
         $params['profile_picture_preference'] = 'facebook';
     } elseif ($tid = $req->session('tid')) {
         $params['twitter_id'] = $tid;
         $params['profile_picture_preference'] = 'twitter';
     } elseif ($iid = $req->session('iid')) {
         $params['instagram_id'] = $iid;
         $params['profile_picture_preference'] = 'instagram';
     } else {
         return $res->setCode(404);
     }
     // register
     $user = User::registerUser($params);
     if ($user) {
         // login
         $this->app['auth']->login($req->request('user_email'), $req->request('user_password')[0], $req, true);
         // cleanup session
         $req->setSession(['fbid' => null, 'tid' => null, 'iid' => null]);
         // redirect
         $redir = $req->request('redir') ? $req->request('redir') : $req->cookies('redirect');
         if (!empty($redir)) {
             $req->setCookie('redirect', '', time() - 86400, '/');
             return $res->redirect($redir);
         } else {
             return $res->redirect('/profile');
         }
     }
     return $this->finishSignup($req, $res);
 }
Esempio n. 11
0
 /**
  * @depends testCreate
  */
 public function testInviteVolunteer()
 {
     // invite an existing user by an email address
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user));
     // invite an existing user by an email address again
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user));
     // invite an existing user by username
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('testvolunteer2'));
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$user2));
     // invite a non-existent user by email address
     $this->assertInstanceOf('app\\volunteers\\models\\Volunteer', self::$org->inviteVolunteer('*****@*****.**'));
     // check that user exists and is temporary
     self::$tempUser = User::findOne(['where' => ['user_email' => '*****@*****.**']]);
     $this->assertTrue(self::$tempUser->exists());
     $this->assertTrue(self::$tempUser->isTemporary());
     $this->assertEquals(self::$org->id(), self::$tempUser->invited_by);
     $this->assertEquals(Volunteer::ROLE_VOLUNTEER, self::$org->getRoleOfUser(self::$tempUser));
     // invite a non-existent user by username
     $this->assertFalse(self::$org->inviteVolunteer('badusername'));
 }
 public function callback($req, $res)
 {
     if ($req->query('denied')) {
         return $res->redirect('/');
     }
     $twitter = $this->twitter($req->session('oauth_token'), $req->session('oauth_token_secret'));
     $token_credentials = $twitter->getAccessToken($req->query('oauth_verifier'));
     if (!isset($token_credentials['oauth_token'])) {
         $this->app['errors']->push(['context' => 'user.login', 'error' => 'invalid_token', 'message' => 'Twitter: Invalid token. Please try again.']);
         $usersController = new \app\users\Controller();
         $usersController->injectApp($this->app);
         return $usersController->loginForm($req, $res);
     }
     $twitter = $this->twitter($token_credentials['oauth_token'], $token_credentials['oauth_token_secret'], false);
     // fetch profile
     $user_profile = $twitter->get('account/verify_credentials');
     if (isset($user_profile->errors)) {
         return $res->setBody('There was an error signing you into Twitter:<br/><pre>' . print_r($user_profile->errors, true) . '</pre>');
     }
     /* log the user in or kick off signup */
     $currentUser = $this->app['user'];
     $tid = $user_profile->id;
     // generate parameters to update profile
     $user_profile = (array) json_decode(json_encode($user_profile), true);
     $profileUpdateArray = ['id' => $tid, 'access_token' => $token_credentials['oauth_token'], 'access_token_secret' => $token_credentials['oauth_token_secret']];
     // twitter id matches existing user?
     $users = User::find(['where' => ['twitter_id' => $tid]]);
     if ($users['count'] == 1) {
         $user = $users['models'][0];
         // check if we are dealing with a temporary user
         if (!$user->isTemporary()) {
             if ($user->id() != $currentUser->id()) {
                 if ($req->query('forceLogin') || !$currentUser->isLoggedIn()) {
                     // log the user in
                     $this->app['auth']->signInUser($user->id(), 'twitter');
                 } else {
                     // inform the user that the twitter account they are trying to
                     // connect belongs to someone else
                     return new View('switchingAccounts/twitter', ['title' => 'Switch accounts?', 'otherUser' => $user, 'otherProfile' => $user->twitterProfile()]);
                 }
             }
             $profile = new TwitterProfile($tid);
             // create or update the profile
             if ($profile->exists()) {
                 $profile->set($profileUpdateArray);
             } else {
                 $profile = new TwitterProfile();
                 $profile->create($profileUpdateArray);
             }
             // refresh profile from API
             $profile->refreshProfile($user_profile);
             return $this->finalRedirect($req, $res);
         } else {
             // show finish signup screen
             $req->setSession('tid', $tid);
             return $res->redirect('/signup/finish');
         }
     }
     if ($currentUser->isLoggedIn()) {
         // add to current user's account
         $currentUser->set('twitter_id', $tid);
     } else {
         // save this for later
         $req->setSession('tid', $tid);
     }
     $profile = new TwitterProfile($tid);
     // create or update the profile
     if ($profile->exists()) {
         $profile->set($profileUpdateArray);
     } else {
         $profile = new TwitterProfile();
         $profile->create($profileUpdateArray);
     }
     // refresh profile from API
     $profile->refreshProfile($user_profile);
     // get outta here
     if ($currentUser->isLoggedIn()) {
         $this->finalRedirect($req, $res);
     } else {
         $res->redirect('/signup/finish');
     }
 }