function onEndShowHTML($action)
 {
     if (!common_logged_in()) {
         // Set a place to return to when submitting forms
         common_set_returnto($action->selfUrl());
     }
 }
Beispiel #2
0
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         common_set_returnto($_SERVER['REQUEST_URI']);
         if (Event::handle('RedirectToLogin', array($this, null))) {
             common_redirect(common_local_url('login'), 303);
         }
     }
     $id = $this->trimmed('id');
     if (!$id) {
         $this->profile = false;
     } else {
         $this->profile = Profile::staticGet('id', $id);
         if (!$this->profile) {
             // TRANS: Client error displayed when referring to non-existing profile ID.
             $this->clientError(_('No profile with that ID.'));
             return false;
         }
     }
     $current = common_current_user()->getProfile();
     if ($this->profile && !$current->canTag($this->profile)) {
         // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
         $this->clientError(_('You cannot tag this user.'));
     }
     return true;
 }
Beispiel #3
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->arg('page') && $this->arg('page') != 1) {
             $args['page'] = $this->arg['page'];
         }
         common_redirect(common_local_url($this->trimmed('action'), $args), 301);
         return false;
     }
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         $this->clientError(_('No such user.'), 404);
         return false;
     }
     $this->profile = $this->user->getProfile();
     if (!$this->profile) {
         $this->serverError(_('User has no profile.'));
         return false;
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Beispiel #5
0
 /**
  * Read and validate arguments
  *
  * @param array $args URL parameters
  *
  * @return boolean success value
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
 /**
  * Prepare for the action
  *
  * We check to see that the user is logged in, has
  * authenticated in this session, and has the right
  * to configure the site.
  *
  * @param array $args Array of arguments from Web driver
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     // User must be logged in.
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
     }
     $user = common_current_user();
     // ...because they're logged in
     assert(!empty($user));
     // It must be a "real" login, not saved cookie login
     if (!common_is_real_login()) {
         // Cookie theft is too easy; we require automatic
         // logins to re-authenticate before admining the site
         common_set_returnto($this->selfUrl());
         if (Event::handle('RedirectToLogin', array($this, $user))) {
             common_redirect(common_local_url('login'), 303);
         }
     }
     // User must have the right to change admin settings
     if (!$user->hasRight(Right::CONFIGURESITE)) {
         // TRANS: Client error message thrown when a user tries to change admin settings but has no access rights.
         $this->clientError(_('You cannot make changes to this site.'));
     }
     // This panel must be enabled
     $name = $this->trimmed('action');
     $name = mb_substr($name, 0, -10);
     if (!self::canAdmin($name)) {
         // TRANS: Client error message throw when a certain panel's settings cannot be changed.
         $this->clientError(_('Changes to that panel are not allowed.'), 403);
     }
     return true;
 }
Beispiel #7
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
         $this->clientError(_('No such group.'), 404);
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::getKV('nickname', $this->nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
         $this->clientError(_('No such group.'), 404);
     }
     $this->group = User_group::getKV('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
         $this->clientError(_('No such group.'), 404);
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #8
0
 /**
  * Take arguments for running
  *
  * This method is called first, and it lets the action class get
  * all its arguments and validate them. It's also the time
  * to fetch any relevant data from the database.
  *
  * Action classes should run parent::prepare($args) as the first
  * line of this method to make sure the default argument-processing
  * happens.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return;
     } else {
         if (!common_is_real_login()) {
             // Cookie theft means that automatic logins can't
             // change important settings or see private info, and
             // _all_ our settings are important
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         } else {
             $this->user = common_current_user();
             $sdate = !isset($_REQUEST['sdate']) ? new DateTime('first day of this month') : new DateTime($_REQUEST['sdate']);
             $edate = !isset($_REQUEST['edate']) ? new DateTime('last day of this month') : new DateTime($_REQUEST['edate']);
             // Custom date range
             $this->sa = Social_analytics::init($this->user->id, $sdate, $edate);
         }
     }
     return true;
 }
Beispiel #9
0
 /**
  * Read and validate arguments
  *
  * @param array $args URL parameters
  *
  * @return boolean success value
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     if ($this->page > MAX_PUBLIC_PAGE) {
         // TRANS: Client error displayed when requesting a public timeline page beyond the page limit.
         // TRANS: %s is the page limit.
         $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE));
     }
     common_set_returnto($this->selfUrl());
     $this->userProfile = Profile::current();
     $user = common_current_user();
     if (!empty($user) && $user->streamModeOnly()) {
         $stream = new PublicNoticeStream($this->userProfile);
     } else {
         $stream = new ThreadingPublicNoticeStream($this->userProfile);
     }
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     if (!$this->notice) {
         // TRANS: Server error displayed when a public timeline cannot be retrieved.
         $this->serverError(_('Could not retrieve public timeline.'));
         return;
     }
     if ($this->page > 1 && $this->notice->N == 0) {
         // TRANS: Server error when page not found (404).
         $this->serverError(_('No such page.'), $code = 404);
     }
     return true;
 }
Beispiel #10
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $user = common_current_user();
     // User must be logged in.
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     // ...because they're logged in
     assert(!empty($user));
     // It must be a "real" login, not saved cookie login
     if (!common_is_real_login()) {
         // Cookie theft is too easy; we require automatic
         // logins to re-authenticate before admining the site
         common_set_returnto($this->selfUrl());
         if (Event::handle('RedirectToLogin', array($this, $user))) {
             common_redirect(common_local_url('login'), 303);
         }
     }
     // User must have the right to review flags
     if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) {
         $this->clientError(_('You cannot review profile flags.'));
         return false;
     }
     $this->page = $this->trimmed('page');
     if (empty($this->page)) {
         $this->page = 1;
     }
     $this->profiles = $this->getProfiles();
     return true;
 }
Beispiel #12
0
 /**
  * Prepare the object
  *
  * Check the input values and initialize the object.
  * Shows an error page on bad input.
  *
  * @param array $args $_REQUEST data
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $nickname = common_canonical_nickname($this->arg('nickname'));
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         // TRANS: Client error displayed when trying to reply to a non-exsting user.
         $this->clientError(_('No such user.'));
         return false;
     }
     $profile = $this->user->getProfile();
     if (!$profile) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_('User has no profile.'));
         return false;
     }
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     $stream = new ReplyNoticeStream($this->user->id, Profile::current());
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     if ($this->page > 1 && $this->notice->N == 0) {
         // TRANS: Server error when page not found (404)
         $this->serverError(_('No such page.'), $code = 404);
     }
     return true;
 }
 /**
  * Handle input and output a page
  *
  * @param array $args $_REQUEST arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     } else {
         if (!common_is_real_login()) {
             // Cookie theft means that automatic logins can't
             // change important settings or see private info, and
             // _all_ our settings are important
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         } else {
             if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                 $this->handlePost();
             } else {
                 $this->showForm();
             }
         }
     }
 }
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->arg('page') && $this->arg('page') != 1) {
             $args['page'] = $this->arg['page'];
         }
         common_redirect(common_local_url($this->trimmed('action'), $args), 301);
         return false;
     }
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         // TRANS: Client error displayed when calling a profile action without specifying a user.
         $this->clientError(_('No such user.'), 404);
         return false;
     }
     $this->profile = $this->user->getProfile();
     if (!$this->profile) {
         // TRANS: Server error displayed when calling a profile action while the specified user does not have a profile.
         $this->serverError(_('User has no profile.'));
         return false;
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #15
0
 /**
  * Check the login data
  *
  * Determines if the login data is valid. If so, logs the user
  * in, and redirects to the 'with friends' page, or to the stored
  * return-to URL.
  *
  * @return void
  */
 protected function doPost()
 {
     // XXX: login throttle
     $nickname = $this->trimmed('nickname');
     $password = $this->arg('password');
     $user = common_check_user($nickname, $password);
     if (!$user instanceof User) {
         // TRANS: Form validation error displayed when trying to log in with incorrect credentials.
         throw new ServerException(_('Incorrect username or password.'));
     }
     // success!
     if (!common_set_user($user)) {
         // TRANS: Server error displayed when during login a server error occurs.
         throw new ServerException(_('Error setting user. You are probably not authorized.'));
     }
     common_real_login(true);
     $this->updateScopedProfile();
     if ($this->boolean('rememberme')) {
         common_rememberme($user);
     }
     $url = common_get_returnto();
     if ($url) {
         // We don't have to return to it again
         common_set_returnto(null);
         $url = common_inject_session($url);
     } else {
         $url = common_local_url('all', array('nickname' => $this->scoped->nickname));
     }
     common_redirect($url, 303);
 }
Beispiel #16
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #17
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->arg('page') && $this->arg('page') != 1) {
             $args['page'] = $this->arg['page'];
         }
         common_redirect(common_local_url($this->trimmed('action'), $args), 301);
         return false;
     }
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         // TRANS: Client error displayed when calling a profile action without specifying a user.
         $this->clientError(_('No such user.'), 404);
         return false;
     }
     $this->profile = $this->user->getProfile();
     if (!$this->profile) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_('User has no profile.'));
         return false;
     }
     $user = common_current_user();
     if ($this->profile->hasRole(Profile_role::SILENCED) && (empty($user) || !$user->hasRight(Right::SILENCEUSER))) {
         throw new ClientException(_('This profile has been silenced by site moderators'), 403);
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
 function prepare($args)
 {
     Action::prepare($args);
     // skip the ProfileAction code and replace it...
     $id = $this->arg('id');
     $this->user = false;
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_m('User has no profile.'));
         return false;
     }
     $user = User::staticGet('id', $this->profile->id);
     if ($user) {
         // This is a local user -- send to their regular profile.
         $url = common_local_url('showstream', array('nickname' => $user->nickname));
         common_redirect($url);
         return false;
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     $p = Profile::current();
     if (empty($this->tag)) {
         $stream = new ProfileNoticeStream($this->profile, $p);
     } else {
         $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $p);
     }
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     return true;
 }
Beispiel #19
0
 /**
  * Accept a confirmation code
  *
  * Checks the code and confirms the address in the
  * user record
  *
  * @param args $args $_REQUEST array
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         common_set_returnto($this->selfUrl());
         common_redirect(common_local_url('login'));
         return;
     }
     $code = $this->trimmed('code');
     if (!$code) {
         $this->clientError(_('No confirmation code.'));
         return;
     }
     $confirm = Confirm_address::staticGet('code', $code);
     if (!$confirm) {
         $this->clientError(_('Confirmation code not found.'));
         return;
     }
     $cur = common_current_user();
     if ($cur->id != $confirm->user_id) {
         $this->clientError(_('That confirmation code is not for you!'));
         return;
     }
     $type = $confirm->address_type;
     if (!in_array($type, array('email', 'jabber', 'sms'))) {
         $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
         return;
     }
     if ($cur->{$type} == $confirm->address) {
         $this->clientError(_('That address has already been confirmed.'));
         return;
     }
     $cur->query('BEGIN');
     $orig_user = clone $cur;
     $cur->{$type} = $confirm->address;
     if ($type == 'sms') {
         $cur->carrier = $confirm->address_extra + 0;
         $carrier = Sms_carrier::staticGet($cur->carrier);
         $cur->smsemail = $carrier->toEmailAddress($cur->sms);
     }
     $result = $cur->updateKeys($orig_user);
     if (!$result) {
         common_log_db_error($cur, 'UPDATE', __FILE__);
         $this->serverError(_('Couldn\'t update user.'));
         return;
     }
     if ($type == 'email') {
         $cur->emailChanged();
     }
     $result = $confirm->delete();
     if (!$result) {
         common_log_db_error($confirm, 'DELETE', __FILE__);
         $this->serverError(_('Couldn\'t delete email confirmation.'));
         return;
     }
     $cur->query('COMMIT');
     $this->type = $type;
     $this->showPage();
 }
Beispiel #20
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->tag = $this->trimmed('tag');
     if (!common_valid_profile_tag($this->tag)) {
         $this->clientError(sprintf(_('Not a valid people tag: %s.'), $this->tag));
         return;
     }
     $this->page = $this->arg('page') ? $this->arg('page') : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
 protected function prepare(array $args = array())
 {
     // this will call ->doPreparation() which child classes use to set $this->target
     parent::prepare($args);
     if ($this->target->hasRole(Profile_role::SILENCED) && (!$this->scoped instanceof Profile || !$this->scoped->hasRight(Right::SILENCEUSER))) {
         throw new ClientException(_('This profile has been silenced by site moderators'), 403);
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #22
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname = common_canonical_nickname($this->arg('nickname'));
     $this->user = User::staticGet('nickname', $nickname);
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
 /**
  * Take arguments for running
  *
  * This method is called first, and it lets the action class get
  * all its arguments and validate them. It's also the time
  * to fetch any relevant data from the database.
  *
  * Action classes should run parent::prepare($args) as the first
  * line of this method to make sure the default argument-processing
  * happens.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $alumno = $this->trimmed('nickname');
     $group = $this->trimmed('nickgroup');
     $this->group = User_group::staticGet('nickname', $group);
     $this->alumno = Profile::staticGet('nickname', $alumno);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $ids = Grades::getNoticeFromUserInGroup($this->alumno->id, $this->group->id);
     $this->generarEstadisticas($ids);
     $this->notice = $this->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, $ids);
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #24
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->tag = $this->trimmed('tag');
     if (!common_valid_profile_tag($this->tag)) {
         // TRANS: Client error displayed when trying to list a profile with an invalid list.
         // TRANS: %s is the invalid list name.
         $this->clientError(sprintf(_('Not a valid list: %s.'), $this->tag));
         return;
     }
     $this->page = $this->arg('page') ? $this->arg('page') : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #25
0
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // XXX: selfURL() didn't work. :<
         common_set_returnto($_SERVER['REQUEST_URI']);
         if (Event::handle('RedirectToLogin', array($this, null))) {
             common_redirect(common_local_url('login'), 303);
         }
         return false;
     }
     if ($this->pullRemoteProfile()) {
         $this->validateRemoteProfile();
     }
     return true;
 }
Beispiel #26
0
 function prepare($args)
 {
     parent::prepare($args);
     $taginput = $this->trimmed('tag');
     $this->tag = common_canonical_tag($taginput);
     if (!$this->tag) {
         common_redirect(common_local_url('publictagcloud'), 301);
         return false;
     }
     if ($this->tag != $taginput) {
         common_redirect(common_local_url('tag', array('tag' => $this->tag)));
     }
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
Beispiel #27
0
 function handle($args)
 {
     parent::handle($args);
     if (common_is_real_login()) {
         // TRANS: Client error displayed when trying to log in while already logged on.
         $this->clientError(_m('Already logged in.'));
     } else {
         global $casSettings;
         phpCAS::client(CAS_VERSION_2_0, $casSettings['server'], $casSettings['port'], $casSettings['path'], false);
         phpCAS::setNoCasServerValidation();
         phpCAS::handleLogoutRequests();
         phpCAS::forceAuthentication();
         global $casTempPassword;
         $casTempPassword = common_good_rand(16);
         $user = common_check_user(phpCAS::getUser(), $casTempPassword);
         if (!$user) {
             // TRANS: Server error displayed when trying to log in with incorrect username or password.
             $this->serverError(_m('Incorrect username or password.'));
             return;
         }
         // success!
         if (!common_set_user($user)) {
             // TRANS: Server error displayed when login fails in CAS authentication plugin.
             $this->serverError(_m('Error setting user. You are probably not authorized.'));
             return;
         }
         common_real_login(true);
         $url = common_get_returnto();
         if ($url) {
             // We don't have to return to it again
             common_set_returnto(null);
         } else {
             if (common_config('site', 'private') && $casSettings['takeOverLogin']) {
                 //SSO users expect to just go to the URL they entered
                 //if we don't have a returnto set, the user entered the
                 //main StatusNet url, so send them there.
                 $url = common_local_url('public');
             } else {
                 //With normal logins (regular form-based username/password),
                 //the user would expect to go to their home after logging in.
                 $url = common_local_url('public', array('nickname' => $user->nickname));
             }
         }
         common_redirect($url, 303);
     }
 }
Beispiel #28
0
 /**
  * Prepare the object
  *
  * Check the input values and initialize the object.
  * Shows an error page on bad input.
  *
  * @param array $args $_REQUEST data
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $nickname = common_canonical_nickname($this->arg('nickname'));
     $this->user = User::staticGet('nickname', $nickname);
     if (!$this->user) {
         $this->clientError(_('No such user.'));
         return false;
     }
     $profile = $this->user->getProfile();
     if (!$profile) {
         $this->serverError(_('User has no profile.'));
         return false;
     }
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         /* Use a session token for CSRF protection. */
         $token = $this->trimmed('token');
         if (!$token || $token != common_session_token()) {
             $srv = $this->getStoredParams();
             // TRANS: Client error displayed when the session token does not match or is not given.
             $this->showForm($srv->getRemoteUser(), _('There was a problem ' . 'with your session token. Try again, ' . 'please.'));
             return;
         }
         /* We've shown the form, now post user's choice. */
         $this->sendAuthorization();
     } else {
         if (!common_logged_in()) {
             /* Go log in, and then come back. */
             common_set_returnto($_SERVER['REQUEST_URI']);
             common_redirect(common_local_url('login'));
             return;
         }
         $user = common_current_user();
         $profile = $user->getProfile();
         if (!$profile) {
             common_log_db_error($user, 'SELECT', __FILE__);
             // TRANS: Error message displayed when referring to a user without a profile.
             $this->serverError(_('User has no profile.'));
             return;
         }
         /* TODO: If no token is passed the user should get a prompt to enter
            it according to OAuth Core 1.0. */
         try {
             $this->validateOmb();
             $srv = new OMB_Service_Provider(profile_to_omb_profile($user->uri, $profile), omb_oauth_datastore());
             $remote_user = $srv->handleUserAuth();
         } catch (Exception $e) {
             $this->clearParams();
             $this->clientError($e->getMessage());
             return;
         }
         $this->storeParams($srv);
         $this->showForm($remote_user);
     }
 }
Beispiel #30
0
 /**
  * Read and validate arguments
  *
  * @param array $args URL parameters
  *
  * @return boolean success value
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     if ($this->page > MAX_PUBLIC_PAGE) {
         $this->clientError(sprintf(_("Beyond the page limit (%s)."), MAX_PUBLIC_PAGE));
     }
     common_set_returnto($this->selfUrl());
     $this->notice = Notice::publicStream(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     if (!$this->notice) {
         $this->serverError(_('Could not retrieve public stream.'));
         return;
     }
     if ($this->page > 1 && $this->notice->N == 0) {
         // TRANS: Server error when page not found (404)
         $this->serverError(_('您访问的网页不存在'), $code = 404);
     }
     return true;
 }