Ejemplo n.º 1
0
 /**
  * 创建token
  */
 public function createToken($adminData)
 {
     $adminInfo = json_encode($adminData);
     $modToken = new TokenModel();
     $token = $modToken->setToken($adminInfo);
     if (!$token) {
         return false;
     } else {
         return $token;
     }
 }
Ejemplo n.º 2
0
 public function checkLogin()
 {
     $token = $this->_request->get('token');
     $modToken = new TokenModel();
     $tokenInfo = $modToken->getToken($token);
     if (!$tokenInfo) {
         response('没有登陆');
     } else {
         $this->uid = $tokenInfo['uid'];
     }
 }
Ejemplo n.º 3
0
 public function create()
 {
     $appid = isset($_POST['appID']) ? $_POST['appID'] : $_GET['appID'];
     $secret = isset($_POST['appSecret']) ? $_POST['appSecret'] : $_GET['appSecret'];
     $expires = (int) isset($_GET['expires']) ? $_GET['expires'] : 14400;
     $app = db()->table('authapp')->get('appID', $appid)->addRestriction('appSecret', $secret)->fetch();
     if (!$app) {
         throw new PublicException('No application found', 403);
     }
     $token = TokenModel::create($app, $expires);
     //Send the token to the view so it can render it
     $this->view->set('token', $token);
 }
Ejemplo n.º 4
0
 public function activate($tokenid = null)
 {
     $token = $tokenid ? db()->table('token')->get('token', $tokenid)->fetch() : null;
     #The token should have been created by the Auth Server
     if ($token && $token->app !== null) {
         throw new PublicException('Token level insufficient', 403);
     }
     if ($token) {
         $token->user->verified = 1;
         $token->user->store();
     } else {
         $token = TokenModel::create(null, 1800, false);
         $token->user = $this->user;
         $token->store();
         $url = new absoluteURL('user', 'activate', $token->token);
         EmailModel::queue($this->user->email, 'Activate your account', sprintf('Click here to activate your account: <a href="%s">%s</a>', $url, $url));
     }
     #We need to redirect the user back to the home page
     $this->response->getHeaders()->redirect(new URL(array('message' => 'success')));
 }