Newer
Older
<?php
class Controller_Api_V0_Auth extends Controller_Handler_Api
{
/**
* @api {get} api/v0/auth/userinfo?token=:token&login=:login&password=:password Check authorisation and get user info
* @apiName Get user info
* @apiGroup Auth
* @apiVersion 0.1.0
* @apiParam {String} token Api key
* @apiParam {String} login User's login
* @apiParam {String} password User's password
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
*/
public function action_get_userinfo() {
if ( !$this->user->isAdmin() ) // ToDo: we should use apikey mask for checking rights
$this->fail();
$login = $this->request->query('login');
$password = $this->request->query('password');
$id = (int) Model_Account::checkAuth($login, $password);
if ($id < 0)
$this->notFoundError('Login or password are incorrect.');
$info = (object)Model_Account::with($id);
$res = (object)['LastName' => $info->LastName,
'FirstName' => $info->FirstName,
'SecondName' => $info->SecondName,
'IsEnabled' => $info->IsEnabled,
'Type' => $info->Type];
switch($info->Type )
{
case 'teacher':
$res->TeacherID = $info->TeacherID;
break;
case 'student':
$res->StudentID = $info->StudentID;
break;
}
return $res;
}
}