* code for task#1580.

This commit is contained in:
xia0ta0
2013-07-19 14:40:51 +08:00
parent 36a90cd70d
commit 6954ee9d89
3 changed files with 319 additions and 11 deletions
+132 -11
View File
@@ -1,21 +1,102 @@
<?php
class sso extends control
{
public function auth($key)
/**
* Browse all auths.
*
* @access public
* @return void
*/
public function browse()
{
if(!empty($_POST) or (isset($_GET['account']) and isset($_GET['password'])))
$this->view->title = $this->lang->sso->browse;
$this->view->auths = $this->sso->getAuths();
$this->display();
}
/**
* Create auth.
*
* @access public
* @return void
*/
public function create()
{
if(!empty($_POST))
{
$account = '';
$password = '';
if($this->post->account) $account = $this->post->account;
if($this->get->account) $account = $this->get->account;
if($this->post->password) $password = $this->post->password;
if($this->get->password) $password = $this->get->password;
if(!$this->post->title) die(js::alert($this->lang->sso->error->title));
if(!$this->post->code) die(js::alert($this->lang->sso->error->code));
if(!$this->post->ip) die(js::alert($this->lang->sso->error->ip));
$this->sso->createAuth();
if(dao::isError()) die(js::error(dao::getError()));
die(js::locate(inlink('browse'), 'parent'));
}
$this->view->title = $this->lang->sso->create;
$this->view->key = $this->sso->createKey();
$this->display();
}
/**
* Edit auth.
*
* @param string $code
* @access public
* @return void
*/
public function edit($code)
{
if(!empty($_POST))
{
if(!$this->post->title) die(js::alert($this->lang->sso->error->title));
if(!$this->post->ip) die(js::alert($this->lang->sso->error->ip));
$this->sso->updateAuth($code);
if(dao::isError()) die(js::error(dao::getError()));
die(js::locate(inlink('browse'), 'parent'));
}
$user = $this->loadModel('user')->identify($account, $password);
$this->view->auth = $this->sso->getAuth($code);
$this->view->code = $code;
$this->display();
}
/**
* Delete auth.
*
* @param string $code
* @param string $confirm
* @access public
* @return void
*/
public function delete($code, $confirm = 'no')
{
if($confirm == 'no')
{
die(js::confirm($this->lang->sso->confirmDelete, inlink('delete', "code=$code&confirm=yes")));
}
else
{
$this->sso->deleteAuth($code);
die(js::locate(inlink('browse'), 'parent'));
}
}
/**
* Auth user.
*
* @param string $app
* @access public
* @return void
*/
public function auth($app)
{
$user = $this->sso->identify($app);
if($user)
{
$dept = $this->loadModel('dept')->getByID($user->dept);
$user->deptName = $dept ? $dept->name : '';
$response['status'] = 'success';
$response['data'] = json_encode($user);
$this->send($response);
@@ -26,11 +107,51 @@ class sso extends control
$this->send($response);
}
public function depts($key)
/**
* Get all departments.
*
* @param string $app
* @access public
* @return void
*/
public function depts($app)
{
if($this->post->key) $key = $this->post->key;
if($this->get->key) $key = $this->get->key;
if($this->sso->checkIP($app) and $this->sso->getAppKey($app) == $key)
{
$depts = $this->sso->getAllDepts();
$response['status'] = 'success';
$response['data'] = json_encode($depts);
$this->send($response);
}
$response['status'] = 'fail';
$response['data'] = 'key error';
$this->send($response);
}
public function users($key)
/**
* Get all users.
*
* @param string $app
* @access public
* @return void
*/
public function users($app)
{
if($this->post->key) $key = $this->post->key;
if($this->get->key) $key = $this->get->key;
if($this->sso->checkIP($app) and $this->sso->getAppKey($app) == $key)
{
$depts = $this->sso->getAllUsers();
$response['status'] = 'success';
$response['data'] = json_encode($depts);
$this->send($response);
}
$response['status'] = 'fail';
$response['data'] = 'key error';
$this->send($response);
}
}