123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class OtpAction extends Action
- {
- var $user;
- var $token;
- var $rememberme;
- var $returnto;
- var $lt;
- function prepare(array $args = array())
- {
- parent::prepare($args);
- if (common_is_real_login()) {
-
- $this->clientError(_('Already logged in.'));
- }
- $id = $this->trimmed('user_id');
- if (empty($id)) {
-
- $this->clientError(_('No user ID specified.'));
- }
- $this->user = User::getKV('id', $id);
- if (empty($this->user)) {
-
- $this->clientError(_('No such user.'));
- }
- $this->token = $this->trimmed('token');
- if (empty($this->token)) {
-
- $this->clientError(_('No login token specified.'));
- }
- $this->lt = Login_token::getKV('user_id', $id);
- if (empty($this->lt)) {
-
- $this->clientError(_('No login token requested.'));
- }
- if ($this->lt->token != $this->token) {
-
- $this->clientError(_('Invalid login token specified.'));
- }
- if ($this->lt->modified > time() + Login_token::TIMEOUT) {
-
-
- $this->lt->delete();
- $this->lt = null;
-
- $this->clientError(_('Login token expired.'));
- }
- $this->rememberme = $this->boolean('rememberme');
- $this->returnto = $this->trimmed('returnto');
- return true;
- }
- function handle()
- {
- parent::handle();
-
- if (!common_set_user($this->user)) {
-
- $this->serverError(_('Error setting user. You are probably not authorized.'));
- }
-
- $this->lt->delete();
- $this->lt = null;
- common_real_login(true);
- if ($this->rememberme) {
- common_rememberme($this->user);
- }
- if (!empty($this->returnto)) {
- $url = $this->returnto;
-
- common_set_returnto(null);
- } else {
- $url = common_local_url('all',
- array('nickname' =>
- $this->user->nickname));
- }
- common_redirect($url, 303);
- }
- }
|