質問編集履歴

1

問題あると思われるコードだけ記載致しました。

2015/12/19 15:34

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -24,135 +24,7 @@
24
24
 
25
25
 
26
26
 
27
- namespace MyApp\Controller;
28
-
29
-
30
-
31
- class Signup extends \MyApp\Controller {
32
-
33
-
34
-
35
- public function run() {
36
-
37
- if ($this->isLoggedIn()) {
38
-
39
- header('Location: ' . SITE_URL);
40
-
41
- exit;
27
+ 中略...
42
-
43
- }
44
-
45
-
46
-
47
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
48
-
49
- $this->postProcess();
50
-
51
- }
52
-
53
- }
54
-
55
-
56
-
57
- protected function postProcess() {
58
-
59
- // validate
60
-
61
- try {
62
-
63
- $this->_validate();
64
-
65
- } catch (\MyApp\Exception\InvalidEmail $e) {
66
-
67
- // echo $e->getMessage();
68
-
69
- // exit;
70
-
71
- $this->setErrors('email', $e->getMessage());
72
-
73
- } catch (\MyApp\Exception\InvalidPassword $e) {
74
-
75
- // echo $e->getMessage();
76
-
77
- // exit;
78
-
79
- $this->setErrors('password', $e->getMessage());
80
-
81
- } catch (\MyApp\Exception\InvalidAdress $e) {
82
-
83
- // echo $e->getMessage();
84
-
85
- // exit;
86
-
87
- $this->setErrors('adress', $e->getMessage());
88
-
89
- }catch (\MyApp\Exception\InvalidPhonenamber $e) {
90
-
91
- // echo $e->getMessage();
92
-
93
- // exit;
94
-
95
- $this->setErrors('phonenumber', $e->getMessage());
96
-
97
- }
98
-
99
-
100
-
101
- // echo "success";
102
-
103
- // exit;
104
-
105
-
106
-
107
- $this->setValues('email', $_POST['email']);
108
-
109
-
110
-
111
- if ($this->hasError()) {
112
-
113
- return;
114
-
115
- } else {
116
-
117
- // create user
118
-
119
- try {
120
-
121
- $userModel = new \MyApp\Model\User();
122
-
123
- $userModel->create([
124
-
125
- 'email' => $_POST['email'],
126
-
127
- 'password' => $_POST['password'],
128
-
129
- 'adress' => $_POST['adress'],
130
-
131
- 'phonenumber' => $_POST['phonenumber']
132
-
133
- ]);
134
-
135
- } catch (\MyApp\Exception\DuplicateEmail $e) {
136
-
137
- $this->setErrors('email', $e->getMessage());
138
-
139
- return;
140
-
141
- }
142
-
143
-
144
-
145
- // redirect to login
146
-
147
- header('Location: ' . SITE_URL . '/login.php');
148
-
149
- exit;
150
-
151
- }
152
-
153
- }
154
-
155
-
156
28
 
157
29
  private function _validate() {
158
30
 
@@ -203,105 +75,3 @@
203
75
 
204
76
 
205
77
  }
206
-
207
-
208
-
209
-
210
-
211
- **sign.php**
212
-
213
- <?php
214
-
215
-
216
-
217
- // 新規登録
218
-
219
-
220
-
221
- require_once(__DIR__ . '/../config/config.php');
222
-
223
-
224
-
225
- $app = new MyApp\Controller\Signup();
226
-
227
-
228
-
229
- $app->run();
230
-
231
-
232
-
233
- ?>
234
-
235
- <!DOCTYPE html>
236
-
237
- <html lang="ja">
238
-
239
- <head>
240
-
241
- <meta charset="utf-8">
242
-
243
- <title>新規登録</title>
244
-
245
- <link rel="stylesheet" href="css/bootstrap.min.css">
246
-
247
- </head>
248
-
249
- <body>
250
-
251
- <div id="container">
252
-
253
- <form action="" method="post" id="signup">
254
-
255
-
256
-
257
- <p>
258
-
259
- <input type="text" name="adress" placeholder="住所">
260
-
261
- </p>
262
-
263
- <p class="err"><?= h($app->getErrors('adress')); ?></p>
264
-
265
-
266
-
267
- <p>
268
-
269
- <input type="text" name="phonenumber" placeholder="電話番号">
270
-
271
- </p>
272
-
273
- <p class="err"><?= h($app->getErrors('phonenumber')); ?></p>
274
-
275
-
276
-
277
- <p>
278
-
279
- <input type="text" name="email" placeholder="メールアドレス" value="<?= isset($app->getValues()->email) ? h($app->getValues()->email) : ''; ?>">
280
-
281
- </p>
282
-
283
- <p class="err"><?= h($app->getErrors('email')); ?></p>
284
-
285
- <p>
286
-
287
- <input type="password" name="password" placeholder="パスワード">
288
-
289
- </p>
290
-
291
- <p class="err"><?= h($app->getErrors('password')); ?></p>
292
-
293
-
294
-
295
- <div class="btn" onclick="document.getElementById('signup').submit();">新規登録</div>
296
-
297
- <p class="fs12"><a href="/login.php">ログイン</a></p>
298
-
299
- <input type="hidden" name="token" value="<?= h($_SESSION['token']); ?>">
300
-
301
- </form>
302
-
303
- </div>
304
-
305
- </body>
306
-
307
- </html>