1
1
<?php
2
2
abstract class Api_UserapiModelBase extends Api_AppModel
3
3
{
4
+ /** constructor */
4
5
public function __construct ()
5
6
{
6
7
parent ::__construct ();
7
8
$ this ->_name = 'api_userapi ' ;
8
9
$ this ->_key = 'userapi_id ' ;
9
10
10
- $ this ->_mainData = array (
11
- 'userapi_id ' => array ('type ' => MIDAS_DATA ),
12
- 'user_id ' => array ('type ' => MIDAS_DATA ),
13
- 'apikey ' => array ('type ' => MIDAS_DATA ),
14
- 'application_name ' => array ('type ' => MIDAS_DATA ),
15
- 'token_expiration_time ' => array ('type ' => MIDAS_DATA ),
16
- 'creation_date ' => array ('type ' => MIDAS_DATA ),
11
+ $ this ->_mainData = array (
12
+ 'userapi_id ' => array ('type ' => MIDAS_DATA ),
13
+ 'user_id ' => array ('type ' => MIDAS_DATA ),
14
+ 'apikey ' => array ('type ' => MIDAS_DATA ),
15
+ 'application_name ' => array ('type ' => MIDAS_DATA ),
16
+ 'token_expiration_time ' => array ('type ' => MIDAS_DATA ),
17
+ 'creation_date ' => array ('type ' => MIDAS_DATA ),
17
18
'user ' => array ('type ' => MIDAS_MANY_TO_ONE , 'model ' => 'User ' , 'parent_column ' => 'user_id ' , 'child_column ' => 'user_id ' ),
18
19
);
19
20
$ this ->initialize (); // required
20
21
} // end __construct()
21
22
22
- abstract function createKeyFromEmailPassword ($ appname ,$ email ,$ password );
23
- abstract function getByAppAndEmail ($ appname ,$ email );
24
- abstract function getByAppAndUser ($ appname ,$ userDao );
25
- abstract function getToken ($ email ,$ apikey ,$ appname );
23
+ abstract function createKeyFromEmailPassword ($ appname , $ email , $ password );
24
+ abstract function getByAppAndEmail ($ appname , $ email );
25
+ abstract function getByAppAndUser ($ appname , $ userDao );
26
+ abstract function getToken ($ email , $ apikey , $ appname );
26
27
abstract function getUserapiFromToken ($ token );
27
28
abstract function getByUser ($ userDao );
28
29
@@ -43,14 +44,14 @@ function createDefaultApiKey($userDao)
43
44
->where ('application_name = ? ' , 'Default ' ));
44
45
foreach ($ rowset as $ row )
45
46
{
46
- $ userApiDao = $ this ->initDao ('Userapi ' , $ row , 'api ' );
47
+ $ userApiDao = $ this ->initDao ('Userapi ' , $ row , 'api ' );
47
48
$ this ->delete ($ userApiDao );
48
49
}
49
50
50
51
// Save new default key
51
52
$ key = md5 ($ userDao ->getEmail ().$ userDao ->getPassword ().'Default ' );
52
- $ this ->loadDaoClass ('UserapiDao ' ,'api ' );
53
- $ userApiDao= new Api_UserapiDao ();
53
+ $ this ->loadDaoClass ('UserapiDao ' , 'api ' );
54
+ $ userApiDao = new Api_UserapiDao ();
54
55
$ userApiDao ->setUserId ($ userDao ->getKey ());
55
56
$ userApiDao ->setApplicationName ('Default ' );
56
57
$ userApiDao ->setApikey ($ key );
@@ -59,16 +60,16 @@ function createDefaultApiKey($userDao)
59
60
$ this ->save ($ userApiDao );
60
61
}
61
62
62
- /** Create a new API key */
63
- function createKey ($ userDao ,$ applicationname ,$ tokenexperiationtime )
63
+ /** Create a new API key */
64
+ function createKey ($ userDao , $ applicationname , $ tokenexperiationtime )
64
65
{
65
66
if (!$ userDao instanceof UserDao || !is_string ($ applicationname ) || !is_string ($ tokenexperiationtime ) || empty ($ applicationname ))
66
67
{
67
68
throw new Zend_Exception ("Error parameter " );
68
69
}
69
70
70
71
// Check that the applicationname doesn't exist for this user
71
- $ userapiDao= $ this ->getByAppAndUser ($ applicationname , $ userDao );
72
+ $ userapiDao = $ this ->getByAppAndUser ($ applicationname , $ userDao );
72
73
if (!empty ($ userapiDao ))
73
74
{
74
75
return false ;
@@ -80,22 +81,18 @@ function createKey($userDao,$applicationname,$tokenexperiationtime)
80
81
$ length = 40 ;
81
82
82
83
// seed with microseconds
83
- function make_seed_recoverpass ()
84
- {
85
- list ($ usec , $ sec ) = explode (' ' , microtime ());
86
- return (float ) $ sec + ((float ) $ usec * 100000 );
87
- }
88
- srand (make_seed_recoverpass ());
84
+ list ($ usec , $ sec ) = explode (' ' , microtime ());
85
+ srand ((float ) $ sec + ((float ) $ usec * 100000 ));
89
86
90
87
$ key = "" ;
91
- $ max= strlen ($ keychars )- 1 ;
92
- for ($ i= 0 ; $ i< $ length ; $ i ++)
88
+ $ max = strlen ($ keychars ) - 1 ;
89
+ for ($ i = 0 ; $ i < $ length ; $ i ++)
93
90
{
94
91
$ key .= substr ($ keychars , rand (0 , $ max ), 1 );
95
92
}
96
93
97
- $ this ->loadDaoClass ('UserapiDao ' ,'api ' );
98
- $ userApiDao= new Api_UserapiDao ();
94
+ $ this ->loadDaoClass ('UserapiDao ' , 'api ' );
95
+ $ userApiDao = new Api_UserapiDao ();
99
96
$ userApiDao ->setUserId ($ userDao ->getKey ());
100
97
$ userApiDao ->setApikey ($ key );
101
98
$ userApiDao ->setApplicationName ($ applicationname );
@@ -104,7 +101,7 @@ function make_seed_recoverpass()
104
101
105
102
$ this ->save ($ userApiDao );
106
103
return $ userApiDao ;
107
- }//end createKey
104
+ }
108
105
109
- } // end class AssetstoreModelBase
106
+ }
110
107
?>
0 commit comments