OSDN Git Service

e7e0cc1635fb9572eee800d4f012a79fd491d505
[hirameki-note/repo.git] / hirameki-note / src / main / php / logic / account.php
1 <?php\r
2         // Copyright (c) 2008, u6k.yu1@gmail.com\r
3         // All rights reserved.\r
4         // \r
5         // Redistribution and use in source and binary forms, with or without\r
6         // modification, are permitted provided that the following conditions are met:\r
7         //     * Redistributions of source code must retain the above copyright\r
8         //       notice, this list of conditions and the following disclaimer.\r
9         //     * Redistributions in binary form must reproduce the above copyright\r
10         //       notice, this list of conditions and the following disclaimer in the\r
11         //       documentation and/or other materials provided with the distribution.\r
12         //     * Neither the name of the u6k nor the\r
13         //       names of its contributors may be used to endorse or promote products\r
14         //       derived from this software without specific prior written permission.\r
15         // \r
16         // THIS SOFTWARE IS PROVIDED BY u6k.yu1@gmail.com ``AS IS'' AND ANY\r
17         // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
18         // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
19         // DISCLAIMED. IN NO EVENT SHALL u6k.yu1@gmail.com BE LIABLE FOR ANY\r
20         // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
21         // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
22         // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
23         // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
24         // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
25         // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
26         \r
27         require_once("MDB2.php");\r
28         \r
29         require_once(dirname(__FILE__) . "/../common/common.php");\r
30         require_once(dirname(__FILE__) . "/../config/config.php");\r
31         \r
32         function login($name, $password) {\r
33                 /*\r
34                  * \88ø\90\94\82ð\8am\94F\82µ\82Ü\82·\81B\r
35                  */\r
36                 if (empty($name)) {\r
37                         throw new ArgumentException("name\88ø\90\94\82ª\8bó\82Å\82·\81B");\r
38                 }\r
39                 if (!is_string($name)) {\r
40                         throw new ArgumentException("name\88ø\90\94\82ª\95\8e\9a\97ñ\8c^\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B");\r
41                 }\r
42                 if (empty($password)) {\r
43                         throw new ArgumentException("password\88ø\90\94\82ª\8bó\82Å\82·\81B");\r
44                 }\r
45                 if (!is_string($password)) {\r
46                         throw new ArgumentException("password\88ø\90\94\82ª\95\8e\9a\97ñ\8c^\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B");\r
47                 }\r
48                 \r
49                 /*\r
50                  * \83f\81[\83^\83x\81[\83X\82©\82ç\83A\83J\83E\83\93\83g\8fî\95ñ\82ð\8c\9f\8dõ\82µ\81A\83\8d\83O\83C\83\93\8am\94F\82ð\8ds\82¢\82Ü\82·\81B\r
51                  */\r
52                 global $config;\r
53                 $con = MDB2::connect($config);\r
54                 $con->loadModule("Extended");\r
55                 \r
56                 $sql = <<< SQL_END\r
57 select\r
58         account.id as id,\r
59         account.name as name,\r
60         account.real_name as real_name,\r
61         account.email as email\r
62 from\r
63         account,\r
64         (\r
65                 select\r
66                         id,\r
67                         max(create_time) as latest_time\r
68                 from\r
69                         account\r
70                 group by\r
71                         id\r
72                 having\r
73                         name = :name\r
74                         and password = :password\r
75         ) as latest_account\r
76 where\r
77         account.id = latest_account.id\r
78         and account.create_time = latest_account.latest_time\r
79         and account.enable = :enable\r
80 SQL_END;\r
81                 $type = "integer";\r
82                 $param = array(\r
83                         "name" => $name,\r
84                         "password" => md5($password),\r
85                         "enable" => 1\r
86                 );\r
87                 $param_type = array(\r
88                         "name" => "text",\r
89                         "password" => "text",\r
90                         "enable" => "integer"\r
91                 );\r
92                 \r
93                 $result = $con->getOne($sql, $type, $param, $param_type);\r
94                 \r
95                 $con->disconnect();\r
96                 \r
97                 \r
98         }\r
99 ?>\r